Class LayerTreeModel

  • All Implemented Interfaces:
    AVList, MessageListener, TreeModel, WWObject, java.beans.PropertyChangeListener, java.util.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:

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

    hiddenLayer.setValue(AVKey.HIDDEN, true); // Prevent layer from being displayed in the layer tree
    • 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 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:
        java.lang.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:
        java.lang.IllegalArgumentException - if the layerList is null.
    • 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 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.
      • initialize

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

        protected TreeNode createRootNode()
        Returns a new root TreeNode for this tree model. Called from initialize.
        Returns:
        a new TreeNode.
      • 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:
        java.lang.IllegalArgumentException - if the layerNode is null.
      • 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:
        java.lang.IllegalArgumentException - if the layer 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.
      • 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 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:
        java.lang.IllegalArgumentException - if the layerList is null.
        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.