ca.odell.glazedlists.swing
Class TreeTableCellPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ca.odell.glazedlists.swing.TreeTableCellPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class TreeTableCellPanel
extends JPanel

This panel exists to relieve the burdens of creating a TableCellRenderer or TableCellEditor that is appropriate for use in a hierarchy column of a tree table. Specifically, it combines three different components to produce a single panel. Those components are:

The components are arranged on the panel like this:

[indent pixels] [expand/collapse button] [spacer pixels] [nodeComponent]

Author:
James Lemieux
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
TreeTableCellPanel()
           
 
Method Summary
 void configure(TreeNodeData treeNodeData, boolean showExpanderForEmptyParent, Component nodeComponent, boolean hasFocus, int indent, int spacer)
          This method adjusts the contents of this panel to display thse given nodeComponent.
 Component getNodeComponent()
          Return the Component that displays the data of the tree node.
 boolean isPointOverExpanderButton(Point p)
          Returns true if p occurs within the bounds of the expander button; false otherwise.
 boolean isPointOverNodeComponent(Point p)
          Returns true if p occurs within the bounds of the node component; false otherwise.
protected  boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
          This method is called by Swing when the TreeTableCellPanel is installed as a TableCellEditor.
 void setBackground(Color bg)
          Set the background color of the TreeTableCellPanel and node component.
 void setFont(Font font)
          Set the font of the TreeTableCellPanel and its inner node component.
 void setForeground(Color fg)
          Set the foreground color of the TreeTableCellPanel and node component.
 void setNextFocusableComponent(Component aComponent)
          This method is called by Swing when installing this TreeTableCellPanel as a TableCellEditor.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeTableCellPanel

public TreeTableCellPanel()
Method Detail

configure

public void configure(TreeNodeData treeNodeData,
                      boolean showExpanderForEmptyParent,
                      Component nodeComponent,
                      boolean hasFocus,
                      int indent,
                      int spacer)
This method adjusts the contents of this panel to display thse given nodeComponent. Specifically, the panel is layed out like so:

[indent pixels] [expand/collapse button] [spacer pixels] [nodeComponent]

The expand/collapse button is visible if TreeNodeData.isExpanded() returns true. The expander button's icon is either a traditional plus or minus icon depending on the value of TreeNodeData.isExpanded().

The nodeComponent is displayed unmodified.

Parameters:
treeNodeData - hierarhical information about the node within the tree
showExpanderForEmptyParent - true indicates the expander button should always be present, even when no children yet exist
nodeComponent - a Component which displays the data of the tree node
hasFocus - true indicates the cell currently has the focus
indent - the amount of space between the left cell edge and the expand/collapse button
spacer - the amount of space between the right edge of the expand/collapse button and the nodeComponent

setBackground

public void setBackground(Color bg)
Set the background color of the TreeTableCellPanel and node component.

Overrides:
setBackground in class JComponent

setForeground

public void setForeground(Color fg)
Set the foreground color of the TreeTableCellPanel and node component.

Overrides:
setForeground in class JComponent

setFont

public void setFont(Font font)
Set the font of the TreeTableCellPanel and its inner node component.

Overrides:
setFont in class JComponent

getNodeComponent

public Component getNodeComponent()
Return the Component that displays the data of the tree node.


isPointOverExpanderButton

public boolean isPointOverExpanderButton(Point p)
Returns true if p occurs within the bounds of the expander button; false otherwise.


isPointOverNodeComponent

public boolean isPointOverNodeComponent(Point p)
Returns true if p occurs within the bounds of the node component; false otherwise.


processKeyBinding

protected boolean processKeyBinding(KeyStroke ks,
                                    KeyEvent e,
                                    int condition,
                                    boolean pressed)
This method is called by Swing when the TreeTableCellPanel is installed as a TableCellEditor. It gives the component a chance to process the KeyEvent. For example, a JTextField will honour the keystroke and add the letter to its Document. The TreeTableCellPanel's main job is to pass the KeyEvent on to the underlying nodeComponent so that it may have a chance to react. This only need occur once for the KeyEvent that caused the cell edit, after which time the focus will be within the nodeComponent and subsequent keystrokes should be ignored.

Overrides:
processKeyBinding in class JComponent

setNextFocusableComponent

public void setNextFocusableComponent(Component aComponent)
This method is called by Swing when installing this TreeTableCellPanel as a TableCellEditor. It ensures that focus will return to the JTable when the cell edit is complete.

We override this method to ensure that if the nodeComponent acting as the child editor of the TreeTableCellPanel has focus when the cell edit is complete, focus is returned to the JTable in that case as well.

Overrides:
setNextFocusableComponent in class JComponent


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by hbrands at 2015-02-16 14:02