EchoPoint
1.0

echopoint.tree
Class DefaultTreeCellRenderer

java.lang.Object
  extended bynextapp.echo.Component
      extended bynextapp.echo.Label
          extended byechopoint.tree.DefaultTreeCellRenderer
All Implemented Interfaces:
ReflectionSetter, java.io.Serializable, TreeCellRenderer

public class DefaultTreeCellRenderer
extends nextapp.echo.Label
implements TreeCellRenderer, ReflectionSetter

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 Label 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.

See Also:
Serialized Form

Nested Class Summary
static class DefaultTreeCellRenderer.NestedStyleInfo
          Nested public static StyleInfo class.
 
Field Summary
static java.lang.String STYLE_BACKGROUND_NON_SELECTION_COLOR
          A style constant for the Background Non Selection Color property.
static java.lang.String STYLE_BACKGROUND_SELECTION_COLOR
          A style constant for the Background Selection Color property.
static java.lang.String STYLE_TEXT_NON_SELECTION_COLOR
          A style constant for the Text Non Selection Color property.
static java.lang.String STYLE_TEXT_SELECTION_COLOR
          A style constant for the Text Selection Color property.
 
Fields inherited from class nextapp.echo.Label
HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, ICON_TEXT_MARGIN_CHANGED_PROPERTY, STYLE_HORIZONTAL_ALIGNMENT, STYLE_HORIZONTAL_TEXT_POSITION, STYLE_ICON_TEXT_MARGIN, STYLE_VERTICAL_ALIGNMENT, STYLE_VERTICAL_TEXT_POSITION, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
Fields inherited from class nextapp.echo.Component
BACKGROUND_CHANGED_PROPERTY, CHILDREN_CHANGED_PROPERTY, ENABLED_CHANGED_PROPERTY, FONT_CHANGED_PROPERTY, FOREGROUND_CHANGED_PROPERTY, IDENTIFIER_CHANGED_PROPERTY, listenerList, LOCALE_CHANGED_PROPERTY, MODEL_CHANGED_PROPERTY, STYLE_BACKGROUND, STYLE_FONT, STYLE_FOREGROUND, UPDATE_PROPERTY, VISIBLE_CHANGED_PROPERTY
 
Constructor Summary
DefaultTreeCellRenderer()
          Creates a new instance of DefaultTreeCellRenderer.
 
Method Summary
 void applyStyle(nextapp.echo.Style style)
           
 nextapp.echo.Color getBackgroundNonSelectionColor()
          Returns the background color to be used for non selected nodes.
 nextapp.echo.Color getBackgroundSelectionColor()
          Returns the color to use for the background if node is selected.
 nextapp.echo.Color getTextNonSelectionColor()
          Returns the color the text is drawn with when the node isn't selected.
 nextapp.echo.Color getTextSelectionColor()
          Returns the color the text is drawn with when the node is selected.
 nextapp.echo.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.
 nextapp.echo.Label getTreeCellRendererText(Tree tree, java.lang.Object node, boolean sel, boolean expanded, boolean leaf)
          Configures the renderer based on the passed in parameters.
 java.lang.Object set(java.lang.reflect.Field field, java.lang.Object newValue)
          Called to save the old value of a field, set in a new value and return the old value of a field.
 void setBackgroundNonSelectionColor(nextapp.echo.Color newColor)
          Sets the background color to be used for non selected nodes.
 void setBackgroundSelectionColor(nextapp.echo.Color newColor)
          Sets the color to use for the background if node is selected.
 void setTextNonSelectionColor(nextapp.echo.Color newColor)
          Sets the color the text is drawn with when the node isn't selected.
 void setTextSelectionColor(nextapp.echo.Color newColor)
          Sets the color the text is drawn with when the node is selected.
 
Methods inherited from class nextapp.echo.Label
getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextMargin, getText, getVerticalAlignment, getVerticalTextPosition, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextMargin, setText, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class nextapp.echo.Component
add, add, addHierarchyListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getComponent, getComponentCount, getComponents, getEchoInstance, getFont, getForeground, getIdentifier, getLocale, getParent, indexOf, init, isAncestorOf, isEnabled, isRegistered, isShowing, isVisible, remove, remove, removeAll, removeHierarchyListener, removePropertyChangeListener, setBackground, setEnabled, setFont, setForeground, setIdentifier, setLocale, setVisible, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_BACKGROUND_NON_SELECTION_COLOR

public static final java.lang.String STYLE_BACKGROUND_NON_SELECTION_COLOR
A style constant for the Background Non Selection Color property. Values of this key must be of type nextapp.echo.Color.

See Also:
Constant Field Values

STYLE_BACKGROUND_SELECTION_COLOR

public static final java.lang.String STYLE_BACKGROUND_SELECTION_COLOR
A style constant for the Background Selection Color property. Values of this key must be of type nextapp.echo.Color.

See Also:
Constant Field Values

STYLE_TEXT_NON_SELECTION_COLOR

public static final java.lang.String STYLE_TEXT_NON_SELECTION_COLOR
A style constant for the Text Non Selection Color property. Values of this key must be of type nextapp.echo.Color.

See Also:
Constant Field Values

STYLE_TEXT_SELECTION_COLOR

public static final java.lang.String STYLE_TEXT_SELECTION_COLOR
A style constant for the Text Selection Color property. Values of this key must be of type nextapp.echo.Color.

See Also:
Constant Field Values
Constructor Detail

DefaultTreeCellRenderer

public DefaultTreeCellRenderer()
Creates a new instance of DefaultTreeCellRenderer.

Method Detail

applyStyle

public void applyStyle(nextapp.echo.Style style)
See Also:
Component.applyStyle(nextapp.echo.Style)

getBackgroundNonSelectionColor

public nextapp.echo.Color getBackgroundNonSelectionColor()
Returns the background color to be used for non selected nodes.


getBackgroundSelectionColor

public nextapp.echo.Color getBackgroundSelectionColor()
Returns the color to use for the background if node is selected.


getTextNonSelectionColor

public nextapp.echo.Color getTextNonSelectionColor()
Returns the color the text is drawn with when the node isn't selected.


getTextSelectionColor

public nextapp.echo.Color getTextSelectionColor()
Returns the color the text is drawn with when the node is selected.


getTreeCellRendererComponent

public nextapp.echo.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.

getTreeCellRendererText

public nextapp.echo.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 Label is set based on the selection while the icon is set based on on leaf and expanded.

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

Specified by:
getTreeCellRendererText in interface TreeCellRenderer
Returns:
Label that is used to draw the Tree cell.

setBackgroundNonSelectionColor

public void setBackgroundNonSelectionColor(nextapp.echo.Color newColor)
Sets the background color to be used for non selected nodes.


setBackgroundSelectionColor

public void setBackgroundSelectionColor(nextapp.echo.Color newColor)
Sets the color to use for the background if node is selected.


setTextNonSelectionColor

public void setTextNonSelectionColor(nextapp.echo.Color newColor)
Sets the color the text is drawn with when the node isn't selected.


setTextSelectionColor

public void setTextSelectionColor(nextapp.echo.Color newColor)
Sets the color the text is drawn with when the node is selected.


set

public java.lang.Object set(java.lang.reflect.Field field,
                            java.lang.Object newValue)
                     throws java.lang.Exception
Description copied from interface: ReflectionSetter
Called to save the old value of a field, set in a new value and return the old value of a field. This interface allows a field set operation to be "delegated" back into the class that has permission to perform the field set.

 public Object set(Field f, Object newValue) throws Exception {
      Object oldValue = f.get(this);
      f.set(this,newValue);
      return oldValue;
 }
 

Specified by:
set in interface ReflectionSetter
Parameters:
field - - the field to be set
newValue - - the new value to be set
Returns:
the oldValue of the field
Throws:
java.lang.Exception
See Also:
ReflectionSetter.set(Field, Object)

EchoPoint
1.0