csli.util.swing.jtree
Class MaintainTreeExpansionListener

java.lang.Object
  extended by csli.util.swing.jtree.MaintainTreeExpansionListener
All Implemented Interfaces:
EventListener, TreeExpansionListener, TreeModelListener

public class MaintainTreeExpansionListener
extends Object
implements TreeModelListener, TreeExpansionListener

This is a combination TreeModelListener and TreeExpansionListener, which when properly added to a JTree / TreeModel will be able to maintain what is expanded / collapsed through any calls to nodeStructureChanged(). This code shows an example of adding this to a JTree / TreeModel combo. MaintainTreeExpansionListener listener = new MaintainTreeExpansionListener(m_tree); m_tree.addTreeExpansionListener(listener); treeModel.addTreeModelListener(listener); m_tree.setModel(treeModel); I think the main reason this class is useful is because calling nodeStructureChanged(root) and passing in the root is often more convenient than calculating all the changes and calling the other event functions in the TreeModel class. However, calling that on the root seems to collapse everything, which makes using a JTree that does this a lot rather unfriendly.

Author:
Karl Schultz

Constructor Summary
MaintainTreeExpansionListener(JTree tree)
          Basic constructor, needs the JTree that it will both be a TreeExpansionListener on, as well as being the TreeModelListener for that JTree's TreeModel.
 
Method Summary
 void treeCollapsed(TreeExpansionEvent event)
          Record the node that was collapsed by removing it from the HashSet.
 void treeExpanded(TreeExpansionEvent event)
          Record the node that was expanded by adding it to the HashSet.
 void treeNodesChanged(TreeModelEvent e)
          Un-used at the moment.
 void treeNodesInserted(TreeModelEvent e)
          Un-used at the moment.
 void treeNodesRemoved(TreeModelEvent e)
          Record any nodes that were deleted by removing them from the HashSet.
 void treeStructureChanged(TreeModelEvent e)
          This is the main function that we need to re-expand everything for when called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MaintainTreeExpansionListener

public MaintainTreeExpansionListener(JTree tree)
Basic constructor, needs the JTree that it will both be a TreeExpansionListener on, as well as being the TreeModelListener for that JTree's TreeModel.

Parameters:
tree -
Method Detail

treeExpanded

public void treeExpanded(TreeExpansionEvent event)
Record the node that was expanded by adding it to the HashSet.

Specified by:
treeExpanded in interface TreeExpansionListener

treeCollapsed

public void treeCollapsed(TreeExpansionEvent event)
Record the node that was collapsed by removing it from the HashSet.

Specified by:
treeCollapsed in interface TreeExpansionListener

treeNodesChanged

public void treeNodesChanged(TreeModelEvent e)
Un-used at the moment.

Specified by:
treeNodesChanged in interface TreeModelListener

treeNodesInserted

public void treeNodesInserted(TreeModelEvent e)
Un-used at the moment.

Specified by:
treeNodesInserted in interface TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(TreeModelEvent e)
Record any nodes that were deleted by removing them from the HashSet.

Specified by:
treeNodesRemoved in interface TreeModelListener

treeStructureChanged

public void treeStructureChanged(TreeModelEvent e)
This is the main function that we need to re-expand everything for when called.

Specified by:
treeStructureChanged in interface TreeModelListener