Package uk.ac.starlink.vo

## Class MaskTreeModel

- java.lang.Object
- - uk.ac.starlink.vo.MaskTreeModel

- All Implemented Interfaces:
    `javax.swing.tree.TreeModel`

      public class MaskTreeModel
      extends java.lang.Object
      implements javax.swing.tree.TreeModel

  Wrapper tree model that includes only a selection of the nodes in the base model. The selection is controlled by a supplied Mask object.

  It's intended for use with a static base model. It ought to work for a base model which sends TreeModelEvents, but that hasn't been tested, and it doesn't translate the events very cleverly to downstream listeners.

  Since:
    17 Mar 2015
  Author:
    Mark Taylor

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `MaskTreeModel.Mask` | Defines node inclusion in a masked tree.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `MaskTreeModel​(javax.swing.tree.TreeModel base, boolean includeDescendants)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addTreeModelListener​(javax.swing.event.TreeModelListener lnr)` |
    `javax.swing.tree.TreeModel` | `getBaseModel()` | Returns the underlying, unmasked, model.
    `java.lang.Object` | `getChild​(java.lang.Object parent, int index)` |
    `int` | `getChildCount​(java.lang.Object parent)` |
    `int` | `getIndexOfChild​(java.lang.Object parent, java.lang.Object child)` |
    `MaskTreeModel.Mask` | `getMask()` | Returns the currently active mask.
    `int` | `getNodeCount()` | Returns the total number of nodes in this model.
    `java.lang.Object` | `getRoot()` |
    `boolean` | `isLeaf​(java.lang.Object node)` |
    `void` | `removeTreeModelListener​(javax.swing.event.TreeModelListener lnr)` |
    `void` | `setBaseModel​(javax.swing.tree.TreeModel base)` | Sets the underlying, unmasked, model.
    `void` | `setMask​(MaskTreeModel.Mask mask)` | Sets the mask for defning inclusion of nodes in the base model.
    `void` | `valueForPathChanged​(javax.swing.tree.TreePath path, java.lang.Object newValue)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MaskTreeModel

          public MaskTreeModel​(javax.swing.tree.TreeModel base,
                               boolean includeDescendants)

      Constructor.
      Parameters:
        `base` - underlying tree model
        `includeDescendants` - if true, all descendants of an included node are automatically included

  - ### Method Detail

    - #### getRoot

          public java.lang.Object getRoot()

      Specified by:
        `getRoot` in interface `javax.swing.tree.TreeModel`

    - #### isLeaf

          public boolean isLeaf​(java.lang.Object node)

      Specified by:
        `isLeaf` in interface `javax.swing.tree.TreeModel`

    - #### getChildCount

          public int getChildCount​(java.lang.Object parent)

      Specified by:
        `getChildCount` in interface `javax.swing.tree.TreeModel`

    - #### getChild

          public java.lang.Object getChild​(java.lang.Object parent,
                                           int index)

      Specified by:
        `getChild` in interface `javax.swing.tree.TreeModel`

    - #### getIndexOfChild

          public int getIndexOfChild​(java.lang.Object parent,
                                     java.lang.Object child)

      Specified by:
        `getIndexOfChild` in interface `javax.swing.tree.TreeModel`

    - #### valueForPathChanged

          public void valueForPathChanged​(javax.swing.tree.TreePath path,
                                          java.lang.Object newValue)

      Specified by:
        `valueForPathChanged` in interface `javax.swing.tree.TreeModel`

    - #### addTreeModelListener

          public void addTreeModelListener​(javax.swing.event.TreeModelListener lnr)

      Specified by:
        `addTreeModelListener` in interface `javax.swing.tree.TreeModel`

    - #### removeTreeModelListener

          public void removeTreeModelListener​(javax.swing.event.TreeModelListener lnr)

      Specified by:
        `removeTreeModelListener` in interface `javax.swing.tree.TreeModel`

    - #### getBaseModel

          public javax.swing.tree.TreeModel getBaseModel()

      Returns the underlying, unmasked, model.
      Returns:
        base tree model

    - #### setBaseModel

          public void setBaseModel​(javax.swing.tree.TreeModel base)

      Sets the underlying, unmasked, model.
      Parameters:
        `base` - new base model

    - #### getMask

          public MaskTreeModel.Mask getMask()

      Returns the currently active mask.
      Returns:
        mask, may be null for full inclusion

    - #### setMask

          public void setMask​(MaskTreeModel.Mask mask)

      Sets the mask for defning inclusion of nodes in the base model. A null mask is used for full inclusion (and will be more efficient than one for which `isIncluded` always returns true).

      If the supplied `mask` matches the previously installed one by equality, no action is performed. So it's not essential that mask implementations implement equals/hashCode, but it may be beneficial.

      Parameters:
        `mask` - new mask, or null for full inclusion

    - #### getNodeCount

          public int getNodeCount()

      Returns the total number of nodes in this model.
      Returns:
        node count