Class TreeExpansionHandler

  • All Implemented Interfaces:
    java.util.EventListener, javax.swing.event.TreeExpansionListener, javax.swing.event.TreeModelListener

    public class TreeExpansionHandler
    extends java.lang.Object
    implements javax.swing.event.TreeExpansionListener, javax.swing.event.TreeModelListener
    The tree expansion handler assures that tree nodes stay expanded, even when their last child is removed, and then new child nodes are added. Swing doesn't do this on its own, grrr.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Set expanded
      A set with the tree nodes, which are expanded.
      protected javax.swing.JTree tree
      The tree.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeExpansionHandler​(javax.swing.JTree tree)
      Create a tree expansion handler for a given tree.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected IFuture handlePath​(javax.swing.tree.TreePath path)
      Check if an action (e.g.
      void handleTreeStructureChanged​(javax.swing.event.TreeModelEvent event, javax.swing.tree.TreePath root, int i)
      Handle each node in the subtree.
      boolean isExpanded​(javax.swing.tree.TreePath path)
      Test if a path is expanded or should be.
      static boolean isTreeExpanded​(javax.swing.JTree tree, javax.swing.tree.TreePath path)
      Test if a tree node is expanded or should be.
      void treeCollapsed​(javax.swing.event.TreeExpansionEvent event)
      Called whenever an item in the tree has been collapsed.
      void treeExpanded​(javax.swing.event.TreeExpansionEvent event)
      Called whenever an item in the tree has been expanded.
      void treeNodesChanged​(javax.swing.event.TreeModelEvent event)
      Invoked after a node (or a set of siblings) has changed in some way.
      void treeNodesInserted​(javax.swing.event.TreeModelEvent event)
      Invoked after nodes have been inserted into the tree.
      void treeNodesRemoved​(javax.swing.event.TreeModelEvent event)
      Invoked after nodes have been removed from the tree.
      void treeStructureChanged​(javax.swing.event.TreeModelEvent event)
      Invoked after the tree has drastically changed structure from a given node down.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tree

        protected javax.swing.JTree tree
        The tree.
      • expanded

        protected java.util.Set expanded
        A set with the tree nodes, which are expanded.
    • Constructor Detail

      • TreeExpansionHandler

        public TreeExpansionHandler​(javax.swing.JTree tree)
        Create a tree expansion handler for a given tree.
    • Method Detail

      • treeExpanded

        public void treeExpanded​(javax.swing.event.TreeExpansionEvent event)
        Called whenever an item in the tree has been expanded.
        Specified by:
        treeExpanded in interface javax.swing.event.TreeExpansionListener
      • treeCollapsed

        public void treeCollapsed​(javax.swing.event.TreeExpansionEvent event)
        Called whenever an item in the tree has been collapsed.
        Specified by:
        treeCollapsed in interface javax.swing.event.TreeExpansionListener
      • treeNodesChanged

        public void treeNodesChanged​(javax.swing.event.TreeModelEvent event)
        Invoked after a node (or a set of siblings) has changed in some way.
        Specified by:
        treeNodesChanged in interface javax.swing.event.TreeModelListener
      • treeNodesInserted

        public void treeNodesInserted​(javax.swing.event.TreeModelEvent event)
        Invoked after nodes have been inserted into the tree.
        Specified by:
        treeNodesInserted in interface javax.swing.event.TreeModelListener
      • treeNodesRemoved

        public void treeNodesRemoved​(javax.swing.event.TreeModelEvent event)
        Invoked after nodes have been removed from the tree.
        Specified by:
        treeNodesRemoved in interface javax.swing.event.TreeModelListener
      • treeStructureChanged

        public void treeStructureChanged​(javax.swing.event.TreeModelEvent event)
        Invoked after the tree has drastically changed structure from a given node down.
        Specified by:
        treeStructureChanged in interface javax.swing.event.TreeModelListener
      • handleTreeStructureChanged

        public void handleTreeStructureChanged​(javax.swing.event.TreeModelEvent event,
                                               javax.swing.tree.TreePath root,
                                               int i)
        Handle each node in the subtree. Wait for node to be expanded before continuing to inlcude subnodes.
      • handlePath

        protected IFuture handlePath​(javax.swing.tree.TreePath path)
        Check if an action (e.g. expand) has to be performed on the path.
      • isExpanded

        public boolean isExpanded​(javax.swing.tree.TreePath path)
        Test if a path is expanded or should be.
      • isTreeExpanded

        public static boolean isTreeExpanded​(javax.swing.JTree tree,
                                             javax.swing.tree.TreePath path)
        Test if a tree node is expanded or should be.