Class DefaultTreeCheckingModel

java.lang.Object
eu.essilab.lablib.checkboxtree.DefaultTreeCheckingModel
All Implemented Interfaces:
TreeCheckingModel

public class DefaultTreeCheckingModel extends Object implements TreeCheckingModel
The default checking model, providing methods for storing and retrieving the checked TreePaths. Adding/removing paths is delegated to a CheckingMode instance. This implementation is based on TreePath only and does not take advantage of TreeNode convenience methods (this is left to future/alternative implementations).
Author:
Lorenzo Bigagli, Enrico Boldrini
  • Field Details

  • Constructor Details

    • DefaultTreeCheckingModel

      public DefaultTreeCheckingModel(TreeModel model)
      Creates a DefaultTreeCheckingModel with PropagateTreeCheckingMode.
  • Method Details

    • addCheckingPath

      public void addCheckingPath(TreePath path)
      Adds a path to the checked paths set.
      Specified by:
      addCheckingPath in interface TreeCheckingModel
      Parameters:
      path - the path to be added.
    • addCheckingPaths

      public void addCheckingPaths(TreePath[] paths)
      Adds the paths to the checked paths set.
      Specified by:
      addCheckingPaths in interface TreeCheckingModel
      Parameters:
      paths - the paths to be added.
    • addTreeCheckingListener

      public void addTreeCheckingListener(TreeCheckingListener x)
      Adds x to the list of listeners that are notified each time the set of checking TreePaths changes.
      Specified by:
      addTreeCheckingListener in interface TreeCheckingModel
      Parameters:
      x - the new listener to be added
    • checkSubTree

      public void checkSubTree(TreePath path)
      Checks the subtree with root path.
      Parameters:
      path - root of the tree to be checked
    • clearChecking

      public void clearChecking()
      Clears the checking.
      Specified by:
      clearChecking in interface TreeCheckingModel
    • fireValueChanged

      protected void fireValueChanged(TreeCheckingEvent e)
      Notifies all listeners that are registered for tree selection events on this object.
      See Also:
    • getCheckingMode

      public TreeCheckingModel.CheckingMode getCheckingMode()
      Specified by:
      getCheckingMode in interface TreeCheckingModel
      Returns:
      The CheckingMode.
    • getCheckingPaths

      public TreePath[] getCheckingPaths()
      Specified by:
      getCheckingPaths in interface TreeCheckingModel
      Returns:
      Returns the paths that are in the checking.
    • getCheckingRoots

      public TreePath[] getCheckingRoots()
      Specified by:
      getCheckingRoots in interface TreeCheckingModel
      Returns:
      Returns the path of any root of a subtree in the checking.
    • getChildrenChecking

      public DefaultTreeCheckingModel.ChildrenChecking getChildrenChecking(TreePath path)
    • getChildrenPath

      protected TreePath[] getChildrenPath(TreePath path)
      Return the paths that are children of path, using methods of TreeModel. Nodes don't have to be of type TreeNode.
      Parameters:
      path - the parent path
      Returns:
      the array of children path
    • getGreyingPaths

      public TreePath[] getGreyingPaths()
      Specified by:
      getGreyingPaths in interface TreeCheckingModel
      Returns:
      The paths that are in the greying.
    • hasDifferentChildren

      public boolean hasDifferentChildren(TreePath path)
      Parameters:
      path - the root path of the tree to be checked.
      Returns:
      true if exists a child of node with a value different from itself.
    • isPathChecked

      public boolean isPathChecked(TreePath path)
      Description copied from interface: TreeCheckingModel
      Returns true if the item identified by the path is currently checked.
      Specified by:
      isPathChecked in interface TreeCheckingModel
      Parameters:
      path - a TreePath identifying a node
      Returns:
      true if the node is checked
    • isPathEnabled

      public boolean isPathEnabled(TreePath path)
      Description copied from interface: TreeCheckingModel
      Returns whether the specified path checking state can be toggled.
      Specified by:
      isPathEnabled in interface TreeCheckingModel
    • isPathGreyed

      public boolean isPathGreyed(TreePath path)
      Description copied from interface: TreeCheckingModel
      Returns whether the specified path is greyed.
      Specified by:
      isPathGreyed in interface TreeCheckingModel
    • pathHasCheckedChildren

      public boolean pathHasCheckedChildren(TreePath path)
      Parameters:
      path - the root of the subtree to be checked.
      Returns:
      true if exists a checked node in the subtree of path.
    • pathHasChildrenWithValue

      protected boolean pathHasChildrenWithValue(TreePath path, boolean value)
      Parameters:
      path - the root of the subtree to be searched.
      value - the value to be found.
      Returns:
      true if exists a node with checked status value in the subtree of path.
    • pathHasUncheckedChildren

      public boolean pathHasUncheckedChildren(TreePath path)
      Note: The checking and the greyness of children MUST be consistent to work properly.
      Parameters:
      path - the root of the subtree to be checked.
      Returns:
      true if exists an unchecked node in the subtree of path.
    • removeCheckingPath

      public void removeCheckingPath(TreePath path)
      Removes a path from the checked paths set
      Specified by:
      removeCheckingPath in interface TreeCheckingModel
      Parameters:
      path - the path to be removed
    • removeCheckingPaths

      public void removeCheckingPaths(TreePath[] paths)
      Removes the paths from the checked paths set
      Specified by:
      removeCheckingPaths in interface TreeCheckingModel
      Parameters:
      paths - the paths to be removed
    • removeTreeCheckingListener

      public void removeTreeCheckingListener(TreeCheckingListener x)
      Removes x from the list of listeners that are notified each time the set of checking TreePaths changes.
      Specified by:
      removeTreeCheckingListener in interface TreeCheckingModel
      Parameters:
      x - the listener to remove
    • setCheckingMode

      public void setCheckingMode(TreeCheckingModel.CheckingMode mode)
      Sets the specified checking mode. The consistence of the existing checking is not enforced nor controlled.
      Specified by:
      setCheckingMode in interface TreeCheckingModel
      Parameters:
      mode - the checking mode to set.
    • setCheckingMode

      public void setCheckingMode(TreeCheckingMode mode)
      Sets the specified checking mode. The consistence of the existing checking is not enforced nor controlled.
    • setCheckingPath

      public void setCheckingPath(TreePath path)
      Sets the checking to path.
      Specified by:
      setCheckingPath in interface TreeCheckingModel
    • setCheckingPaths

      public void setCheckingPaths(TreePath[] paths)
      Sets the checking to the specified paths.
      Specified by:
      setCheckingPaths in interface TreeCheckingModel
    • setPathEnabled

      public void setPathEnabled(TreePath path, boolean enable)
      Sets whether or not the path is enabled.
      Specified by:
      setPathEnabled in interface TreeCheckingModel
      Parameters:
      path - the path to enable/disable
    • setPathsEnabled

      public void setPathsEnabled(TreePath[] paths, boolean enable)
      Sets whether or not the paths are enabled.
      Specified by:
      setPathsEnabled in interface TreeCheckingModel
      Parameters:
      paths - the paths to enable/disable
    • setTreeModel

      public void setTreeModel(TreeModel newModel)
      Sets the specified tree model. The current checking set is cleared.
    • toggleCheckingPath

      public void toggleCheckingPath(TreePath path)
      Delegates to the current checkingMode the toggling style, using the Strategy Pattern.
      Specified by:
      toggleCheckingPath in interface TreeCheckingModel
    • toString

      public String toString()
      Return a string that describes the tree model including the values of checking, enabling, greying.
      Overrides:
      toString in class Object
    • uncheckSubTree

      public void uncheckSubTree(TreePath path)
      Unchecks the subtree rooted at path.
      Parameters:
      path - root of the tree to be unchecked
    • ungreySubTree

      public void ungreySubTree(TreePath path)
      Ungreys the subtree rooted at path.
      Parameters:
      path - the root of the tree to be checked
    • updateAncestorsGreyness

      public void updateAncestorsGreyness(TreePath path)
      Updates the grayness value of the parents of path. Note: the greyness and checking of the other nodes (not ancestors) MUST BE consistent.
      Parameters:
      path - the treepath containing the ancestors to be grey-updated
    • updateCheckingConsistency

      public void updateCheckingConsistency()
      Updates consistency of the checking, by invoking updateSubTreeCheckingConsistency on the root node.
    • updatePathGreyness

      protected void updatePathGreyness(TreePath ancestor)
      Updates the greyness value value for the given path if there are children with different values. Note: the greyness and cheking of children MUST BE consistent.
      Parameters:
      ancestor - the path to be grey-updated.
    • updateSubTreeCheckingConsistency

      public void updateSubTreeCheckingConsistency(TreePath path)
      Updates consistency of the checking of sub-tree starting at path. It's based on paths greyness.
      Parameters:
      path - the root of the sub-tree to be grey-updated
    • updateSubTreeGreyness

      public void updateSubTreeGreyness(TreePath path)
      Updates the greyness of sub-tree starting at path.
      Parameters:
      path - the root of the sub-tree to be grey-updated
    • updateTreeGreyness

      public void updateTreeGreyness()
      Updates the greyness state of the entire tree.