NASA World Wind

gov.nasa.worldwind.util.tree
Class BasicTreeNode

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.util.tree.BasicTreeNode
All Implemented Interfaces:
AVList, MessageListener, TreeNode, WWObject, PropertyChangeListener, EventListener
Direct Known Subclasses:
KMLFeatureTreeNode, LayerTreeNode

public class BasicTreeNode
extends WWObjectImpl
implements TreeNode

Default implementation of a TreeNode.


Field Summary
protected  List<TreeNode> children
           
protected  String description
           
protected  boolean enabled
           
protected  Object imageSource
           
protected  TreeNode parent
           
protected  boolean selected
           
protected  String text
           
protected  BasicWWTexture texture
           
protected  String treeSelected
          Flag to indicate that any part of the sub-tree rooted at this node is selected.
protected  boolean visible
           
 
Fields inherited from interface gov.nasa.worldwind.util.tree.TreeNode
NOT_SELECTED, PARTIALLY_SELECTED, SELECTED
 
Constructor Summary
BasicTreeNode(String text)
          Create a node with text.
BasicTreeNode(String text, Object imageSource)
          Create a node with text and an icon.
 
Method Summary
 void addChild(int index, TreeNode child)
          Add a child node at a specified position in the list of children.
 void addChild(TreeNode child)
          Add a child node.
protected  String computeTreeSelected()
          Determine if any part of the sub-tree rooted at this node is selected.
 Iterable<TreeNode> getChildren()
          Get the children of this node.
 String getDescription()
          Get extra text associated with this node.
 Object getImageSource()
          Get the source of the node icon.
 TreeNode getParent()
          Get the node's parent.
 TreePath getPath()
          Get the path from the root node to this node.
 String getText()
          Get the text of this node.
 BasicWWTexture getTexture()
          Get the texture loaded for the node's icon.
 boolean hasImage()
          Does this node have an icon? This method returns true if an image source has been set.
protected  void initializeTexture()
          Create and initialize the texture from the image source.
 boolean isEnabled()
          Is the node enabled?
 boolean isLeaf()
          Is the node a leaf node.
 boolean isSelected()
          Is the node selected?
 String isTreeSelected()
          Is any part of the sub-tree rooted at this node selected?
 boolean isVisible()
          Is the node visible?
 void propertyChange(PropertyChangeEvent propertyChangeEvent)
          The property change listener for this instance.
 void removeAllChildren()
          Remove all of the child nodes from this node.
 void removeChild(TreeNode child)
          Remove a child node.
 void setDescription(String description)
          Set the node description.
 void setEnabled(boolean enabled)
          Set the node to enabled or not enabled.
 void setImageSource(Object imageSource)
          Set the node's icon.
 void setParent(TreeNode node)
          Set the parent node.
 void setSelected(boolean selected)
          Set the node to selected or not selected.
 void setVisible(boolean visible)
          Set the node to visible or not visible.
 
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage
 
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 gov.nasa.worldwind.event.MessageListener
onMessage
 

Field Detail

children

protected List<TreeNode> children

description

protected String description

enabled

protected boolean enabled

imageSource

protected Object imageSource

parent

protected TreeNode parent

selected

protected boolean selected

text

protected String text

texture

protected BasicWWTexture texture

treeSelected

protected String treeSelected
Flag to indicate that any part of the sub-tree rooted at this node is selected. This value is computed on demand and cached.


visible

protected boolean visible
Constructor Detail

BasicTreeNode

public BasicTreeNode(String text)
Create a node with text.

Parameters:
text - Node text.

BasicTreeNode

public BasicTreeNode(String text,
                     Object imageSource)
Create a node with text and an icon.

Parameters:
text - Node text.
imageSource - Image source for the node icon. May be a String, URL, or BufferedImage.
Method Detail

addChild

public void addChild(int index,
                     TreeNode child)
Add a child node at a specified position in the list of children.

Specified by:
addChild in interface TreeNode
Parameters:
index - Index at which the new child will be inserted.
child - New child.

addChild

public void addChild(TreeNode child)
Add a child node.

Specified by:
addChild in interface TreeNode
Parameters:
child - New child.

computeTreeSelected

protected String computeTreeSelected()
Determine if any part of the sub-tree rooted at this node is selected.

Returns:
TreeNode.SELECTED, TreeNode.NOT_SELECTED, TreeNode.PARTIALLY_SELECTED.

getChildren

public Iterable<TreeNode> getChildren()
Get the children of this node.

Specified by:
getChildren in interface TreeNode
Returns:
Child nodes, or an empty iterator if the node does not have children.
See Also:
TreeNode.addChild(TreeNode)

getDescription

public String getDescription()
Description copied from interface: TreeNode
Get extra text associated with this node.

Specified by:
getDescription in interface TreeNode
Returns:
Description of node.

getImageSource

public Object getImageSource()
Get the source of the node icon.

Specified by:
getImageSource in interface TreeNode
Returns:
Image source of the icon. null if the node does not have an icon.

getParent

public TreeNode getParent()
Get the node's parent. Each node in the tree has a parent, except for the root node. The parent of the root node is null.

Specified by:
getParent in interface TreeNode
Returns:
Parent node, or null if this the root node.
See Also:
TreeNode.setParent(TreeNode)

getPath

public TreePath getPath()
Get the path from the root node to this node.

Specified by:
getPath in interface TreeNode
Returns:
Tree path to this node.

getText

public String getText()
Get the text of this node.

Specified by:
getText in interface TreeNode
Returns:
Node text.

getTexture

public BasicWWTexture getTexture()
Get the texture loaded for the node's icon.

Specified by:
getTexture in interface TreeNode
Returns:
Icon texture, or null if the texture has not been loaded yet.

hasImage

public boolean hasImage()
Does this node have an icon? This method returns true if an image source has been set. The method returns true even if the image has not been fully loaded.

Specified by:
hasImage in interface TreeNode
Returns:
True if the node has an image.

initializeTexture

protected void initializeTexture()
Create and initialize the texture from the image source. If the image is not in memory this method will request that it be loaded.


isEnabled

public boolean isEnabled()
Is the node enabled?

Specified by:
isEnabled in interface TreeNode
Returns:
True if the node is enabled.
See Also:
TreeNode.setEnabled(boolean)

isLeaf

public boolean isLeaf()
Is the node a leaf node.

Specified by:
isLeaf in interface TreeNode
Returns:
True if this is a leaf node.

isSelected

public boolean isSelected()
Is the node selected?

Specified by:
isSelected in interface TreeNode
Returns:
True if the node is selected.
See Also:
TreeNode.setSelected(boolean), TreeNode.isTreeSelected()

isTreeSelected

public String isTreeSelected()
Is any part of the sub-tree rooted at this node selected?

Specified by:
isTreeSelected in interface TreeNode
Returns:
TreeNode.SELECTED, TreeNode.NOT_SELECTED, TreeNode.PARTIALLY_SELECTED.

isVisible

public boolean isVisible()
Is the node visible?

Specified by:
isVisible in interface TreeNode
Returns:
True if the node is visible.
See Also:
TreeNode.setVisible(boolean)

propertyChange

public void propertyChange(PropertyChangeEvent propertyChangeEvent)
The property change listener for this instance. Receives property change notifications that this instance has registered with other property change notifiers.

Specified by:
propertyChange in interface PropertyChangeListener
Overrides:
propertyChange in class WWObjectImpl
Parameters:
propertyChangeEvent - the event

removeAllChildren

public void removeAllChildren()
Remove all of the child nodes from this node.

Specified by:
removeAllChildren in interface TreeNode

removeChild

public void removeChild(TreeNode child)
Remove a child node.

Specified by:
removeChild in interface TreeNode
Parameters:
child - Child to remove.

setDescription

public void setDescription(String description)
Description copied from interface: TreeNode
Set the node description. The description can hold any extra text associated with the node.

Specified by:
setDescription in interface TreeNode
Parameters:
description - New description.

setEnabled

public void setEnabled(boolean enabled)
Set the node to enabled or not enabled. A node that is not enabled will not respond to user input.

Specified by:
setEnabled in interface TreeNode
Parameters:
enabled - New enabled state.
See Also:
TreeNode.isEnabled()

setImageSource

public void setImageSource(Object imageSource)
Set the node's icon.

Specified by:
setImageSource in interface TreeNode
Parameters:
imageSource - New icon source. May be a String, URL, or BufferedImage.

setParent

public void setParent(TreeNode node)
Set the parent node.

Specified by:
setParent in interface TreeNode
Parameters:
node - New parent node.
See Also:
TreeNode.getParent()

setSelected

public void setSelected(boolean selected)
Set the node to selected or not selected.

Specified by:
setSelected in interface TreeNode
Parameters:
selected - New selection value.
See Also:
TreeNode.isSelected()

setVisible

public void setVisible(boolean visible)
Set the node to visible or not visible. If the node is not visible it will not be drawn by the tree layout.

Specified by:
setVisible in interface TreeNode
Parameters:
visible - New visibility setting.
See Also:
TreeNode.isVisible()

NASA World Wind