NASA World Wind

gov.nasa.worldwind.util.tree
Class BasicTreeLayout

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.util.tree.BasicTreeLayout
All Implemented Interfaces:
AVList, MessageListener, PreRenderable, Renderable, Scrollable, TreeLayout, WWObject, PropertyChangeListener, EventListener

public class BasicTreeLayout
extends WWObjectImpl
implements TreeLayout, Scrollable, PreRenderable

Layout that draws a Tree similar to a file browser tree.


Nested Class Summary
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
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 Summary
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
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.
 
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, finalize, 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 java.beans.PropertyChangeListener
propertyChange
 
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
 

Field Detail

activeAttributes

protected TreeAttributes activeAttributes
Active attributes, either normal or highlight.


attributesFrameNumber

protected long attributesFrameNumber

defaultAttributes

protected static final TreeAttributes defaultAttributes
The attributes used if attributes are not specified.


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.


frame

protected ScrollFrame frame
Frame that contains the tree.


frameNumber

protected long frameNumber

highlightAttributes

protected TreeAttributes highlightAttributes
Attributes to use when the frame is highlighted.


highlighted

protected boolean highlighted
Indicates whether or not the tree is highlighted.


indent

protected int indent
Indentation in pixels applied to each new level of the tree.


layoutCache

protected BoundedHashMap<TreeNode,BasicTreeLayout.NodeLayout> layoutCache
Cache of computed node layout data.


lineHeight

protected int lineHeight
The height of one line of text in the active font.


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 "...".


mustRecomputeLayout

protected boolean mustRecomputeLayout
Indicates that the tree layout needs to be computed.


mustRecomputeSize

protected boolean mustRecomputeSize
Indicates that the tree size needs to be computed.


nodeCount

protected int nodeCount
Number of nodes in the tree, used to set a bound on the text cache.


normalAttributes

protected TreeAttributes normalAttributes
Attributes to use when the tree is not highlighted.


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.


pickSupport

protected PickSupport pickSupport
Support for setting up and restoring picking state, and resolving the picked object.


previousFrameSize

protected Dimension previousFrameSize
Frame size when the tree layout was last computed.


previousSizeBounds

protected Dimension previousSizeBounds
Frame size when the tree size was last computed.


screenLocation

protected Point screenLocation
Location of the lower left corner of the tree, in GL coordinates.


scrollToNode

protected TreeNode scrollToNode
This field is set by makeVisible(TreePath), and read by scrollToNode(gov.nasa.worldwind.render.DrawContext) during rendering.


showDescription

protected boolean showDescription
Indicates that node description text must be drawn.


size

protected Dimension size
Cache the rendered size of the tree and recompute when the tree changes.


textCache

protected BoundedHashMap<BasicTreeLayout.TextCacheKey,Rectangle2D> textCache
Cache of computed text bounds.


tree

protected Tree tree
Tree that is drawn by this layout.


treeNodes

protected List<BasicTreeLayout.NodeLayout> treeNodes
Cache of node layouts. This list is populated when the tree layout is computed.


updateTime

protected long updateTime
Time at which the rendered tree last changed. Used to indicate when the ScrollFrame needs to refresh the rendered representation


wrapText

protected boolean wrapText
Indicates whether or not the description text will be wrapped to fit the frame.

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

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.

computeSize

protected void computeSize(Tree tree,
                           TreeNode root,
                           DrawContext dc,
                           Dimension frameSize,
                           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 the size 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 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.

computeTreeLayout

protected void computeTreeLayout(TreeNode root,
                                 DrawContext dc,
                                 Dimension frameSize,
                                 Point location,
                                 int level,
                                 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.

computeWrappedText

protected String computeWrappedText(DrawContext dc,
                                    TreeNode node,
                                    Font font,
                                    int width)
Get the wrapped description text for a node. The wrapped text will be cached in the layoutCache.

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.

createFrame

protected ScrollFrame createFrame()
Create the frame that the tree will be rendered inside.

Returns:
A new frame.

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 returned HotSpot calls toggleNodeSelection(TreeNode) upon a left-click select event.

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.

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.

determineActiveAttributes

protected void determineActiveAttributes()
Determines which attributes -- normal, highlight or default -- to use each frame.


drawCheckboxes

protected void drawCheckboxes(DrawContext dc,
                              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.

drawCheckmarks

protected void drawCheckmarks(DrawContext dc,
                              Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw checkmark symbols in the selected checkboxes.

Parameters:
dc - Current draw context.
nodes - List of visible nodes.

drawDescriptionText

protected void drawDescriptionText(DrawContext dc,
                                   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.

drawFilledCheckboxes

protected void drawFilledCheckboxes(DrawContext dc,
                                    Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw squares filled with a gradient for partially selected checkboxes.

Parameters:
dc - Current draw context.
nodes - List of visible nodes.

drawIcons

protected void drawIcons(DrawContext dc,
                         Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw icons for a tree nodes.

Parameters:
dc - Current draw context.
nodes - List of visible nodes.

drawText

protected void drawText(DrawContext dc,
                        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.

drawTriangles

protected void drawTriangles(DrawContext dc,
                             Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw triangles to indicate that the nodes are expanded or collapsed.

Parameters:
dc - Current draw context.
nodes - Visible nodes.

estimateWrappedTextLines

protected int estimateWrappedTextLines(DrawContext dc,
                                       String text,
                                       Font font,
                                       int frameWidth)

findNodeBounds

protected Rectangle findNodeBounds(TreeNode needle,
                                   TreeNode haystack,
                                   DrawContext dc,
                                   Dimension frameSize,
                                   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.

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.

getAttributes

public TreeAttributes getAttributes()
Get the tree attributes.

Specified by:
getAttributes in interface TreeLayout
Returns:
Tree attributes.
See Also:
TreeLayout.setAttributes(TreeAttributes)

getDescriptionText

protected 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.

getFrame

public ScrollFrame getFrame()
Get the frame that surrounds the tree.

Returns:
The frame that the tree is drawn on.

getHighlightAttributes

public TreeAttributes getHighlightAttributes()
Get the attributes to apply when the tree is highlighted.

Returns:
Attributes to use when tree is highlighted.

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.

getMultilineTextBounds

protected Rectangle2D getMultilineTextBounds(DrawContext dc,
                                             String text,
                                             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.

getNodeSize

public Dimension getNodeSize(DrawContext dc,
                             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.

getNodeStateSymbolSize

protected 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.

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.

getSelectedSymbolSize

protected 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.

getSize

public Dimension getSize(DrawContext dc,
                         Dimension frameSize)
Get the size of the entire tree, including the part that is not visible in the scroll pane.

Specified by:
getSize in interface Scrollable
Parameters:
dc - Draw context.
frameSize - Size of the frame the tree will be rendered into. May be null.
Returns:
Size of the rendered tree.

getText

protected String getText(TreeNode node)
Get the text for a node.

Parameters:
node - Node to get text for.
Returns:
Text for node.

getTextBounds

protected Rectangle2D getTextBounds(DrawContext dc,
                                    String text,
                                    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.

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 interface Scrollable
Returns:
Time at which the contents were last updated.

intersectsFrustum

protected boolean intersectsFrustum(DrawContext dc,
                                    BasicTreeLayout.NodeLayout layout,
                                    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, otherwise false.

invalidate

public void invalidate()
Force the layout to recompute the size of the tree.


invalidateWrappedText

protected void invalidateWrappedText()
Invalidate the computed wrapped text, forcing the text wrap to be recomputed.


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.

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.

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.

isShowDescription

public boolean isShowDescription()
Should the node renderer include node descriptions?

Returns:
True if the renderer should renderer node descriptions.

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.

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 interface TreeLayout
Parameters:
path - Path to make visible.

markUpdated

protected void markUpdated()
Set the updateTime 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.

mustRecomputeSize

protected boolean mustRecomputeSize(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, otherwise false.

mustRecomputeTreeLayout

protected boolean mustRecomputeTreeLayout(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, otherwise false.

pickTextAndIcon

protected void pickTextAndIcon(DrawContext dc,
                               Iterable<BasicTreeLayout.NodeLayout> nodes)
Draw pick rectangles over the icon and text areas the visible nodes.

Parameters:
dc - Current draw context.
nodes - Visible nodes.

preRender

public void preRender(DrawContext dc)

Specified by:
preRender in interface PreRenderable

render

public void render(DrawContext dc)
Render a tree.

Specified by:
render in interface Renderable
Specified by:
render in interface TreeLayout
Parameters:
dc - Draw context to draw in.
See Also:
DrawContext

renderNodes

protected void renderNodes(DrawContext dc,
                           Point drawPoint,
                           Iterable<BasicTreeLayout.NodeLayout> nodes,
                           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.

renderScrollable

public void renderScrollable(DrawContext dc,
                             Point location,
                             Dimension frameSize,
                             Rectangle clipBounds)
Render the scrollable component. The component should render itself with the lower left corner of the content located at location.in the rectangle specified by bounds. Note that some of the content may be clipped by the scroll frame.

Specified by:
renderScrollable in interface Scrollable
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.

scrollToNode

protected void scrollToNode(DrawContext dc)
Scroll the frame to make a the node set in scrollToNode node visible. Does nothing if scrollToNode is null.

Parameters:
dc - Draw context.

setAttributes

public void setAttributes(TreeAttributes attributes)
Set the tree attributes.

Specified by:
setAttributes in interface TreeLayout
Parameters:
attributes - New attributes.
See Also:
TreeLayout.getAttributes()

setDescendantsSelected

protected void setDescendantsSelected(TreeNode node,
                                      boolean selected)
Sets the selection state of the branch beneath the specified node.

Parameters:
node - the TreeNode who descendants selection should be set.
selected - true to mark the descendants and selected, otherwise false.

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.

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.

setHighlightAttributes

public void setHighlightAttributes(TreeAttributes attributes)
Set the attributes to use when the tree is highlighted.

Parameters:
attributes - New highlight attributes.

setHighlighted

public void setHighlighted(boolean highlighted)
Set the tree layout to highlighted or not highlighted.

Specified by:
setHighlighted in interface Scrollable
Parameters:
highlighted - True if the tree should be highlighted.

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.

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.

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.

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.

toggleNodeSelection

protected void toggleNodeSelection(TreeNode node)
Toggles the selection state of the specified 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:

Parameters:
node - the TreeNode who's selection state should be toggled.

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.

NASA World Wind