echopointng.tree
Class DefaultTreeCellRenderer

java.lang.Object
  extended by nextapp.echo2.app.Component
      extended by nextapp.echo2.app.Label
          extended by echopointng.tree.DefaultTreeCellRenderer
All Implemented Interfaces:
TreeCellRenderer, java.io.Serializable, RenderIdSupport

public class DefaultTreeCellRenderer
extends Label
implements TreeCellRenderer

Used to display an entry in a tree. If the tree cell value is a DefaultMutableTreeNode and its user object is a Component then the DefaultTreeCellRenderer will return null on getTreeCellRenderText and return the Component in getTreeCellRendererComponent.

Otherwise it will "cast" the cell value to a String via toString() and return a LabelEx via the getTreeCellRenderText method. It uses the Tree's TreeIcon object to obtain an icon for "parent" and "leaf" nodes.

You can derived your own TreeCellRendererclass from this one and specify your own icons for each node if you wish.

Note that this class also has Style support so you can set appearance attributes via a Style object or the EchoPoint CSS support.

The standard LabelEx background, foreground and font properties are used for non selected tree cell nodes. The selectedBackground, selectedForeground and selectedFont properties are used for selected tree cell nodes.

See Also:
Serialized Form

Field Summary
static Font DEFAULT_FONT
          The default Tree Cell Font
static Color DEFAULT_SELECTED_BACKGROUND
          The default Selected Tree Cell Background
static Font DEFAULT_SELECTED_FONT
          The default Selected Tree Cell Font
static Color DEFAULT_SELECTED_FOREGROUND
          The default Selected Tree Cell FOREGROUND
static java.lang.String PROPERTY_SELECTED_BACKGROUND
           
static java.lang.String PROPERTY_SELECTED_FONT
           
static java.lang.String PROPERTY_SELECTED_FOREGROUND
           
 
Fields inherited from class nextapp.echo2.app.Label
PROPERTY_ICON, PROPERTY_ICON_TEXT_MARGIN, PROPERTY_LINE_WRAP, PROPERTY_TEXT, PROPERTY_TEXT_ALIGNMENT, PROPERTY_TEXT_POSITION, PROPERTY_TOOL_TIP_TEXT
 
Fields inherited from class nextapp.echo2.app.Component
CHILDREN_CHANGED_PROPERTY, ENABLED_CHANGED_PROPERTY, FOCUS_TRAVERSAL_INDEX_CHANGED_PROPERTY, FOCUS_TRAVERSAL_PARTICIPANT_CHANGED_PROPERTY, LAYOUT_DIRECTION_CHANGED_PROPERTY, LOCALE_CHANGED_PROPERTY, PROPERTY_BACKGROUND, PROPERTY_FONT, PROPERTY_FOREGROUND, PROPERTY_LAYOUT_DATA, STYLE_CHANGED_PROPERTY, STYLE_NAME_CHANGED_PROPERTY, VISIBLE_CHANGED_PROPERTY
 
Constructor Summary
DefaultTreeCellRenderer()
          Creates a new instance of DefaultTreeCellRenderer.
 
Method Summary
 Color getSelectedBackground()
           
 Font getSelectedFont()
           
 Color getSelectedForeground()
           
 Component getTreeCellRendererComponent(Tree tree, java.lang.Object node, boolean selected, boolean expanded, boolean leaf)
          If the value is a Component then it will be returned as is, otherwise it returns null.
 Label getTreeCellRendererText(Tree tree, java.lang.Object node, boolean sel, boolean expanded, boolean leaf)
          Configures the renderer based on the passed in parameters.
 void setBackground(Color newValue)
          Sets the default background color of the Component.
 void setFont(Font newValue)
          Sets the default text font of the Component.
 void setForeground(Color newValue)
          Sets the default foreground color of the Component.
 void setSelectedBackground(Color newValue)
          Sets the background color to be used for selected tree cell nodes.
 void setSelectedFont(Font newValue)
          Sets the font to be used for selected tree cell nodes.
 void setSelectedForeground(Color newValue)
          Sets the foreground color to be used for selected tree cell nodes.
 
Methods inherited from class nextapp.echo2.app.Label
getIcon, getIconTextMargin, getText, getTextAlignment, getTextPosition, getToolTipText, isLineWrap, isValidChild, setIcon, setIconTextMargin, setLineWrap, setText, setTextAlignment, setTextPosition, setToolTipText
 
Methods inherited from class nextapp.echo2.app.Component
add, add, addPropertyChangeListener, dispose, firePropertyChange, getApplicationInstance, getBackground, getComponent, getComponent, getComponentCount, getComponents, getEventListenerList, getFocusTraversalIndex, getFont, getForeground, getId, getIndexedProperty, getLayoutData, getLayoutDirection, getLocale, getParent, getProperty, getRenderId, getRenderIndexedProperty, getRenderIndexedProperty, getRenderLayoutDirection, getRenderLocale, getRenderProperty, getRenderProperty, getStyle, getStyleName, getVisibleComponent, getVisibleComponentCount, getVisibleComponents, hasEventListenerList, indexOf, init, isAncestorOf, isEnabled, isFocusTraversalParticipant, isRegistered, isRenderEnabled, isRenderVisible, isValidParent, isVisible, processInput, remove, remove, removeAll, removePropertyChangeListener, setEnabled, setFocusTraversalIndex, setFocusTraversalParticipant, setId, setIndexedProperty, setLayoutData, setLayoutDirection, setLocale, setProperty, setStyle, setStyleName, setVisible, validate, verifyInput, visibleIndexOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FONT

public static final Font DEFAULT_FONT
The default Tree Cell Font


DEFAULT_SELECTED_BACKGROUND

public static final Color DEFAULT_SELECTED_BACKGROUND
The default Selected Tree Cell Background


DEFAULT_SELECTED_FOREGROUND

public static final Color DEFAULT_SELECTED_FOREGROUND
The default Selected Tree Cell FOREGROUND


DEFAULT_SELECTED_FONT

public static final Font DEFAULT_SELECTED_FONT
The default Selected Tree Cell Font


PROPERTY_SELECTED_BACKGROUND

public static final java.lang.String PROPERTY_SELECTED_BACKGROUND
See Also:
Constant Field Values

PROPERTY_SELECTED_FOREGROUND

public static final java.lang.String PROPERTY_SELECTED_FOREGROUND
See Also:
Constant Field Values

PROPERTY_SELECTED_FONT

public static final java.lang.String PROPERTY_SELECTED_FONT
See Also:
Constant Field Values
Constructor Detail

DefaultTreeCellRenderer

public DefaultTreeCellRenderer()
Creates a new instance of DefaultTreeCellRenderer.

Method Detail

getSelectedBackground

public Color getSelectedBackground()
Returns:
the background color to be used for selected tree cell nodes.

getSelectedForeground

public Color getSelectedForeground()
Returns:
the foreground color to be used for selected tree cell nodes.

getSelectedFont

public Font getSelectedFont()
Returns:
the font to be used for selected tree cell nodes.

setSelectedBackground

public void setSelectedBackground(Color newValue)
Sets the background color to be used for selected tree cell nodes.

Parameters:
newValue - - The newValue to set.

setSelectedForeground

public void setSelectedForeground(Color newValue)
Sets the foreground color to be used for selected tree cell nodes.

Parameters:
newValue - - The newValue to set.

setSelectedFont

public void setSelectedFont(Font newValue)
Sets the font to be used for selected tree cell nodes.

Parameters:
newValue - - The newValue to set.

setBackground

public void setBackground(Color newValue)
Description copied from class: Component
Sets the default background color of the Component.

Overrides:
setBackground in class Component
Parameters:
newValue - the new background Color
See Also:
Component.setBackground(nextapp.echo2.app.Color)

setForeground

public void setForeground(Color newValue)
Description copied from class: Component
Sets the default foreground color of the Component.

Overrides:
setForeground in class Component
Parameters:
newValue - the new foreground Color
See Also:
Component.setForeground(nextapp.echo2.app.Color)

setFont

public void setFont(Font newValue)
Description copied from class: Component
Sets the default text font of the Component.

Overrides:
setFont in class Component
Parameters:
newValue - the new Font
See Also:
Component.setFont(nextapp.echo2.app.Font)

getTreeCellRendererComponent

public Component getTreeCellRendererComponent(Tree tree,
                                              java.lang.Object node,
                                              boolean selected,
                                              boolean expanded,
                                              boolean leaf)
If the value is a Component then it will be returned as is, otherwise it returns null.

Specified by:
getTreeCellRendererComponent in interface TreeCellRenderer
Returns:
Component that is used to draw the value.
See Also:
TreeCellRenderer.getTreeCellRendererComponent(Tree, Object, boolean, boolean, boolean)

getTreeCellRendererText

public Label getTreeCellRendererText(Tree tree,
                                     java.lang.Object node,
                                     boolean sel,
                                     boolean expanded,
                                     boolean leaf)
Configures the renderer based on the passed in parameters.

The foreground color of the LabelEx is set based on the selection while the icon is set based on on leaf and expanded.

The same LabelEx object is returned for each call to this method. The Tree rendering code uses only the public properties of the return LabelEx. In fact since DefaultTreeCellRenderer is derived from LabelEx it simply returns itself.

Specified by:
getTreeCellRendererText in interface TreeCellRenderer
Returns:
LabelEx that is used to draw the Tree cell.
See Also:
TreeCellRenderer.getTreeCellRendererText(Tree, Object, boolean, boolean, boolean)