public class BasicTreeLayout extends WWObjectImpl implements TreeLayout, Scrollable, PreRenderable
Tree
similar to a file browser tree.Modifier and Type | Class and 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.
|
Modifier and Type | Field and 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 Dimension |
previousFrameSize
Frame size when the tree layout was last computed.
|
protected Dimension |
previousSizeBounds
Frame size when the tree size was last computed.
|
protected Point |
screenLocation
Location of the lower left corner of the tree, in GL coordinates.
|
protected TreeNode |
scrollToNode
This field is set by
makeVisible(TreePath) , and read by scrollToNode(gov.nasa.worldwind.render.DrawContext)
during rendering. |
protected boolean |
showDescription
Indicates that node description text must be drawn.
|
protected Dimension |
size
Cache the rendered size of the tree and recompute when the tree changes.
|
protected BoundedHashMap<BasicTreeLayout.TextCacheKey,Rectangle2D> |
textCache
Cache of computed text bounds.
|
protected Tree |
tree
Tree that is drawn by this layout.
|
protected 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 and 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.
|
Modifier and Type | Method and 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,
Dimension frameSize,
Dimension size,
int x,
int level)
Compute the size of a tree.
|
protected void |
computeTreeLayout(TreeNode root,
DrawContext dc,
Dimension frameSize,
Point location,
int level,
List<BasicTreeLayout.NodeLayout> nodes)
Determine the tree layout.
|
protected String |
computeWrappedText(DrawContext dc,
TreeNode node,
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,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw check boxes.
|
protected void |
drawCheckmarks(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw checkmark symbols in the selected checkboxes.
|
protected void |
drawDescriptionText(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the description text for tree nodes.
|
protected void |
drawFilledCheckboxes(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw squares filled with a gradient for partially selected checkboxes.
|
protected void |
drawIcons(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw icons for a tree nodes.
|
protected void |
drawText(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw the main line of text for a list of tree nodes.
|
protected void |
drawTriangles(DrawContext dc,
Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw triangles to indicate that the nodes are expanded or collapsed.
|
protected int |
estimateWrappedTextLines(DrawContext dc,
String text,
Font font,
int frameWidth) |
protected Rectangle |
findNodeBounds(TreeNode needle,
TreeNode haystack,
DrawContext dc,
Dimension frameSize,
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 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 Rectangle2D |
getMultilineTextBounds(DrawContext dc,
String text,
Font font)
Get the bounds of a multi-line text string.
|
Dimension |
getNodeSize(DrawContext dc,
Dimension frameSize,
int x,
TreeNode node,
TreeAttributes attributes)
Compute the size of a node.
|
protected 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 Dimension |
getSelectedSymbolSize()
Get the size of the symbol that indicates that a node is selected or not selected.
|
Dimension |
getSize(DrawContext dc,
Dimension frameSize)
Get the size of the entire tree, including the part that is not visible in the scroll pane.
|
protected String |
getText(TreeNode node)
Get the text for a node.
|
protected Rectangle2D |
getTextBounds(DrawContext dc,
String text,
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,
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 the
updateTime 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(Dimension frameSize)
Indicates whether or not the tree size needs to be recomputed.
|
protected boolean |
mustRecomputeTreeLayout(Dimension frameSize)
Indicates whether or not the tree layout needs to be recomputed.
|
protected void |
pickTextAndIcon(DrawContext dc,
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,
Point drawPoint,
Iterable<BasicTreeLayout.NodeLayout> nodes,
Rectangle clipBounds)
Render a list of tree nodes.
|
void |
renderScrollable(DrawContext dc,
Point location,
Dimension frameSize,
Rectangle clipBounds)
Render the scrollable component.
|
protected void |
scrollToNode(DrawContext dc)
Scroll the frame to make a the node set in
scrollToNode 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 specified
node . |
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 specified
node . |
protected void |
updateAttributes(DrawContext dc)
Update the active attributes for the current frame, and compute other properties that are based on the active
attributes.
|
onMessage, propertyChange
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
propertyChange
onMessage
protected TreeAttributes activeAttributes
protected long attributesFrameNumber
protected static final TreeAttributes defaultAttributes
protected boolean drawNodeStateSymbol
protected boolean drawSelectedSymbol
protected ScrollFrame frame
protected long frameNumber
protected TreeAttributes highlightAttributes
protected boolean highlighted
protected int indent
protected BoundedHashMap<TreeNode,BasicTreeLayout.NodeLayout> layoutCache
protected int lineHeight
protected int maxWrappedLines
protected boolean mustRecomputeLayout
protected boolean mustRecomputeSize
protected int nodeCount
protected TreeAttributes normalAttributes
protected int padding
protected PickSupport pickSupport
protected Dimension previousFrameSize
protected Dimension previousSizeBounds
protected Point screenLocation
protected TreeNode scrollToNode
makeVisible(TreePath)
, and read by scrollToNode(gov.nasa.worldwind.render.DrawContext)
during rendering.protected boolean showDescription
protected Dimension size
protected BoundedHashMap<BasicTreeLayout.TextCacheKey,Rectangle2D> textCache
protected Tree tree
protected List<BasicTreeLayout.NodeLayout> treeNodes
protected long updateTime
protected boolean wrapText
public BasicTreeLayout(Tree tree)
tree
- Tree to create layout for.public BasicTreeLayout(Tree tree, int x, int y)
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.public BasicTreeLayout(Tree tree, Offset screenLocation)
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.protected int computeIndentation()
protected int computeMaxTextHeight(DrawContext dc)
dc
- Current draw context.protected void computeSize(Tree tree, TreeNode root, DrawContext dc, Dimension frameSize, Dimension size, int x, int level)
size
parameter.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 of size
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 the x
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.protected void computeTreeLayout(TreeNode root, DrawContext dc, Dimension frameSize, Point location, int level, List<BasicTreeLayout.NodeLayout> nodes)
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.protected String computeWrappedText(DrawContext dc, TreeNode node, Font font, int width)
layoutCache
.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.protected ScrollFrame createFrame()
protected HotSpot createSelectControl(TreeNode node)
HotSpot
calls toggleNodeSelection(TreeNode)
upon a left-click select event.node
- The node to expand or collapse.TreeHotSpot
that will be added as a pickable object to the screen area occupied by the toggle
control.protected HotSpot createTogglePathControl(Tree tree, TreeNode node)
tree
- Tree that contains the node.node
- The node to expand or collapse.TreeHotSpot
that will be added as a pickable object to the screen area occupied by the toggle
control.protected void determineActiveAttributes()
protected void drawCheckboxes(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawCheckmarks(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawDescriptionText(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawFilledCheckboxes(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawIcons(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawText(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- List of visible nodes.protected void drawTriangles(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- Visible nodes.protected int estimateWrappedTextLines(DrawContext dc, String text, Font font, int frameWidth)
protected Rectangle findNodeBounds(TreeNode needle, TreeNode haystack, DrawContext dc, Dimension frameSize, Point location, int level)
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.needle
.protected TreeAttributes getActiveAttributes()
public TreeAttributes getAttributes()
getAttributes
in interface TreeLayout
TreeLayout.setAttributes(TreeAttributes)
protected String getDescriptionText(TreeNode node)
node
- Node to get text for.node
. May return null if there is no description.public ScrollFrame getFrame()
public TreeAttributes getHighlightAttributes()
public int getMaxWrappedLines()
protected Rectangle2D getMultilineTextBounds(DrawContext dc, String text, Font font)
dc
- Current draw context.text
- Text to find bounds of.font
- Font applied to the text.public Dimension getNodeSize(DrawContext dc, Dimension frameSize, int x, TreeNode node, TreeAttributes attributes)
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.protected Dimension getNodeStateSymbolSize()
public Offset getScreenLocation()
protected Dimension getSelectedSymbolSize()
public Dimension getSize(DrawContext dc, Dimension frameSize)
getSize
in interface Scrollable
dc
- Draw context.frameSize
- Size of the frame the tree will be rendered into. May be null
.protected String getText(TreeNode node)
node
- Node to get text for.protected Rectangle2D getTextBounds(DrawContext dc, String text, Font font)
dc
- Draw context.text
- Text to get bounds of.font
- Font applied to the text.public long getUpdateTime()
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.getUpdateTime
in interface Scrollable
protected boolean intersectsFrustum(DrawContext dc, BasicTreeLayout.NodeLayout layout, Rectangle scrollBounds)
dc
- the current draw context.layout
- node to test intersection of.scrollBounds
- bounds of the area currently visible in the scroll frame.true
If the frame intersects the frustum, otherwise false
.public void invalidate()
protected void invalidateWrappedText()
public boolean isDrawNodeStateSymbol()
public boolean isDrawSelectedSymbol()
public boolean isHighlighted()
public boolean isShowDescription()
public boolean isWrapText()
true
if the description will be wrapped to fit the frame.public void makeVisible(TreePath path)
makeVisible
in interface TreeLayout
path
- Path to make visible.protected void markUpdated()
updateTime
to the current system time, marking the Scrollable contents as updated.protected boolean mustDisplayNode(TreeNode node, int level)
node
- Node to test.level
- Level of the node in the tree. The root node is level 1, its children are level 2, etc.protected boolean mustRecomputeSize(Dimension frameSize)
frameSize
- Size of the frame that holds the tree. Size may be null if the frame size is not known.true
if the size needs to be recomputed, otherwise false
.protected boolean mustRecomputeTreeLayout(Dimension frameSize)
frameSize
- Size of the frame that holds the tree.true
if the layout needs to be recomputed, otherwise false
.protected void pickTextAndIcon(DrawContext dc, Iterable<BasicTreeLayout.NodeLayout> nodes)
dc
- Current draw context.nodes
- Visible nodes.public void preRender(DrawContext dc)
preRender
in interface PreRenderable
public void render(DrawContext dc)
render
in interface Renderable
render
in interface TreeLayout
dc
- Draw context to draw in.DrawContext
protected void renderNodes(DrawContext dc, Point drawPoint, Iterable<BasicTreeLayout.NodeLayout> nodes, Rectangle clipBounds)
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.public void renderScrollable(DrawContext dc, Point location, Dimension frameSize, Rectangle clipBounds)
location
.in the rectangle specified by bounds
. Note that some of the content may be
clipped by the scroll frame.renderScrollable
in interface Scrollable
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.protected void scrollToNode(DrawContext dc)
scrollToNode
node visible. Does nothing if scrollToNode
is null.dc
- Draw context.public void setAttributes(TreeAttributes attributes)
setAttributes
in interface TreeLayout
attributes
- New attributes.TreeLayout.getAttributes()
protected void setDescendantsSelected(TreeNode node, boolean selected)
node
.node
- the TreeNode
who descendants selection should be set.selected
- true
to mark the descendants and selected, otherwise false
.public void setDrawNodeStateSymbol(boolean drawNodeStateSymbol)
drawNodeStateSymbol
- True if the node state symbol (default is a triangle pointing either to the right or
down) will be drawn.public void setDrawSelectedSymbol(boolean drawSelectedSymbol)
drawSelectedSymbol
- True if the node selected symbol (a checkbox by default) will be drawn.public void setHighlightAttributes(TreeAttributes attributes)
attributes
- New highlight attributes.public void setHighlighted(boolean highlighted)
setHighlighted
in interface Scrollable
highlighted
- True if the tree should be highlighted.public void setMaxWrappedLines(int maxLines)
maxLines
- Maximum number of lines of description text that will be drawn.public void setScreenLocation(Offset screenLocation)
screenLocation
- New screen location.public void setShowDescription(boolean showDescription)
showDescription
- True if the description should be rendered. False if only the icon and title should be
rendered.public void setWrapText(boolean wrapText)
wrapText
- true
if the description text must be wrapped to fit the frame.protected void toggleNodeSelection(TreeNode node)
node
. In order to provide an intuitive tree selection
model to the application, this changes the selection state of the node
's ancestors and descendants
as follows:
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.node
- the TreeNode
who's selection state should be toggled.protected void updateAttributes(DrawContext dc)
dc
- Current draw context.