Package gov.nasa.worldwind.util.tree
Class BasicTreeNode
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.util.tree.BasicTreeNode
-
- All Implemented Interfaces:
AVList
,MessageListener
,TreeNode
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
- Direct Known Subclasses:
KMLFeatureTreeNode
,LayerTreeNode
public class BasicTreeNode extends WWObjectImpl implements TreeNode
Default implementation of aTreeNode
.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<TreeNode>
children
protected java.lang.String
description
protected boolean
enabled
protected java.lang.Object
imageSource
protected TreeNode
parent
protected boolean
selected
protected java.lang.String
text
protected BasicWWTexture
texture
protected java.lang.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
Constructors Constructor Description BasicTreeNode(java.lang.String text)
Create a node with text.BasicTreeNode(java.lang.String text, java.lang.Object imageSource)
Create a node with text and an icon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 java.lang.String
computeTreeSelected()
Determine if any part of the sub-tree rooted at this node is selected.java.lang.Iterable<TreeNode>
getChildren()
Get the children of this node.java.lang.String
getDescription()
Get extra text associated with this node.java.lang.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.java.lang.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?java.lang.String
isTreeSelected()
Is any part of the sub-tree rooted at this node selected?boolean
isVisible()
Is the node visible?void
propertyChange(java.beans.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(java.lang.String description)
Set the node description.void
setEnabled(boolean enabled)
Set the node to enabled or not enabled.void
setImageSource(java.lang.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, 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
-
text
protected java.lang.String text
-
imageSource
protected java.lang.Object imageSource
-
texture
protected BasicWWTexture texture
-
description
protected java.lang.String description
-
parent
protected TreeNode parent
-
children
protected java.util.List<TreeNode> children
-
enabled
protected boolean enabled
-
selected
protected boolean selected
-
visible
protected boolean visible
-
treeSelected
protected java.lang.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.
-
-
Constructor Detail
-
BasicTreeNode
public BasicTreeNode(java.lang.String text)
Create a node with text.- Parameters:
text
- Node text.
-
BasicTreeNode
public BasicTreeNode(java.lang.String text, java.lang.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
-
getText
public java.lang.String getText()
Get the text of this node.
-
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 isnull
.- Specified by:
getParent
in interfaceTreeNode
- Returns:
- Parent node, or
null
if this the root node. - See Also:
TreeNode.setParent(TreeNode)
-
setParent
public void setParent(TreeNode node)
Set the parent node.- Specified by:
setParent
in interfaceTreeNode
- Parameters:
node
- New parent node.- See Also:
TreeNode.getParent()
-
getChildren
public java.lang.Iterable<TreeNode> getChildren()
Get the children of this node.- Specified by:
getChildren
in interfaceTreeNode
- Returns:
- Child nodes, or an empty iterator if the node does not have children.
- See Also:
TreeNode.addChild(TreeNode)
-
isEnabled
public boolean isEnabled()
Is the node enabled?- Specified by:
isEnabled
in interfaceTreeNode
- Returns:
- True if the node is enabled.
- See Also:
TreeNode.setEnabled(boolean)
-
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 interfaceTreeNode
- Parameters:
enabled
- New enabled state.- See Also:
TreeNode.isEnabled()
-
isSelected
public boolean isSelected()
Is the node selected?- Specified by:
isSelected
in interfaceTreeNode
- Returns:
- True if the node is selected.
- See Also:
TreeNode.setSelected(boolean)
,TreeNode.isTreeSelected()
-
setSelected
public void setSelected(boolean selected)
Set the node to selected or not selected.- Specified by:
setSelected
in interfaceTreeNode
- Parameters:
selected
- New selection value.- See Also:
TreeNode.isSelected()
-
isTreeSelected
public java.lang.String isTreeSelected()
Is any part of the sub-tree rooted at this node selected?- Specified by:
isTreeSelected
in interfaceTreeNode
- Returns:
TreeNode.SELECTED
,TreeNode.NOT_SELECTED
,TreeNode.PARTIALLY_SELECTED
.
-
computeTreeSelected
protected java.lang.String computeTreeSelected()
Determine if any part of the sub-tree rooted at this node is selected.
-
isVisible
public boolean isVisible()
Is the node visible?- Specified by:
isVisible
in interfaceTreeNode
- Returns:
- True if the node is visible.
- See Also:
TreeNode.setVisible(boolean)
-
isLeaf
public boolean isLeaf()
Is the node a leaf node.
-
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 interfaceTreeNode
- Parameters:
visible
- New visibility setting.- See Also:
TreeNode.isVisible()
-
getDescription
public java.lang.String getDescription()
Description copied from interface:TreeNode
Get extra text associated with this node.- Specified by:
getDescription
in interfaceTreeNode
- Returns:
- Description of node.
-
setDescription
public void setDescription(java.lang.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 interfaceTreeNode
- Parameters:
description
- New description.
-
getImageSource
public java.lang.Object getImageSource()
Get the source of the node icon.- Specified by:
getImageSource
in interfaceTreeNode
- Returns:
- Image source of the icon.
null
if the node does not have an icon.
-
setImageSource
public void setImageSource(java.lang.Object imageSource)
Set the node's icon.- Specified by:
setImageSource
in interfaceTreeNode
- Parameters:
imageSource
- New icon source. May be a String, URL, or BufferedImage.
-
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.
-
getTexture
public BasicWWTexture getTexture()
Get the texture loaded for the node's icon.- Specified by:
getTexture
in interfaceTreeNode
- Returns:
- Icon texture, or null if the texture has not been loaded yet.
-
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.
-
addChild
public void addChild(TreeNode child)
Add a child node.
-
addChild
public void addChild(int index, TreeNode child)
Add a child node at a specified position in the list of children.
-
removeChild
public void removeChild(TreeNode child)
Remove a child node.- Specified by:
removeChild
in interfaceTreeNode
- Parameters:
child
- Child to remove.
-
removeAllChildren
public void removeAllChildren()
Remove all of the child nodes from this node.- Specified by:
removeAllChildren
in interfaceTreeNode
-
getPath
public TreePath getPath()
Get the path from the root node to this node.
-
propertyChange
public void propertyChange(java.beans.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 interfacejava.beans.PropertyChangeListener
- Overrides:
propertyChange
in classWWObjectImpl
- Parameters:
propertyChangeEvent
- the event
-
-