DepositoryTreeCellRenderer.java :  » IDE » Schmortopf » Schmortopf » JavaSourceEditor » DocumentHistoryTracker » Java Open Source

Java Open Source » IDE » Schmortopf 
Schmortopf » Schmortopf » JavaSourceEditor » DocumentHistoryTracker » DepositoryTreeCellRenderer.java
package Schmortopf.JavaSourceEditor.DocumentHistoryTracker;


import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.beans.*;

import Schmortopf.JavaSourceEditor.SourceEditorDocument;
import Schmortopf.Utility.gui.FileIcon.SelfDrawingFileTreeIcon;
import Schmortopf.FileComponents.View.SelfDrawingIcon;
import Language.Language;            

public class DepositoryTreeCellRenderer extends DefaultTreeCellRenderer
{                                           

  // Don't declare the icons static, otherwise recreating objects of
  // this class on UI changed will not create new UI conforming icons.
  private final Icon fileEditableIcon = new SelfDrawingFileTreeIcon( SelfDrawingFileTreeIcon.EditableFileIcon );
  private final Icon fileChangedIcon  = new SelfDrawingFileTreeIcon( SelfDrawingFileTreeIcon.ChangedFileIcon  );
  private final Icon fileReadonlyIcon = new SelfDrawingFileTreeIcon( SelfDrawingFileTreeIcon.ReadOnlyFileIcon );

  private final Icon rootIcon  = new SelfDrawingIcon( Language.Translate("Links to Projectfiles"), SelfDrawingIcon.ColorBlue    );



  public DepositoryTreeCellRenderer()
  {
    super();
  }





 /**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on on leaf and expanded.
  */
  public Component getTreeCellRendererComponent( JTree tree,
                                                 Object value,
                                                 boolean sel,
                                                 boolean expanded,
                                                 boolean leaf, int row,
                                                 boolean hasFocus )
  {
    this.hasFocus = hasFocus;
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
    boolean isRoot = ( node.getParent() == null );
    // The tree only has one level, so if it's not the root(-node), it's a leaf :
    if( isRoot )
     {
       this.setText(node.getUserObject().toString()); 
       this.setOpenIcon( this.rootIcon );
       this.setClosedIcon( this.rootIcon );
       this.setIcon( this.rootIcon );
     }
    else // it's a leaf :
     {
       DocumentHistoryEntry userObject = (DocumentHistoryEntry)node.getUserObject();
       this.setText( userObject.getName() );
       Icon leafIcon = this.fileEditableIcon;
       this.setIcon( userObject.getIcon() );
     }
    this.selected = sel;
    if( this.selected )
        this.setForeground( this.getTextSelectionColor() );
        else
        this.setForeground( this.getTextNonSelectionColor() );
    setComponentOrientation(tree.getComponentOrientation());
    // Set the selected state of the current icon :
    final Icon currentIcon = this.getIcon();
    if( currentIcon instanceof SelfDrawingIcon )
     {
        final SelfDrawingIcon selfDrawingIcon = (SelfDrawingIcon)currentIcon;
        selfDrawingIcon.setSelected(this.selected);
        selfDrawingIcon.setSelectionColor( this.getBackgroundSelectionColor() );
     }
    return this;
  } // getTreeCellRendererComponent






  public void updateSpecialUI()
  {
    setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
    setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
    setOpenIcon(UIManager.getIcon("Tree.openIcon"));
    setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
    setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
    setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
    setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
    setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
  }




  
} // DepositoryTreeCellRenderer




java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.