Class PathTree

All Implemented Interfaces:
Serializable, TreeModel

public class PathTree extends DefaultTreeModel
A class that creates and manipulates sorted trees. This is useful for displaying trees of accounts or reports.

Nodes are added by specifying a label. The label is split into parts by the separator character, and nodes are added hierarchicaly for each name part. The object is added to the leaf node with the label of the last part of the name.

Leaf nodes may be retrieved by using the full label.

See Also:
Serialized Form
  • Constructor Details

    • PathTree

      public PathTree()
      Create a new empty tree model, with a top level folder name of 'Top', and a default separator character of '.'
    • PathTree

      public PathTree(String label, String separator)
      Create a new empty tree model, with a top level folder name of 'Top', and a default separator character of '.'.
      label - the name for the top level node
      separator - the character used to split labels in to parts for intermidate nodes.
  • Method Details

    • exists

      public boolean exists(String label, boolean folder)
      Determine if a label exists in the tree. The label is split in to parts using the separator character, and the parts are matched against the nodes in the tree. Returns true if the label can be matched in the tree.
      label - the label to search for
      folder - if true then allow matches where the last part of the label is not a leaf node.
    • addLabel

      public DefaultMutableTreeNode addLabel(String label, Object object)
    • addLabelInOrder

      public DefaultMutableTreeNode addLabelInOrder(String label, Object object)
    • addFolder

      public DefaultMutableTreeNode addFolder(String label, Object object)
    • insertInOrder

      public void insertInOrder(DefaultMutableTreeNode parent, DefaultMutableTreeNode node)
      Insert a node under parent in sorted order according to token
    • insertNodeInto

      public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
      Override the superclass method to ensure that duplicates are not permitted.
      insertNodeInto in class DefaultTreeModel
    • getLabel

      public String getLabel(DefaultMutableTreeNode node)
      Return the path string for a given node.
    • getLabel

      public static String getLabel(DefaultMutableTreeNode node, String sep)
    • getLabel

      public String getLabel(TreePath path)
      Return the path string for a given tree path.
    • getLabel

      public String getLabel(TreeNode[] tp)
      Return the path string for an array of TreeNode's. Ignore the root node label.
    • getLabel

      public static String getLabel(TreeNode[] tp, String sep)
    • getPath

      public DefaultMutableTreeNode[] getPath(String label, boolean folder)
      Get a tree path for a particular label
    • getLastPathComponent

      public DefaultMutableTreeNode getLastPathComponent(String label, boolean folder)
      Get the last node for this label. The folder parameter specifies if you are looking for a folder or a terminal.
    • findChild

      public static DefaultMutableTreeNode findChild(TreeNode top, String label, boolean folder)
    • findObject

      public static Object findObject(DefaultMutableTreeNode node, Object comp)
    • findObject

      public Object findObject(Object comp)
    • getLeafNames

      public Vector<String> getLeafNames(DefaultMutableTreeNode node)
      Get a vector containing the names of all the terminal paths that are located under the selected node.
    • getLeafNames

      public Vector getLeafNames()
    • getLeafObjects

      public List getLeafObjects(DefaultMutableTreeNode node)
      Get a vector containing the objects at all the terminal paths that are located under the selected node.
    • getLeafObjects

      public List getLeafObjects()
    • getTipEnumerator

      public Enumeration getTipEnumerator()
    • getCommonLabel

      public String getCommonLabel()