Groovy Documentation

com.wordpress.tipsforjava.swing.tree
[Java] Class ComponentTreeCellRenderer

java.lang.Object
  java.awt.Component
      java.awt.Container
          javax.swing.JComponent
              javax.swing.JLabel
                  javax.swing.tree.DefaultTreeCellRenderer
                      com.wordpress.tipsforjava.swing.tree.ComponentTreeCellRenderer

public class ComponentTreeCellRenderer
extends DefaultTreeCellRenderer

A tree cell renderer that displays scaled replicas of Swing components at the nodes of the tree.

Extends DefaultTreeCellRenderer.

Authors:
Rob Camick
Darryl Burke


Field Summary
private Color nonSelColor

private Map renderers

private double scale

private Color selColor

private JTree tree

 
Fields inherited from class DefaultTreeCellRenderer
CENTER, TOP, LEFT, BOTTOM, RIGHT, NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST, HORIZONTAL, VERTICAL, LEADING, TRAILING, NEXT, PREVIOUS, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT
 
Fields inherited from class JLabel
CENTER, TOP, LEFT, BOTTOM, RIGHT, NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST, HORIZONTAL, VERTICAL, LEADING, TRAILING, NEXT, PREVIOUS, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT
 
Constructor Summary
ComponentTreeCellRenderer(JTree tree, double scale)

Returns a ComponentTreeCellRenderer suitable for rendering scaled snapshots of Swing components.

 
Method Summary
Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)

Configures the renderer based on the passed in component.

void refresh()

Reloads the renderer cache using the current state of the components.

private DefaultTreeCellRenderer rendererForComponent(JComponent component, JTree tree)

Creates a renderer with a scaled image of the component

void setScale(double scale)

Sets the scale at which components will be rendered.

 
Methods inherited from class DefaultTreeCellRenderer
invalidate, validate, setFont, getPreferredSize, paint, getFont, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, setBackground, repaint, repaint, repaint, revalidate, getTreeCellRendererComponent, getDefaultOpenIcon, getDefaultClosedIcon, getDefaultLeafIcon, setOpenIcon, getOpenIcon, setClosedIcon, getClosedIcon, setLeafIcon, getLeafIcon, setTextSelectionColor, getTextSelectionColor, setTextNonSelectionColor, getTextNonSelectionColor, setBackgroundSelectionColor, getBackgroundSelectionColor, setBackgroundNonSelectionColor, getBackgroundNonSelectionColor, setBorderSelectionColor, getBorderSelectionColor, setText, getAccessibleContext, imageUpdate, setUI, updateUI, getUIClassID, getUI, getDisabledIcon, getDisplayedMnemonicIndex, setDisplayedMnemonicIndex, setHorizontalTextPosition, setVerticalTextPosition, getText, setIcon, setHorizontalAlignment, getIcon, setDisabledIcon, getVerticalAlignment, setVerticalAlignment, getHorizontalAlignment, getVerticalTextPosition, getHorizontalTextPosition, getIconTextGap, setIconTextGap, setDisplayedMnemonic, setDisplayedMnemonic, getDisplayedMnemonic, getLabelFor, setLabelFor, contains, getLocation, print, getSize, isOpaque, enable, disable, update, getY, getX, getInsets, getInsets, getMinimumSize, getMaximumSize, getAlignmentX, getAlignmentY, getListeners, addNotify, removeNotify, setFocusTraversalKeys, requestFocus, requestFocus, setEnabled, isDoubleBuffered, setVisible, setForeground, getBounds, reshape, getWidth, getHeight, setPreferredSize, setMinimumSize, setMaximumSize, getBaseline, getBaselineResizeBehavior, getGraphics, getFontMetrics, printAll, requestFocusInWindow, addAncestorListener, setInheritsPopupMenu, getInheritsPopupMenu, setComponentPopupMenu, getComponentPopupMenu, isPaintingTile, isPaintingForPrint, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setBorder, getBorder, setAlignmentY, setAlignmentX, setInputVerifier, getInputVerifier, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, getDefaultLocale, setDefaultLocale, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, getPopupLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, setTransferHandler, getTransferHandler, getClientProperty, putClientProperty, isLightweightComponent, setOpaque, computeVisibleRect, getVisibleRect, addVetoableChangeListener, removeVetoableChangeListener, getVetoableChangeListeners, getTopLevelAncestor, removeAncestorListener, getAncestorListeners, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, getRootPane, add, add, add, add, add, remove, remove, list, list, removeAll, getComponent, getComponentCount, countComponents, getComponents, insets, setComponentZOrder, getComponentZOrder, getLayout, setLayout, doLayout, layout, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, getContainerListeners, deliverEvent, getComponentAt, getComponentAt, locate, getMousePosition, findComponentAt, findComponentAt, isAncestorOf, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, isFocusCycleRoot, transferFocusBackward, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, setFocusTraversalPolicyProvider, isFocusTraversalPolicyProvider, transferFocusDownCycle, applyComponentOrientation, addPropertyChangeListener, addPropertyChangeListener, add, toString, getName, contains, size, getParent, getLocation, remove, setName, list, list, list, getSize, resize, resize, setSize, setSize, enable, location, isValid, setLocale, action, getMousePosition, getGraphicsConfiguration, dispatchEvent, isVisible, isEnabled, isDisplayable, isFocusable, getTreeLock, isLightweight, getPeer, isFocusOwner, transferFocus, isPreferredSizeSet, isMinimumSizeSet, isMaximumSizeSet, isShowing, handleEvent, postEvent, getFocusCycleRootAncestor, setDropTarget, getDropTarget, getToolkit, enableInputMethods, show, show, hide, getForeground, isForegroundSet, getBackground, isBackgroundSet, isFontSet, getLocale, getColorModel, getLocationOnScreen, setLocation, setLocation, move, getBounds, bounds, setBounds, setBounds, setCursor, getCursor, isCursorSet, paintAll, repaint, repaint, createImage, createImage, createVolatileImage, createVolatileImage, prepareImage, prepareImage, checkImage, checkImage, setIgnoreRepaint, getIgnoreRepaint, inside, addComponentListener, removeComponentListener, getComponentListeners, addFocusListener, removeFocusListener, getFocusListeners, addHierarchyListener, removeHierarchyListener, getHierarchyListeners, addHierarchyBoundsListener, removeHierarchyBoundsListener, getHierarchyBoundsListeners, addKeyListener, removeKeyListener, getKeyListeners, addMouseListener, removeMouseListener, getMouseListeners, addMouseMotionListener, removeMouseMotionListener, getMouseMotionListeners, addMouseWheelListener, removeMouseWheelListener, getMouseWheelListeners, addInputMethodListener, removeInputMethodListener, getInputMethodListeners, getInputMethodRequests, getInputContext, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, gotFocus, lostFocus, isFocusTraversable, setFocusable, setFocusTraversalKeysEnabled, getFocusTraversalKeysEnabled, nextFocus, transferFocusUpCycle, hasFocus, removePropertyChangeListener, removePropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, setComponentOrientation, getComponentOrientation, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 
Methods inherited from class JLabel
setText, getAccessibleContext, imageUpdate, setUI, updateUI, getUIClassID, getUI, getDisabledIcon, getDisplayedMnemonicIndex, setDisplayedMnemonicIndex, setHorizontalTextPosition, setVerticalTextPosition, getText, setIcon, setHorizontalAlignment, getIcon, setDisabledIcon, getVerticalAlignment, setVerticalAlignment, getHorizontalAlignment, getVerticalTextPosition, getHorizontalTextPosition, getIconTextGap, setIconTextGap, setDisplayedMnemonic, setDisplayedMnemonic, getDisplayedMnemonic, getLabelFor, setLabelFor, contains, getLocation, print, getSize, isOpaque, enable, disable, update, getY, getX, getInsets, getInsets, setFont, getPreferredSize, getMinimumSize, getMaximumSize, getAlignmentX, getAlignmentY, paint, getListeners, addNotify, removeNotify, setFocusTraversalKeys, requestFocus, requestFocus, firePropertyChange, firePropertyChange, firePropertyChange, setEnabled, isDoubleBuffered, setVisible, setForeground, setBackground, getBounds, reshape, getWidth, getHeight, setPreferredSize, setMinimumSize, setMaximumSize, getBaseline, getBaselineResizeBehavior, getGraphics, getFontMetrics, repaint, repaint, printAll, requestFocusInWindow, addAncestorListener, setInheritsPopupMenu, getInheritsPopupMenu, setComponentPopupMenu, getComponentPopupMenu, isPaintingTile, isPaintingForPrint, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setBorder, getBorder, setAlignmentY, setAlignmentX, setInputVerifier, getInputVerifier, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, getDefaultLocale, setDefaultLocale, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, getPopupLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, setTransferHandler, getTransferHandler, getClientProperty, putClientProperty, isLightweightComponent, setOpaque, computeVisibleRect, getVisibleRect, addVetoableChangeListener, removeVetoableChangeListener, getVetoableChangeListeners, getTopLevelAncestor, removeAncestorListener, getAncestorListeners, revalidate, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, getRootPane, add, add, add, add, add, remove, remove, list, list, removeAll, getComponent, invalidate, validate, getComponentCount, countComponents, getComponents, insets, setComponentZOrder, getComponentZOrder, getLayout, setLayout, doLayout, layout, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, getContainerListeners, deliverEvent, getComponentAt, getComponentAt, locate, getMousePosition, findComponentAt, findComponentAt, isAncestorOf, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, isFocusCycleRoot, transferFocusBackward, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, setFocusTraversalPolicyProvider, isFocusTraversalPolicyProvider, transferFocusDownCycle, applyComponentOrientation, addPropertyChangeListener, addPropertyChangeListener, add, toString, getName, contains, size, getParent, getLocation, remove, setName, list, list, list, getSize, resize, resize, setSize, setSize, enable, location, isValid, setLocale, action, getMousePosition, getGraphicsConfiguration, dispatchEvent, isVisible, isEnabled, isDisplayable, isFocusable, getTreeLock, isLightweight, getPeer, isFocusOwner, transferFocus, getFont, isPreferredSizeSet, isMinimumSizeSet, isMaximumSizeSet, isShowing, handleEvent, postEvent, getFocusCycleRootAncestor, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, setDropTarget, getDropTarget, getToolkit, enableInputMethods, show, show, hide, getForeground, isForegroundSet, getBackground, isBackgroundSet, isFontSet, getLocale, getColorModel, getLocationOnScreen, setLocation, setLocation, move, getBounds, bounds, setBounds, setBounds, setCursor, getCursor, isCursorSet, paintAll, repaint, repaint, repaint, createImage, createImage, createVolatileImage, createVolatileImage, prepareImage, prepareImage, checkImage, checkImage, setIgnoreRepaint, getIgnoreRepaint, inside, addComponentListener, removeComponentListener, getComponentListeners, addFocusListener, removeFocusListener, getFocusListeners, addHierarchyListener, removeHierarchyListener, getHierarchyListeners, addHierarchyBoundsListener, removeHierarchyBoundsListener, getHierarchyBoundsListeners, addKeyListener, removeKeyListener, getKeyListeners, addMouseListener, removeMouseListener, getMouseListeners, addMouseMotionListener, removeMouseMotionListener, getMouseMotionListeners, addMouseWheelListener, removeMouseWheelListener, getMouseWheelListeners, addInputMethodListener, removeInputMethodListener, getInputMethodListeners, getInputMethodRequests, getInputContext, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, gotFocus, lostFocus, isFocusTraversable, setFocusable, setFocusTraversalKeysEnabled, getFocusTraversalKeysEnabled, nextFocus, transferFocusUpCycle, hasFocus, removePropertyChangeListener, removePropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, setComponentOrientation, getComponentOrientation, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 

Field Detail

nonSelColor

private final Color nonSelColor


renderers

private Map renderers


scale

private double scale


selColor

private final Color selColor


tree

private JTree tree


 
Constructor Detail

ComponentTreeCellRenderer

public ComponentTreeCellRenderer(JTree tree, double scale)
Returns a ComponentTreeCellRenderer suitable for rendering scaled snapshots of Swing components. This class is intended for use with a JTree that has a ComponentTreeModel.
Parameters:
tree - the tree of components
scale - the scale at which to render the components
See Also:
ComponentTreeModel
DefaultTreeCellRenderer


 
Method Detail

getTreeCellRendererComponent

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
Configures the renderer based on the passed in component. The text and icon are set from the JComponent located as the userObject of the node and the scale, or the String returned by invoking String.valueOf on value if the object at the node is not a JComponent.

The background color is set based on the selection status and the icon is a scaled replica of the JComponent.

For the sake of performance, a renderer for each component is cached. The cache can be synchronized with the current state of the component hierarchy by invoking refresh()

See Also:
refresh()
DefaultTreeCellRenderer.getTreeCellRendererComponent


refresh

public void refresh()
Reloads the renderer cache using the current state of the components.


rendererForComponent

private DefaultTreeCellRenderer rendererForComponent(JComponent component, JTree tree)
Creates a renderer with a scaled image of the component
Parameters:
component - the component
tree - the tree
Returns:
a renderer for the component


setScale

public void setScale(double scale)
Sets the scale at which components will be rendered. The recommended range of vales is 0.1 to 1.0. Setting a scale much in excess of 1.0 may result in slow rendering of the tree.

Setting the scale will also refresh the tree using the current state of the components

Parameters:
scale - the scale at which to render the components
See Also:
refresh


 

Groovy Documentation