Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table.group
Class DefaultTreeTableHeaderRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.CellRendererPane
              extended by com.sciapp.table.WrapperCellRendererPane
                  extended by com.sciapp.table.group.DefaultTreeTableHeaderRenderer
All Implemented Interfaces:
TreeTableHeaderRenderer, ImageObserver, MenuContainer, Serializable, Accessible

public class DefaultTreeTableHeaderRenderer
extends WrapperCellRendererPane
implements TreeTableHeaderRenderer

DefaultTreeTableHeaderRenderer is the default implementation of a TreeTableHeaderRenderer that uses a panel to layout a JTree's expansion control.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.CellRendererPane
CellRendererPane.AccessibleCellRendererPane
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  TreeTableColumnModelAdapter adapter
          the treetable column model adapter
protected  int column
          the column index of the cell being drawn
protected  Rectangle expansionControl
          a rectangle that holds the bounds of the expansion control
protected  Rectangle expansionFrame
          a rectangle that holds the bounds of the expansion frame
protected  boolean isExpanded
          flag that determines whether the path is expanded
protected  boolean isLeaf
          flag that determines whether the path is a leaf node
protected  TreePath path
          the path to draw
protected  Dimension preferredSize
          the preferred size of this component
protected  int row
          the row index of the cell being drawn
protected  boolean separate
          flag that determines whether a separate component should be used to layout the expansion control
 
Fields inherited from class com.sciapp.table.WrapperCellRendererPane
opaqueFalse
 
Fields inherited from class javax.swing.CellRendererPane
accessibleContext
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DefaultTreeTableHeaderRenderer()
          Creates a DefaultTreeTableHeaderRenderer.
DefaultTreeTableHeaderRenderer(TableCellRenderer expandRenderer)
          Creates a DefaultTreeTableHeaderRenderer.
 
Method Summary
protected  Icon createCollapsedIcon()
          Creates and returns an icon that represents the collapsed state of a 'non-leaf' column.
protected  Icon createExpandedIcon()
          Creates and returns an icon that represents the expanded state of a 'non-leaf' column.
 Component getMainComponent()
          Returns the main wrapped component.
 Dimension getPreferredSize()
          Returns the preferred size of this container.
 String getToolTipText(MouseEvent event)
          Returns the string to be used as the tooltip for event.
 Component getTreeTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, boolean isLeaf, boolean isExpanded, TreeTableColumnModelAdapter adapter, TreePath path, TableCellRenderer cellRenderer, int level)
          Returns the component used for drawing the expandable column header.
 boolean getUseSeparateComponent()
          Determines whether a separate component is used to layout the expansion control.
 boolean handleEvent(MouseEvent e, TreeTableHeader header)
          Handles a mouse event on this component.
 void setBounds(int x, int y, int w, int h)
          Moves and resizes this component.
 void setUseSeparateComponent(boolean separate)
          Defines whether a separate component is used to layout the expansion control.
protected  boolean swapExpandedState(MouseEvent e, TreeTableHeader header)
          Changes the expanded state of a non-leaf column, according to a mouse event on the header.
 
Methods inherited from class com.sciapp.table.WrapperCellRendererPane
getMainComponent, paint, paintComponent
 
Methods inherited from class javax.swing.CellRendererPane
addImpl, getAccessibleContext, invalidate, paintComponent, paintComponent, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

row

protected int row
the row index of the cell being drawn


column

protected int column
the column index of the cell being drawn


isLeaf

protected boolean isLeaf
flag that determines whether the path is a leaf node


isExpanded

protected boolean isExpanded
flag that determines whether the path is expanded


adapter

protected TreeTableColumnModelAdapter adapter
the treetable column model adapter


path

protected TreePath path
the path to draw


preferredSize

protected Dimension preferredSize
the preferred size of this component


separate

protected boolean separate
flag that determines whether a separate component should be used to layout the expansion control


expansionFrame

protected final transient Rectangle expansionFrame
a rectangle that holds the bounds of the expansion frame


expansionControl

protected final transient Rectangle expansionControl
a rectangle that holds the bounds of the expansion control

Constructor Detail

DefaultTreeTableHeaderRenderer

public DefaultTreeTableHeaderRenderer()
Creates a DefaultTreeTableHeaderRenderer.


DefaultTreeTableHeaderRenderer

public DefaultTreeTableHeaderRenderer(TableCellRenderer expandRenderer)
Creates a DefaultTreeTableHeaderRenderer.

Method Detail

createCollapsedIcon

protected Icon createCollapsedIcon()
Creates and returns an icon that represents the collapsed state of a 'non-leaf' column.

Returns:
the collapsed icon

createExpandedIcon

protected Icon createExpandedIcon()
Creates and returns an icon that represents the expanded state of a 'non-leaf' column.

Returns:
the expanded icon

getMainComponent

public Component getMainComponent()
Returns the main wrapped component. By default, this is returned.

Overrides:
getMainComponent in class WrapperCellRendererPane
Returns:
the wrapped component

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of this container.

Overrides:
getPreferredSize in class Container
Returns:
an instance of Dimension that represents the preferred size of this container.
See Also:
Container.getMinimumSize(), Container.getLayout(), LayoutManager.preferredLayoutSize(Container), Component.getPreferredSize()

getToolTipText

public String getToolTipText(MouseEvent event)
Returns the string to be used as the tooltip for event.

Overrides:
getToolTipText in class WrapperCellRendererPane
Parameters:
event - the mouse event producing the tooltip
Returns:
the tooltip's text

getTreeTableCellRendererComponent

public Component getTreeTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row,
                                                   int column,
                                                   boolean isLeaf,
                                                   boolean isExpanded,
                                                   TreeTableColumnModelAdapter adapter,
                                                   TreePath path,
                                                   TableCellRenderer cellRenderer,
                                                   int level)
Returns the component used for drawing the expandable column header. This method is used to configure the renderer appropriately before drawing.

Specified by:
getTreeTableCellRendererComponent in interface TreeTableHeaderRenderer
Parameters:
table - the JTable that is asking the renderer to draw; can be null
value - the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
hasFocus - if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
row - the row index of the cell being drawn. When drawing the header, the value of row is -1
column - the column index of the cell being drawn
isLeaf - true if the tree node displayed is a leaf node, false otherwise
isExpanded - true if the column is expanded, false otherwise
adapter - the treetable column model adapter used
path - identifies the tree path to draw
cellRenderer - the renderer of the column being drawn
level - the group level at which the component will be shown
Returns:
the component used for drawing the expandable column header.

getUseSeparateComponent

public boolean getUseSeparateComponent()
Determines whether a separate component is used to layout the expansion control.

Returns:
true if a separate component is used, false otherwise

handleEvent

public boolean handleEvent(MouseEvent e,
                           TreeTableHeader header)
Handles a mouse event on this component.

Specified by:
handleEvent in interface TreeTableHeaderRenderer
Parameters:
e - the mouse event that triggered the method
header - the header source of the event
Returns:
true, if the event should be consumed, false otherwise

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Overrides:
setBounds in class Component
Parameters:
x - the new x-coordinate of this component
y - the new y-coordinate of this component
w - the new width of this component
h - the new height of this component
See Also:
Component.getBounds(), Component.setLocation(int, int), Component.setLocation(Point), Component.setSize(int, int), Component.setSize(Dimension)

setUseSeparateComponent

public void setUseSeparateComponent(boolean separate)
Defines whether a separate component is used to layout the expansion control. The default is true.

Parameters:
separate - true if a separate component should be used, false otherwise

swapExpandedState

protected boolean swapExpandedState(MouseEvent e,
                                    TreeTableHeader header)
Changes the expanded state of a non-leaf column, according to a mouse event on the header.

Parameters:
e - the mouse event responsible for the state change
header - the header source of the event
Returns:
true if the mouse event was inside the borders of the expansion control, false otherwise

Copyright © 2005 Scientific Applications. All Rights Reserved.