|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.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.
| 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 |
|
| 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. |
| Field Detail |
|---|
private final Color nonSelColor
private Map renderers
private double scale
private final Color selColor
private JTree tree
| Constructor Detail |
|---|
public ComponentTreeCellRenderer(JTree tree, double scale)
ComponentTreeCellRenderer suitable for rendering scaled
snapshots of Swing components. This class is intended for use with
a JTree that has a ComponentTreeModel.
tree - the tree of componentsscale - the scale at which to render the components
| Method Detail |
|---|
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
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()
public void refresh()
private DefaultTreeCellRenderer rendererForComponent(JComponent component, JTree tree)
component - the componenttree - the tree
public void setScale(double scale)
Setting the scale will also refresh the tree using the current state of the components
scale - the scale at which to render the components
Groovy Documentation