NASA World Wind

gov.nasa.worldwind.util.layertree
Class LayerTreeModel

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.util.tree.BasicTreeModel
              extended by gov.nasa.worldwind.util.layertree.LayerTreeModel
All Implemented Interfaces:
AVList, MessageListener, TreeModel, WWObject, PropertyChangeListener, EventListener

public class LayerTreeModel
extends BasicTreeModel

A tree model representing Layer objects and their content. LayerTreeModel initializes itself with a default root node. By default, this root node is of type BasicTreeNode and its text is "Layers". Nodes added under the tree model's root should always be of type LayerTreeNode. a LayerTreeNode may be of any type.

LayerTreeModel provides operations for performing the following common tasks on a layer tree:

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 setting AVKey.HIDDEN to true:

hiddenLayer.setValue(AVKey.HIDDEN, true); // Prevent layer from being displayed in the layer tree


Field Summary
protected static 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
LayerTreeModel()
          Creates a new LayerTreeModel with the default root node.
LayerTreeModel(LayerList layerList)
          Creates a new LayerTreeModel with the default root node and adds a new LayerTreeNode for each non-hidden Layer in the specified layerList.
LayerTreeModel(LayerList layerList, boolean includeHiddenLayers)
          Creates a new LayerTreeModel with the default root node and adds a new LayerTreeNode for each Layer in the specified layerList.
 
Method Summary
 LayerTreeNode addLayer(Layer layer)
          Adds the a new LayerTreeNode created with the specified layer to this tree model's root node.
 void addLayer(LayerTreeNode layerNode)
          Adds the specified layerNode to this tree model's root node.
protected  LayerTreeNode createLayerNode(Layer layer)
          Returns a new root LayerTreeNode for the specified layer.
protected  TreeNode createRootNode()
          Returns a new root TreeNode 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 specified layerList.
 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, 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

DEFAULT_ROOT_NAME

protected static final 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 new LayerTreeModel with the default root node. Otherwise the new model is empty.


LayerTreeModel

public LayerTreeModel(LayerList layerList)
Creates a new LayerTreeModel with the default root node and adds a new LayerTreeNode for each non-hidden Layer in the specified layerList. The tree will not include layers marked as hidden.

Parameters:
layerList - the list of Layer objects to the new model represents.
Throws:
IllegalArgumentException - if the layerList is null.

LayerTreeModel

public LayerTreeModel(LayerList layerList,
                      boolean includeHiddenLayers)
Creates a new LayerTreeModel with the default root node and adds a new LayerTreeNode for each Layer in the specified layerList.

Parameters:
layerList - the list of Layer objects to the new model represents.
includeHiddenLayers - if this parameter is true, layers marked as hidden will be included in the tree. Otherwise hidden layers will not be included in the tree.
Throws:
IllegalArgumentException - if the layerList is null.
Method Detail

addLayer

public LayerTreeNode addLayer(Layer layer)
Adds the a new LayerTreeNode created with the specified layer to this tree model's root node. Nodes added under this tree model's root should always be of type LayerTreeNode. Note: this method adds the layer to the tree model regardless of whether or not the layer is marked as hidden.

Parameters:
layer - the layer to add.
Returns:
the LayerTreeNode created for the specified layer.
Throws:
IllegalArgumentException - if the layer is null.

addLayer

public void addLayer(LayerTreeNode layerNode)
Adds the specified layerNode to this tree model's root node. Nodes added under this tree model's root should always be of type LayerTreeNode. Note: this method adds the layer to the tree model regardless of whether or not the layer is marked as hidden.

Parameters:
layerNode - the layer node to add.
Throws:
IllegalArgumentException - if the layerNode is null.

createLayerNode

protected LayerTreeNode createLayerNode(Layer layer)
Returns a new root LayerTreeNode for the specified layer. Called from addLayer(Layer).

Parameters:
layer - the Layer to create a new LayerTreeNode for.
Returns:
a new LayerTreeNode.

createRootNode

protected TreeNode createRootNode()
Returns a new root TreeNode for this tree model. Called from initialize.

Returns:
a new TreeNode.

initialize

protected void initialize()
Initializes this tree model with the default root node.


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.

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.

refresh

public void refresh(LayerList layerList)
Refreshes this tree model's layer nodes with the specified layerList. Clears this tree model by removing all children of the root node, then adds a new LayerTreeNode for each Layer in the specified layerList. Layers marked as hidden will not be included in the tree model, unless the includeHiddenLayers property is set to true.

Parameters:
layerList - the list of Layer objects to the new model represents.
Throws:
IllegalArgumentException - if the layerList is null.
See Also:
setIncludeHiddenLayers(boolean)

removeAllLayers

public void removeAllLayers()
Clears this tree model by removing all children of the root node.


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 to refresh. A layer can be marked as hidden by setting the value for key AVKey.HIDDEN to true.

Parameters:
includeHiddenLayers - true if the tree model should include hidden layers. false if the model should ignore layers marked as hidden.

NASA World Wind