[Jarspy-commits] CVS: JarSpy/src/com/ociweb/jarspy/gui/tree JarSpyClassTree.java,1.3,1.4
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2003-01-28 03:07:31
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/tree
In directory sc8-pr-cvs1:/tmp/cvs-serv30452
Modified Files:
JarSpyClassTree.java
Log Message:
added methods to expand and collapse tree
Index: JarSpyClassTree.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/tree/JarSpyClassTree.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JarSpyClassTree.java 25 Jan 2003 23:24:32 -0000 1.3
--- JarSpyClassTree.java 28 Jan 2003 03:07:29 -0000 1.4
***************
*** 24,31 ****
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
!
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;
! import java.io.File;
/**
--- 24,33 ----
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
! import java.io.File;
! import java.util.Enumeration;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;
! import javax.swing.tree.TreeNode;
! import javax.swing.tree.TreePath;
/**
***************
*** 40,43 ****
--- 42,46 ----
inspector.addJarInspectorListener(this);
setModel(new JarSpyTreeModel());
+ super.setShowsRootHandles(true);
}
***************
*** 62,66 ****
/**
* Notify listener that a JarInspector has been updated
! * @param inspector the JarInspector which has been updated
*/
public void jarInspectorUpdated(JarInspector jarInspector) {
--- 65,69 ----
/**
* Notify listener that a JarInspector has been updated
! * @param jarInspector the JarInspector which has been updated
*/
public void jarInspectorUpdated(JarInspector jarInspector) {
***************
*** 81,84 ****
--- 84,123 ----
if (jarFile == null) {
setModel(new JarSpyTreeModel());
+ }
+ }
+
+ public void expandAll() {
+ expandAll(true);
+ }
+
+ public void collapseAll() {
+ expandAll(false);
+ }
+
+ // If expand is true, expands all nodes in the tree.
+ // Otherwise, collapses all nodes in the tree.
+ private void expandAll(boolean expand) {
+ TreeNode root = (TreeNode) getModel().getRoot();
+
+ // Traverse tree from root
+ expandAll(new TreePath(root), expand);
+ }
+
+ private void expandAll(TreePath parent, boolean expand) {
+ // Traverse children
+ TreeNode node = (TreeNode) parent.getLastPathComponent();
+ if (node.getChildCount() >= 0) {
+ for (Enumeration e = node.children(); e.hasMoreElements();) {
+ TreeNode n = (TreeNode) e.nextElement();
+ TreePath path = parent.pathByAddingChild(n);
+ expandAll(path, expand);
+ }
+ }
+
+ // Expansion or collapse must be done bottom-up
+ if (expand) {
+ expandPath(parent);
+ } else {
+ collapsePath(parent);
}
}
|