Package gov.nasa.worldwind.util.tree
Class BasicTreeLayout
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.util.tree.BasicTreeLayout
-
- All Implemented Interfaces:
AVList
,MessageListener
,PreRenderable
,Renderable
,Scrollable
,TreeLayout
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class BasicTreeLayout extends WWObjectImpl implements TreeLayout, Scrollable, PreRenderable
Layout that draws aTree
similar to a file browser tree.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BasicTreeLayout.NodeLayout
Class to hold information about how a tree node is laid out.protected static class
BasicTreeLayout.TextCacheKey
Cache key for cache text bound cache.
-
Field Summary
Fields Modifier and Type Field Description protected TreeAttributes
activeAttributes
Active attributes, either normal or highlight.protected long
attributesFrameNumber
protected static TreeAttributes
defaultAttributes
The attributes used if attributes are not specified.protected boolean
drawNodeStateSymbol
Indicates that a triangle must be drawn to indicate if a group node is expanded or collapsed.protected boolean
drawSelectedSymbol
Indicates that a checkbox must be drawn for each node to indicate if the node is selected or not.protected ScrollFrame
frame
Frame that contains the tree.protected long
frameNumber
protected TreeAttributes
highlightAttributes
Attributes to use when the frame is highlighted.protected boolean
highlighted
Indicates whether or not the tree is highlighted.protected int
indent
Indentation in pixels applied to each new level of the tree.protected BoundedHashMap<TreeNode,BasicTreeLayout.NodeLayout>
layoutCache
Cache of computed node layout data.protected int
lineHeight
The height of one line of text in the active font.protected int
maxWrappedLines
Maximum number of lines of wrapped description text to draw.protected boolean
mustRecomputeLayout
Indicates that the tree layout needs to be computed.protected boolean
mustRecomputeSize
Indicates that the tree size needs to be computed.protected int
nodeCount
Number of nodes in the tree, used to set a bound on the text cache.protected TreeAttributes
normalAttributes
Attributes to use when the tree is not highlighted.protected int
padding
A little extra space is added to the tree dimensions to give the tree a little bit of separation from the scrollable frame.protected PickSupport
pickSupport
Support for setting up and restoring picking state, and resolving the picked object.protected java.awt.Dimension
previousFrameSize
Frame size when the tree layout was last computed.protected java.awt.Dimension
previousSizeBounds
Frame size when the tree size was last computed.protected java.awt.Point
screenLocation
Location of the lower left corner of the tree, in GL coordinates.protected TreeNode
scrollToNode
This field is set bymakeVisible(TreePath)
, and read byscrollToNode(gov.nasa.worldwind.render.DrawContext)
during rendering.protected boolean
showDescription
Indicates that node description text must be drawn.protected java.awt.Dimension
size
Cache the rendered size of the tree and recompute when the tree changes.protected BoundedHashMap<BasicTreeLayout.TextCacheKey,java.awt.geom.Rectangle2D>
textCache
Cache of computed text bounds.protected Tree
tree
Tree that is drawn by this layout.protected java.util.List<BasicTreeLayout.NodeLayout>
treeNodes
Cache of node layouts.protected long
updateTime
Time at which the rendered tree last changed.protected boolean
wrapText
Indicates whether or not the description text will be wrapped to fit the frame.
-
Constructor Summary
Constructors Constructor Description BasicTreeLayout(Tree tree)
Create a layout for a tree.BasicTreeLayout(Tree tree, int x, int y)
Create a layout for a tree, at a screen location.BasicTreeLayout(Tree tree, Offset screenLocation)
Create a layout for a tree, at a screen location.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
computeIndentation()
Compute the indentation, in pixels, applied to each new level of the tree.protected int
computeMaxTextHeight(DrawContext dc)
Determine the maximum height of a line of text using the active font.protected void
computeSize(Tree tree, TreeNode root, DrawContext dc, java.awt.Dimension frameSize, java.awt.Dimension size, int x, int level)
Compute the size of a tree.protected void
computeTreeLayout(TreeNode root, DrawContext dc, java.awt.Dimension frameSize, java.awt.Point location, int level, java.util.List<BasicTreeLayout.NodeLayout> nodes)
Determine the tree layout.protected java.lang.String
computeWrappedText(DrawContext dc, TreeNode node, java.awt.Font font, int width)
Get the wrapped description text for a node.protected ScrollFrame
createFrame()
Create the frame that the tree will be rendered inside.protected HotSpot
createSelectControl(TreeNode node)
Create a pickable object to represent selection control in the tree.protected HotSpot
createTogglePathControl(Tree tree, TreeNode node)
Create a pickable object to represent a toggle control in the tree.protected void
determineActiveAttributes()
Determines which attributes -- normal, highlight or default -- to use each frame.protected void
drawCheckboxes(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw check boxes.protected void
drawCheckmarks(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw checkmark symbols in the selected checkboxes.protected void
drawDescriptionText(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the description text for tree nodes.protected void
drawFilledCheckboxes(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw squares filled with a gradient for partially selected checkboxes.protected void
drawIcons(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw icons for a tree nodes.protected void
drawText(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the main line of text for a list of tree nodes.protected void
drawTriangles(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw triangles to indicate that the nodes are expanded or collapsed.protected int
estimateWrappedTextLines(DrawContext dc, java.lang.String text, java.awt.Font font, int frameWidth)
protected java.awt.Rectangle
findNodeBounds(TreeNode needle, TreeNode haystack, DrawContext dc, java.awt.Dimension frameSize, java.awt.Point location, int level)
Find the bounds of a node in the tree.protected TreeAttributes
getActiveAttributes()
Get the active attributes, based on the highlight state.TreeAttributes
getAttributes()
Get the tree attributes.protected java.lang.String
getDescriptionText(TreeNode node)
Get the description text for a node.ScrollFrame
getFrame()
Get the frame that surrounds the tree.TreeAttributes
getHighlightAttributes()
Get the attributes to apply when the tree is highlighted.int
getMaxWrappedLines()
Specifies the maximum number of lines of text wrapped description text to draw.protected java.awt.geom.Rectangle2D
getMultilineTextBounds(DrawContext dc, java.lang.String text, java.awt.Font font)
Get the bounds of a multi-line text string.java.awt.Dimension
getNodeSize(DrawContext dc, java.awt.Dimension frameSize, int x, TreeNode node, TreeAttributes attributes)
Compute the size of a node.protected java.awt.Dimension
getNodeStateSymbolSize()
Get the size of the symbol that indicates that a node is expanded or collapsed.Offset
getScreenLocation()
Get the location of the upper left corner of the tree, measured in screen coordinates with the origin at the upper left corner of the screen.protected java.awt.Dimension
getSelectedSymbolSize()
Get the size of the symbol that indicates that a node is selected or not selected.java.awt.Dimension
getSize(DrawContext dc, java.awt.Dimension frameSize)
Get the size of the entire tree, including the part that is not visible in the scroll pane.protected java.lang.String
getText(TreeNode node)
Get the text for a node.protected java.awt.geom.Rectangle2D
getTextBounds(DrawContext dc, java.lang.String text, java.awt.Font font)
Get the bounds of a text string.long
getUpdateTime()
Get the time in milliseconds since the Epoch at which the Scrollable contents last changed.protected boolean
intersectsFrustum(DrawContext dc, BasicTreeLayout.NodeLayout layout, java.awt.Rectangle scrollBounds)
Determines whether a node intersects the view frustum.void
invalidate()
Force the layout to recompute the size of the tree.protected void
invalidateWrappedText()
Invalidate the computed wrapped text, forcing the text wrap to be recomputed.boolean
isDrawNodeStateSymbol()
Will the renderer draw a symbol to indicate that the node is expanded or collapsed (applies only to non-leaf nodes).boolean
isDrawSelectedSymbol()
Will the renderer draw a symbol to indicate that the node is selected? The default symbol is a checkbox.boolean
isHighlighted()
Is the tree highlighted? The tree is highlighted when the mouse is within the bounds of the containing frame.boolean
isShowDescription()
Should the node renderer include node descriptions?boolean
isWrapText()
Indicates whether or not the layout wraps the node description to multiple lines.void
makeVisible(TreePath path)
Make a node in the tree visible in the rendered tree.protected void
markUpdated()
Set theupdateTime
to the current system time, marking the Scrollable contents as updated.protected boolean
mustDisplayNode(TreeNode node, int level)
Determine if a node needs to be displayed.protected boolean
mustRecomputeSize(java.awt.Dimension frameSize)
Indicates whether or not the tree size needs to be recomputed.protected boolean
mustRecomputeTreeLayout(java.awt.Dimension frameSize)
Indicates whether or not the tree layout needs to be recomputed.protected void
pickTextAndIcon(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw pick rectangles over the icon and text areas the visible nodes.void
preRender(DrawContext dc)
void
render(DrawContext dc)
Render a tree.protected void
renderNodes(DrawContext dc, java.awt.Point drawPoint, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes, java.awt.Rectangle clipBounds)
Render a list of tree nodes.void
renderScrollable(DrawContext dc, java.awt.Point location, java.awt.Dimension frameSize, java.awt.Rectangle clipBounds)
Render the scrollable component.protected void
scrollToNode(DrawContext dc)
Scroll the frame to make a the node set inscrollToNode
node visible.void
setAttributes(TreeAttributes attributes)
Set the tree attributes.protected void
setDescendantsSelected(TreeNode node, boolean selected)
Sets the selection state of the branch beneath the specifiednode
.void
setDrawNodeStateSymbol(boolean drawNodeStateSymbol)
Set whether or not the renderer will draw a symbol to indicate that the node is expanded or collapsed (applies only to non-leaf nodes).void
setDrawSelectedSymbol(boolean drawSelectedSymbol)
Set whether or not the renderer will draw a symbol to indicate that the node is selected.void
setHighlightAttributes(TreeAttributes attributes)
Set the attributes to use when the tree is highlighted.void
setHighlighted(boolean highlighted)
Set the tree layout to highlighted or not highlighted.void
setMaxWrappedLines(int maxLines)
Indicates the maximum number of lines of text wrapped description text to draw.void
setScreenLocation(Offset screenLocation)
Set the location of the upper left corner of the tree, measured in screen coordinates with the origin at the upper left corner of the screen.void
setShowDescription(boolean showDescription)
Set the renderer to renderer node descriptions (additional text rendered under the node title).void
setWrapText(boolean wrapText)
Specifies whether or not the layout wraps the node description to multiple lines.protected void
toggleNodeSelection(TreeNode node)
Toggles the selection state of the specifiednode
.protected void
updateAttributes(DrawContext dc)
Update the active attributes for the current frame, and compute other properties that are based on the active attributes.-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
-
-
-
-
Field Detail
-
tree
protected Tree tree
Tree that is drawn by this layout.
-
frame
protected ScrollFrame frame
Frame that contains the tree.
-
normalAttributes
protected TreeAttributes normalAttributes
Attributes to use when the tree is not highlighted.
-
highlightAttributes
protected TreeAttributes highlightAttributes
Attributes to use when the frame is highlighted.
-
activeAttributes
protected TreeAttributes activeAttributes
Active attributes, either normal or highlight.
-
defaultAttributes
protected static final TreeAttributes defaultAttributes
The attributes used if attributes are not specified.
-
highlighted
protected boolean highlighted
Indicates whether or not the tree is highlighted.
-
pickSupport
protected PickSupport pickSupport
Support for setting up and restoring picking state, and resolving the picked object.
-
scrollToNode
protected TreeNode scrollToNode
This field is set bymakeVisible(TreePath)
, and read byscrollToNode(gov.nasa.worldwind.render.DrawContext)
during rendering.
-
size
protected java.awt.Dimension size
Cache the rendered size of the tree and recompute when the tree changes.
-
mustRecomputeSize
protected boolean mustRecomputeSize
Indicates that the tree size needs to be computed.
-
mustRecomputeLayout
protected boolean mustRecomputeLayout
Indicates that the tree layout needs to be computed.
-
showDescription
protected boolean showDescription
Indicates that node description text must be drawn.
-
drawNodeStateSymbol
protected boolean drawNodeStateSymbol
Indicates that a triangle must be drawn to indicate if a group node is expanded or collapsed.
-
drawSelectedSymbol
protected boolean drawSelectedSymbol
Indicates that a checkbox must be drawn for each node to indicate if the node is selected or not.
-
wrapText
protected boolean wrapText
Indicates whether or not the description text will be wrapped to fit the frame.
-
maxWrappedLines
protected int maxWrappedLines
Maximum number of lines of wrapped description text to draw. If the description exceeds this it will be cut off at this number of lines, with a trailing "...".
-
textCache
protected BoundedHashMap<BasicTreeLayout.TextCacheKey,java.awt.geom.Rectangle2D> textCache
Cache of computed text bounds.
-
layoutCache
protected BoundedHashMap<TreeNode,BasicTreeLayout.NodeLayout> layoutCache
Cache of computed node layout data.
-
treeNodes
protected java.util.List<BasicTreeLayout.NodeLayout> treeNodes
Cache of node layouts. This list is populated when the tree layout is computed.
-
padding
protected int padding
A little extra space is added to the tree dimensions to give the tree a little bit of separation from the scrollable frame. This value determines the amount of padding, in pixels.
-
frameNumber
protected long frameNumber
-
attributesFrameNumber
protected long attributesFrameNumber
-
screenLocation
protected java.awt.Point screenLocation
Location of the lower left corner of the tree, in GL coordinates.
-
updateTime
protected long updateTime
Time at which the rendered tree last changed. Used to indicate when the ScrollFrame needs to refresh the rendered representation
-
previousFrameSize
protected java.awt.Dimension previousFrameSize
Frame size when the tree layout was last computed.
-
previousSizeBounds
protected java.awt.Dimension previousSizeBounds
Frame size when the tree size was last computed.
-
lineHeight
protected int lineHeight
The height of one line of text in the active font.
-
nodeCount
protected int nodeCount
Number of nodes in the tree, used to set a bound on the text cache.
-
indent
protected int indent
Indentation in pixels applied to each new level of the tree.
-
-
Constructor Detail
-
BasicTreeLayout
public BasicTreeLayout(Tree tree)
Create a layout for a tree.- Parameters:
tree
- Tree to create layout for.
-
BasicTreeLayout
public BasicTreeLayout(Tree tree, int x, int y)
Create a layout for a tree, at a screen location.- Parameters:
tree
- Tree to create layout for.x
- X coordinate of the upper left corner of the tree frame.y
- Y coordinate of the upper left corner of the tree frame, measured from the top of the screen.
-
BasicTreeLayout
public BasicTreeLayout(Tree tree, Offset screenLocation)
Create a layout for a tree, at a screen location.- Parameters:
tree
- Tree to create layout for.screenLocation
- The location of the upper left corner of the tree frame. The offset is interpreted relative to the lower left corner of the screen.
-
-
Method Detail
-
isWrapText
public boolean isWrapText()
Indicates whether or not the layout wraps the node description to multiple lines. Note that the node title is never wrapped, only the description.- Returns:
true
if the description will be wrapped to fit the frame.
-
setWrapText
public void setWrapText(boolean wrapText)
Specifies whether or not the layout wraps the node description to multiple lines. Note that the node title is never wrapped, only the description.- Parameters:
wrapText
-true
if the description text must be wrapped to fit the frame.
-
getNodeStateSymbolSize
protected java.awt.Dimension getNodeStateSymbolSize()
Get the size of the symbol that indicates that a node is expanded or collapsed.- Returns:
- The size of the node state symbol.
-
getSelectedSymbolSize
protected java.awt.Dimension getSelectedSymbolSize()
Get the size of the symbol that indicates that a node is selected or not selected.- Returns:
- The size of the node selection symbol.
-
isShowDescription
public boolean isShowDescription()
Should the node renderer include node descriptions?- Returns:
- True if the renderer should renderer node descriptions.
-
setShowDescription
public void setShowDescription(boolean showDescription)
Set the renderer to renderer node descriptions (additional text rendered under the node title).- Parameters:
showDescription
- True if the description should be rendered. False if only the icon and title should be rendered.
-
isDrawSelectedSymbol
public boolean isDrawSelectedSymbol()
Will the renderer draw a symbol to indicate that the node is selected? The default symbol is a checkbox.- Returns:
- True if the node selected symbol (a checkbox by default) will be drawn.
-
setDrawSelectedSymbol
public void setDrawSelectedSymbol(boolean drawSelectedSymbol)
Set whether or not the renderer will draw a symbol to indicate that the node is selected. The default symbol is a checkbox.- Parameters:
drawSelectedSymbol
- True if the node selected symbol (a checkbox by default) will be drawn.
-
isDrawNodeStateSymbol
public boolean isDrawNodeStateSymbol()
Will the renderer draw a symbol to indicate that the node is expanded or collapsed (applies only to non-leaf nodes). The default symbol is a triangle pointing to the right, for collapsed nodes, or down for expanded nodes.- Returns:
- True if the node state symbol (default is a triangle pointing either to the right or down) will be drawn.
-
getMaxWrappedLines
public int getMaxWrappedLines()
Specifies the maximum number of lines of text wrapped description text to draw. If the description exceeds this number of lines it will be cut off with a trailing "...".- Returns:
- Maximum number of lines of description text that will be drawn.
-
setMaxWrappedLines
public void setMaxWrappedLines(int maxLines)
Indicates the maximum number of lines of text wrapped description text to draw. If the description exceeds this number of lines it will be cut off with a trailing "...".- Parameters:
maxLines
- Maximum number of lines of description text that will be drawn.
-
setDrawNodeStateSymbol
public void setDrawNodeStateSymbol(boolean drawNodeStateSymbol)
Set whether or not the renderer will draw a symbol to indicate that the node is expanded or collapsed (applies only to non-leaf nodes). The default symbol is a triangle pointing to the right, for collapsed nodes, or down for expanded nodes.- Parameters:
drawNodeStateSymbol
- True if the node state symbol (default is a triangle pointing either to the right or down) will be drawn.
-
getUpdateTime
public long getUpdateTime()
Get the time in milliseconds since the Epoch at which the Scrollable contents last changed.ScrollFrame
uses this timestamp to determine if the contents have updated since they were last rendered. Only events that might cause a change in the rendered content should change the update time.- Specified by:
getUpdateTime
in interfaceScrollable
- Returns:
- Time at which the contents were last updated.
-
createFrame
protected ScrollFrame createFrame()
Create the frame that the tree will be rendered inside.- Returns:
- A new frame.
-
getSize
public java.awt.Dimension getSize(DrawContext dc, java.awt.Dimension frameSize)
Get the size of the entire tree, including the part that is not visible in the scroll pane.- Specified by:
getSize
in interfaceScrollable
- Parameters:
dc
- Draw context.frameSize
- Size of the frame the tree will be rendered into. May benull
.- Returns:
- Size of the rendered tree.
-
computeSize
protected void computeSize(Tree tree, TreeNode root, DrawContext dc, java.awt.Dimension frameSize, java.awt.Dimension size, int x, int level)
Compute the size of a tree. This method invokes itself recursively to calculate the size of the tree, taking into account which nodes are expanded and which are not. This computed size will be stored in thesize
parameter.- Parameters:
tree
- Tree that contains the root node.root
- Root node of the subtree to find the size of. This does not need to be the root node of the tree.dc
- Draw context.frameSize
- Size of the frame into which the tree will render.size
- Size object to modify. This method will change the width and height fields ofsize
to hold the new size of the tree.x
- Horizontal coordinate of the start of this node. This parameter must be zero. This method calls itself recursively and changes thex
parameter to reflect the indentation level of different levels of the tree.level
- Level of this node. Tree root node is level 1, children of the root are level 2, etc.
-
invalidate
public void invalidate()
Force the layout to recompute the size of the tree.
-
markUpdated
protected void markUpdated()
Set theupdateTime
to the current system time, marking the Scrollable contents as updated.
-
mustDisplayNode
protected boolean mustDisplayNode(TreeNode node, int level)
Determine if a node needs to be displayed. This method examines only one node at a time. It does not take into account that the node's parent may be in the collapsed state, in which the children are not rendered.- Parameters:
node
- Node to test.level
- Level of the node in the tree. The root node is level 1, its children are level 2, etc.- Returns:
- True if the node must be displayed.
-
preRender
public void preRender(DrawContext dc)
- Specified by:
preRender
in interfacePreRenderable
-
render
public void render(DrawContext dc)
Render a tree.- Specified by:
render
in interfaceRenderable
- Specified by:
render
in interfaceTreeLayout
- Parameters:
dc
- Draw context to draw in.- See Also:
DrawContext
-
scrollToNode
protected void scrollToNode(DrawContext dc)
Scroll the frame to make a the node set inscrollToNode
node visible. Does nothing ifscrollToNode
is null.- Parameters:
dc
- Draw context.
-
renderScrollable
public void renderScrollable(DrawContext dc, java.awt.Point location, java.awt.Dimension frameSize, java.awt.Rectangle clipBounds)
Render the scrollable component. The component should render itself with the lower left corner of the content located atlocation
.in the rectangle specified bybounds
. Note that some of the content may be clipped by the scroll frame.- Specified by:
renderScrollable
in interfaceScrollable
- Parameters:
dc
- Draw context.location
- Point at which to draw the Scrollable contents. This point indicates the location of the lower left corner of the content, in GL screen coordinates (origin at lower left corner of the screen).frameSize
- Size of the frame that will hold the content.clipBounds
- Bounds of the clip rectangle. Any pixels outside of this box will be discarded, and do not need to be drawn. The rectangle is specified in GL screen coordinates.
-
mustRecomputeTreeLayout
protected boolean mustRecomputeTreeLayout(java.awt.Dimension frameSize)
Indicates whether or not the tree layout needs to be recomputed.- Parameters:
frameSize
- Size of the frame that holds the tree.- Returns:
true
if the layout needs to be recomputed, otherwisefalse
.
-
mustRecomputeSize
protected boolean mustRecomputeSize(java.awt.Dimension frameSize)
Indicates whether or not the tree size needs to be recomputed.- Parameters:
frameSize
- Size of the frame that holds the tree. Size may be null if the frame size is not known.- Returns:
true
if the size needs to be recomputed, otherwisefalse
.
-
updateAttributes
protected void updateAttributes(DrawContext dc)
Update the active attributes for the current frame, and compute other properties that are based on the active attributes. This method only computes attributes once for each frame. Subsequent calls in the same frame will not recompute the attributes.- Parameters:
dc
- Current draw context.
-
computeIndentation
protected int computeIndentation()
Compute the indentation, in pixels, applied to each new level of the tree.- Returns:
- indention (in pixels) to apply to each new level in the tree.
-
computeMaxTextHeight
protected int computeMaxTextHeight(DrawContext dc)
Determine the maximum height of a line of text using the active font.- Parameters:
dc
- Current draw context.- Returns:
- The maximum height of a line of text.
-
renderNodes
protected void renderNodes(DrawContext dc, java.awt.Point drawPoint, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes, java.awt.Rectangle clipBounds)
Render a list of tree nodes.- Parameters:
dc
- Current draw context.drawPoint
- Point in GL coordinates (origin bottom left corner of the screen) that locates the bottom left corner of the tree.nodes
- Nodes to draw.clipBounds
- Pixels outside of this rectangle will be discarded. Any nodes that do not intersect this rectangle will not be drawn.
-
intersectsFrustum
protected boolean intersectsFrustum(DrawContext dc, BasicTreeLayout.NodeLayout layout, java.awt.Rectangle scrollBounds)
Determines whether a node intersects the view frustum.- Parameters:
dc
- the current draw context.layout
- node to test intersection of.scrollBounds
- bounds of the area currently visible in the scroll frame.- Returns:
true
If the frame intersects the frustum, otherwisefalse
.
-
pickTextAndIcon
protected void pickTextAndIcon(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw pick rectangles over the icon and text areas the visible nodes.- Parameters:
dc
- Current draw context.nodes
- Visible nodes.
-
drawText
protected void drawText(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the main line of text for a list of tree nodes.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawDescriptionText
protected void drawDescriptionText(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the description text for tree nodes. The description text is drawn under the main line of text.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawIcons
protected void drawIcons(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw icons for a tree nodes.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawCheckboxes
protected void drawCheckboxes(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw check boxes. Each box includes a check mark is the node is selected, or is filled with a gradient if the node is partially selected.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawFilledCheckboxes
protected void drawFilledCheckboxes(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw squares filled with a gradient for partially selected checkboxes.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawCheckmarks
protected void drawCheckmarks(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw checkmark symbols in the selected checkboxes.- Parameters:
dc
- Current draw context.nodes
- List of visible nodes.
-
drawTriangles
protected void drawTriangles(DrawContext dc, java.lang.Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw triangles to indicate that the nodes are expanded or collapsed.- Parameters:
dc
- Current draw context.nodes
- Visible nodes.
-
computeTreeLayout
protected void computeTreeLayout(TreeNode root, DrawContext dc, java.awt.Dimension frameSize, java.awt.Point location, int level, java.util.List<BasicTreeLayout.NodeLayout> nodes)
Determine the tree layout. This method determines which nodes are visible, and where they will be drawn.- Parameters:
root
- Root node of the subtree to render.dc
- Draw context.frameSize
- Size of the frame into which the tree will render.location
- Location at which to draw the node. The location specifies the upper left corner of the subtree.level
- The level of this node in the tree. The root node is at level 1, its child nodes are at level 2, etc.nodes
- List to collect nodes that are currently visible. This method adds nodes to this list.
-
findNodeBounds
protected java.awt.Rectangle findNodeBounds(TreeNode needle, TreeNode haystack, DrawContext dc, java.awt.Dimension frameSize, java.awt.Point location, int level)
Find the bounds of a node in the tree.- Parameters:
needle
- The node to find.haystack
- Root node of the subtree to search.dc
- Draw context.frameSize
- Size of the frame into which the tree is rendered.location
- Point in OpenGL screen coordinates (origin lower left corner) that defines the upper left corner of the subtree.level
- Level of this subtree in the tree. The root node is level 1, its children are level 2, etc.- Returns:
- Bounds of the node
needle
.
-
makeVisible
public void makeVisible(TreePath path)
Make a node in the tree visible in the rendered tree. For example, scroll the tree viewport so that a path is visible.- Specified by:
makeVisible
in interfaceTreeLayout
- Parameters:
path
- Path to make visible.
-
getScreenLocation
public Offset getScreenLocation()
Get the location of the upper left corner of the tree, measured in screen coordinates with the origin at the upper left corner of the screen.- Returns:
- Screen location, measured in pixels from the upper left corner of the screen.
-
setScreenLocation
public void setScreenLocation(Offset screenLocation)
Set the location of the upper left corner of the tree, measured in screen coordinates with the origin at the upper left corner of the screen.- Parameters:
screenLocation
- New screen location.
-
getAttributes
public TreeAttributes getAttributes()
Get the tree attributes.- Specified by:
getAttributes
in interfaceTreeLayout
- Returns:
- Tree attributes.
- See Also:
TreeLayout.setAttributes(TreeAttributes)
-
setAttributes
public void setAttributes(TreeAttributes attributes)
Set the tree attributes.- Specified by:
setAttributes
in interfaceTreeLayout
- Parameters:
attributes
- New attributes.- See Also:
TreeLayout.getAttributes()
-
getHighlightAttributes
public TreeAttributes getHighlightAttributes()
Get the attributes to apply when the tree is highlighted.- Returns:
- Attributes to use when tree is highlighted.
-
setHighlightAttributes
public void setHighlightAttributes(TreeAttributes attributes)
Set the attributes to use when the tree is highlighted.- Parameters:
attributes
- New highlight attributes.
-
getActiveAttributes
protected TreeAttributes getActiveAttributes()
Get the active attributes, based on the highlight state.- Returns:
- Highlight attributes if the tree is highlighted. Otherwise, the normal attributes.
-
determineActiveAttributes
protected void determineActiveAttributes()
Determines which attributes -- normal, highlight or default -- to use each frame.
-
isHighlighted
public boolean isHighlighted()
Is the tree highlighted? The tree is highlighted when the mouse is within the bounds of the containing frame.- Returns:
- True if the tree is highlighted.
-
setHighlighted
public void setHighlighted(boolean highlighted)
Set the tree layout to highlighted or not highlighted.- Specified by:
setHighlighted
in interfaceScrollable
- Parameters:
highlighted
- True if the tree should be highlighted.
-
getFrame
public ScrollFrame getFrame()
Get the frame that surrounds the tree.- Returns:
- The frame that the tree is drawn on.
-
getNodeSize
public java.awt.Dimension getNodeSize(DrawContext dc, java.awt.Dimension frameSize, int x, TreeNode node, TreeAttributes attributes)
Compute the size of a node.- Parameters:
dc
- Current draw context.frameSize
- Size of the frame into which the tree is rendered.x
- Offset in pixels from the left side of the screen to the left most part of the node.node
- Node for which to compute bounds.attributes
- Attributes to use for bounds calculation.- Returns:
- The dimensions of the node.
-
estimateWrappedTextLines
protected int estimateWrappedTextLines(DrawContext dc, java.lang.String text, java.awt.Font font, int frameWidth)
-
computeWrappedText
protected java.lang.String computeWrappedText(DrawContext dc, TreeNode node, java.awt.Font font, int width)
Get the wrapped description text for a node. The wrapped text will be cached in thelayoutCache
.- Parameters:
dc
- Current draw context.node
- Node for which to get wrapped text.font
- Font to use for the description.width
- Width to which to wrap text.- Returns:
- The wrapped text as a String. The string will contain newline characters to delimit the lines of wrapped text.
-
invalidateWrappedText
protected void invalidateWrappedText()
Invalidate the computed wrapped text, forcing the text wrap to be recomputed.
-
createTogglePathControl
protected HotSpot createTogglePathControl(Tree tree, TreeNode node)
Create a pickable object to represent a toggle control in the tree. The toggle control will expand or collapse a node in response to user input.- Parameters:
tree
- Tree that contains the node.node
- The node to expand or collapse.- Returns:
- A
TreeHotSpot
that will be added as a pickable object to the screen area occupied by the toggle control.
-
createSelectControl
protected HotSpot createSelectControl(TreeNode node)
Create a pickable object to represent selection control in the tree. The selection control will select or deselect a node in response to user input. The returnedHotSpot
calls
upon a left-click select event.toggleNodeSelection(TreeNode)
- Parameters:
node
- The node to expand or collapse.- Returns:
- A
TreeHotSpot
that will be added as a pickable object to the screen area occupied by the toggle control.
-
getTextBounds
protected java.awt.geom.Rectangle2D getTextBounds(DrawContext dc, java.lang.String text, java.awt.Font font)
Get the bounds of a text string. This method consults the text bound cache. If the bounds of the input string are not already cached, they will be computed and added to the cache.- Parameters:
dc
- Draw context.text
- Text to get bounds of.font
- Font applied to the text.- Returns:
- A rectangle that describes the node bounds. See com.jogamp.opengl.util.awt.TextRenderer.getBounds for information on how this rectangle should be interpreted.
-
getMultilineTextBounds
protected java.awt.geom.Rectangle2D getMultilineTextBounds(DrawContext dc, java.lang.String text, java.awt.Font font)
Get the bounds of a multi-line text string. Each newline character in the input string (\n) indicates the start of a new line.- Parameters:
dc
- Current draw context.text
- Text to find bounds of.font
- Font applied to the text.- Returns:
- A rectangle that describes the node bounds. See com.jogamp.opengl.util.awt.TextRenderer.getBounds for information on how this rectangle should be interpreted.
-
toggleNodeSelection
protected void toggleNodeSelection(TreeNode node)
Toggles the selection state of the specifiednode
. In order to provide an intuitive tree selection model to the application, this changes the selection state of thenode
's ancestors and descendants as follows:- The branch beneath the node it also set to the node's new selection state. Toggling an interior node's selection state causes that entire branch to toggle.
- The node's ancestors are set to match the node's
new selection state. If the new state is
false
, this stops at the first ancestor with another branch that has a selected node. When an interior or leaf node is toggled, the path to that node is also toggled, except when doing so would clear a selected path to another interior or leaf node.
- Parameters:
node
- theTreeNode
who's selection state should be toggled.
-
setDescendantsSelected
protected void setDescendantsSelected(TreeNode node, boolean selected)
Sets the selection state of the branch beneath the specifiednode
.- Parameters:
node
- theTreeNode
who descendants selection should be set.selected
-true
to mark the descendants and selected, otherwisefalse
.
-
getText
protected java.lang.String getText(TreeNode node)
Get the text for a node.- Parameters:
node
- Node to get text for.- Returns:
- Text for node.
-
getDescriptionText
protected java.lang.String getDescriptionText(TreeNode node)
Get the description text for a node.- Parameters:
node
- Node to get text for.- Returns:
- Description text for
node
. May return null if there is no description.
-
-