public class SwingNodeRenderer extends java.lang.Object implements NodeRenderer
Constructor and Description |
---|
SwingNodeRenderer(java.awt.Container container)
Creates a new SwingNodeRenderer object.
|
SwingNodeRenderer(java.awt.Container container,
javax.swing.JComponent template)
Creates a new SwingNodeRenderer object.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(java.util.EventListener eventListener,
java.lang.String type)
Goes through the component list, adding listeners of the appropriate
type and adding them to each component for each node.
|
protected javax.swing.JComponent |
createComponent(java.lang.Object node)
Creates the component used to render the specified node.
|
void |
drawNode(java.awt.Graphics g,
java.lang.Object node,
java.awt.Point loc)
Draws the node into the Graphics Context.
|
java.awt.Color |
getColor()
Gets the color for the Renderer, if any.
|
javax.swing.JComponent |
getComponent(java.lang.Object node)
Gets the component used to draw a particular node.
|
java.lang.Object |
getNode(javax.swing.JComponent comp)
Gets the node associated with a given Swing component.
|
java.awt.Rectangle |
getNodeBounds(java.lang.Object node,
java.awt.Point loc)
Returns the bounding box for the node using this renderer.
|
boolean |
getUseSwingColors()
Gets the flag indicating whether this renderer should use the native
Swing colors.
|
void |
highlightNode(java.awt.Graphics g,
java.lang.Object node,
java.awt.Point loc)
Highlights the node into the Graphics Context.
|
boolean |
pickNode(java.lang.Object node,
java.awt.Point loc,
java.awt.Point pickPoint)
Checks whether the specified pickpoint is within the drawn area for the
node.
|
void |
setColor(java.awt.Color color)
Sets the color for the NodeRenderer.
|
void |
setTemplate(javax.swing.JComponent template)
Sets the template.
|
void |
setUseSwingColors(boolean flag)
Sets the flag indicating whether this renderer should use the native
Swing colors.
|
public SwingNodeRenderer(java.awt.Container container)
container
- The container to draw components inpublic SwingNodeRenderer(java.awt.Container container, javax.swing.JComponent template)
container
- The container to draw components intemplate
- the template component, used as an example for rendering
the nodespublic void addListener(java.util.EventListener eventListener, java.lang.String type) throws java.lang.IllegalArgumentException
eventListener
- a listenertype
- the type of listener. For instance, if adding an
ActionListener, type should be "Action"java.lang.IllegalArgumentException
- thrown if the type string doesn't match
the EventListener, or if the type String indicates an
invalid Listener type.protected javax.swing.JComponent createComponent(java.lang.Object node)
setText()
to set
the component text value. The argument for this is the String obtained
by invoking toString()
on the node. The listener, if set,
is also added to this node, if the component type allows the listener.node
- the node to renderpublic void drawNode(java.awt.Graphics g, java.lang.Object node, java.awt.Point loc)
drawNode
in interface NodeRenderer
g
- the Graphics context to display the nodenode
- the node to displayloc
- The node locationpublic java.awt.Color getColor()
getColor
in interface NodeRenderer
public javax.swing.JComponent getComponent(java.lang.Object node)
node
- The node to querypublic java.lang.Object getNode(javax.swing.JComponent comp)
comp
- the Swing componentpublic java.awt.Rectangle getNodeBounds(java.lang.Object node, java.awt.Point loc)
getNodeBounds
in interface NodeRenderer
node
- the Node to calculate the bounds forloc
- The node locationpublic boolean getUseSwingColors()
public void highlightNode(java.awt.Graphics g, java.lang.Object node, java.awt.Point loc)
highlightNode
in interface NodeRenderer
g
- the Graphics context to display the nodenode
- the node to displayloc
- The node locationpublic boolean pickNode(java.lang.Object node, java.awt.Point loc, java.awt.Point pickPoint)
pickNode
in interface NodeRenderer
node
- the node to check for pickingpickPoint
- the coordinate of the point to checkloc
- The node locationpublic void setColor(java.awt.Color color)
setColor
in interface NodeRenderer
color
- the color for this rendererpublic void setTemplate(javax.swing.JComponent template)
template
- the new templatepublic void setUseSwingColors(boolean flag)
flag
- whether to use the native Swing color scheme