EchoPoint
2.1.0rc5

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, 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 String PROPERTY_SELECTED_BACKGROUND
           
static String PROPERTY_SELECTED_FONT
           
static String PROPERTY_SELECTED_FOREGROUND
           
static Font.Typeface TYPEFACE
           
 
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, Object node, boolean selected, boolean expanded, boolean leaf)
          Returns a Component that will be rendered as a Tree cell.
 Label getTreeCellRendererText(Tree tree, Object node, boolean sel, boolean expanded, boolean leaf)
          Configures the renderer based on the passed in parameters.
 XhtmlFragment getTreeCellRendererXhtml(Tree tree, Object node, boolean selected, boolean expanded, boolean leaf)
          Returns a XhtmlFragment that will be rendered as a Tree cell.
 void setBackground(Color newValue)
           
 void setFont(Font newValue)
           
 void setForeground(Color newValue)
           
 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, setRenderId, 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

TYPEFACE

public static final Font.Typeface TYPEFACE

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 String PROPERTY_SELECTED_BACKGROUND
See Also:
Constant Field Values

PROPERTY_SELECTED_FOREGROUND

public static final String PROPERTY_SELECTED_FOREGROUND
See Also:
Constant Field Values

PROPERTY_SELECTED_FONT

public static final 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)
Overrides:
setBackground in class Component
See Also:
Component.setBackground(nextapp.echo2.app.Color)

setForeground

public void setForeground(Color newValue)
Overrides:
setForeground in class Component
See Also:
Component.setForeground(nextapp.echo2.app.Color)

setFont

public void setFont(Font newValue)
Overrides:
setFont in class Component
See Also:
Component.setFont(nextapp.echo2.app.Font)

getTreeCellRendererComponent

public Component getTreeCellRendererComponent(Tree tree,
                                              Object node,
                                              boolean selected,
                                              boolean expanded,
                                              boolean leaf)
Description copied from interface: TreeCellRenderer
Returns a Component that will be rendered as a Tree cell.

If selected is true, the cell will be drawn as if selected. If expanded is true the node is currently expanded and if leaf is true the node represets a leaf tree is the Tree the receiver is being configured for.

This method is called second by the tree rendering code, and only after the getTreeCellRendererText method has returned null.

The returned Component MUST be a unqiue Component since it will be rendered as the Tree cell.

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

getTreeCellRendererXhtml

public XhtmlFragment getTreeCellRendererXhtml(Tree tree,
                                              Object node,
                                              boolean selected,
                                              boolean expanded,
                                              boolean leaf)
Description copied from interface: TreeCellRenderer
Returns a XhtmlFragment that will be rendered as a Tree cell.

If selected is true, the cell will be drawn as if selected. If expanded is true the node is currently expanded and if leaf is true the node represets a leaf tree is the Tree the receiver is being configured for.

This method is called third by the Tree rendering code, and only after the getTreeCellRendererText and getTreeCellRendererComponent method have returned null.

Specified by:
getTreeCellRendererXhtml in interface TreeCellRenderer
Returns:
the XhtmlFragment that is used to draw the cell value.
See Also:
TreeCellRenderer.getTreeCellRendererXhtml(echopointng.Tree, java.lang.Object, boolean, boolean, boolean)

getTreeCellRendererText

public Label getTreeCellRendererText(Tree tree,
                                     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)

EchoPoint
2.1.0rc5