Class LayerTreeModel
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.util.tree.BasicTreeModel
-
- gov.nasa.worldwind.util.layertree.LayerTreeModel
-
- All Implemented Interfaces:
AVList
,MessageListener
,TreeModel
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class LayerTreeModel extends BasicTreeModel
A tree model representing
objects and their content.Layer
LayerTreeModel
initializes itself with a default root node. By default, this root node is of typeBasicTreeNode
and its text is "Layers". Nodes added under the tree model's root should always be of type
. aLayerTreeNode
LayerTreeNode
may be of any type.LayerTreeModel
provides operations for performing the following common tasks on a layer tree:- Adding a layer node.
- Removing all layer nodes.
- Refreshing the layer nodes from a
.LayerList
By default, the tree model does not include layers marked as hidden. This allows an application to prevent certain layers in a
LayerList
from appearing in the tree. For example, the layer that renders the tree itself usually should not appear in the tree. If it did then the user could turn off the tree layer and have no way of getting it back. A layer can be marked as hidden by settingAVKey.HIDDEN
totrue
:hiddenLayer.setValue(AVKey.HIDDEN, true); // Prevent layer from being displayed in the layer tree
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
DEFAULT_ROOT_NAME
The default root name: "Layers".protected boolean
includeHiddenLayers
Indicates whether or not the tree model must include hidden layers.-
Fields inherited from class gov.nasa.worldwind.util.tree.BasicTreeModel
root
-
-
Constructor Summary
Constructors Constructor Description LayerTreeModel()
Creates a newLayerTreeModel
with the default root node.LayerTreeModel(LayerList layerList)
Creates a newLayerTreeModel
with the default root node and adds a newLayerTreeNode
for each non-hiddenLayer
in the specifiedlayerList
.LayerTreeModel(LayerList layerList, boolean includeHiddenLayers)
Creates a newLayerTreeModel
with the default root node and adds a newLayerTreeNode
for eachLayer
in the specifiedlayerList
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LayerTreeNode
addLayer(Layer layer)
Adds the a newLayerTreeNode
created with the specifiedlayer
to this tree model's root node.void
addLayer(LayerTreeNode layerNode)
Adds the specifiedlayerNode
to this tree model's root node.protected LayerTreeNode
createLayerNode(Layer layer)
Returns a new rootLayerTreeNode
for the specifiedlayer
.protected TreeNode
createRootNode()
Returns a new rootTreeNode
for this tree model.protected void
initialize()
Initializes this tree model with the default root node.boolean
isIncludeHiddenLayers()
Indicates whether or not this tree model includes layers marked as hidden.protected boolean
mustIncludeLayer(Layer layer)
Determines if a layer must be included in the layer tree.void
refresh(LayerList layerList)
Refreshes this tree model's layer nodes with the specifiedlayerList
.void
removeAllLayers()
Clears this tree model by removing all children of the root node.void
setIncludeHiddenLayers(boolean includeHiddenLayers)
Specifies whether or not this tree model includes layers marked as hidden.-
Methods inherited from class gov.nasa.worldwind.util.tree.BasicTreeModel
getRoot, setRoot
-
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
-
DEFAULT_ROOT_NAME
protected static final java.lang.String DEFAULT_ROOT_NAME
The default root name: "Layers".- See Also:
- Constant Field Values
-
includeHiddenLayers
protected boolean includeHiddenLayers
Indicates whether or not the tree model must include hidden layers.
-
-
Constructor Detail
-
LayerTreeModel
public LayerTreeModel()
Creates a newLayerTreeModel
with the default root node. Otherwise the new model is empty.
-
LayerTreeModel
public LayerTreeModel(LayerList layerList)
Creates a newLayerTreeModel
with the default root node and adds a newLayerTreeNode
for each non-hiddenLayer
in the specifiedlayerList
. The tree will not include layers marked as hidden.- Parameters:
layerList
- the list ofLayer
objects to the new model represents.- Throws:
java.lang.IllegalArgumentException
- if thelayerList
isnull
.
-
LayerTreeModel
public LayerTreeModel(LayerList layerList, boolean includeHiddenLayers)
Creates a newLayerTreeModel
with the default root node and adds a newLayerTreeNode
for eachLayer
in the specifiedlayerList
.- Parameters:
layerList
- the list ofLayer
objects to the new model represents.includeHiddenLayers
- if this parameter istrue
, layers marked as hidden will be included in the tree. Otherwise hidden layers will not be included in the tree.- Throws:
java.lang.IllegalArgumentException
- if thelayerList
isnull
.
-
-
Method Detail
-
isIncludeHiddenLayers
public boolean isIncludeHiddenLayers()
Indicates whether or not this tree model includes layers marked as hidden.- Returns:
true
if hidden layers are included in the tree mode.false
if hidden layers are not included.
-
setIncludeHiddenLayers
public void setIncludeHiddenLayers(boolean includeHiddenLayers)
Specifies whether or not this tree model includes layers marked as hidden. Changes will take effect on the next call torefresh
. A layer can be marked as hidden by setting the value for keyAVKey.HIDDEN
totrue
.- Parameters:
includeHiddenLayers
-true
if the tree model should include hidden layers.false
if the model should ignore layers marked as hidden.
-
initialize
protected void initialize()
Initializes this tree model with the default root node.
-
createRootNode
protected TreeNode createRootNode()
Returns a new rootTreeNode
for this tree model. Called frominitialize
.- Returns:
- a new
TreeNode
.
-
addLayer
public void addLayer(LayerTreeNode layerNode)
Adds the specifiedlayerNode
to this tree model's root node. Nodes added under this tree model's root should always be of type
. Note: this method adds the layer to the tree model regardless of whether or not the layer is marked as hidden.LayerTreeNode
- Parameters:
layerNode
- the layer node to add.- Throws:
java.lang.IllegalArgumentException
- if thelayerNode
isnull
.
-
addLayer
public LayerTreeNode addLayer(Layer layer)
Adds the a newLayerTreeNode
created with the specifiedlayer
to this tree model's root node. Nodes added under this tree model's root should always be of type
. Note: this method adds the layer to the tree model regardless of whether or not the layer is marked as hidden.LayerTreeNode
- Parameters:
layer
- the layer to add.- Returns:
- the
LayerTreeNode
created for the specifiedlayer
. - Throws:
java.lang.IllegalArgumentException
- if thelayer
isnull
.
-
createLayerNode
protected LayerTreeNode createLayerNode(Layer layer)
Returns a new rootLayerTreeNode
for the specifiedlayer
. Called fromaddLayer(Layer)
.- Parameters:
layer
- theLayer
to create a newLayerTreeNode
for.- Returns:
- a new
LayerTreeNode
.
-
removeAllLayers
public void removeAllLayers()
Clears this tree model by removing all children of the root node.
-
refresh
public void refresh(LayerList layerList)
Refreshes this tree model's layer nodes with the specifiedlayerList
. Clears this tree model by removing all children of the root node, then adds a newLayerTreeNode
for eachLayer
in the specifiedlayerList
. Layers marked as hidden will not be included in the tree model, unless theincludeHiddenLayers
property is set totrue
.- Parameters:
layerList
- the list ofLayer
objects to the new model represents.- Throws:
java.lang.IllegalArgumentException
- if thelayerList
isnull
.- See Also:
setIncludeHiddenLayers(boolean)
-
mustIncludeLayer
protected boolean mustIncludeLayer(Layer layer)
Determines if a layer must be included in the layer tree.- Parameters:
layer
- Layer to test.- Returns:
true
if the layer must be included in the tree,false
if the layer must not be included.
-
-