Took out redundant code in BasicTreeUI and placed in JTree. This works
better for expanding/collapsing a path. The events are automatically
fired from the source and do not need to be fired every time expandPath
or collapsePath is called from another class.

2005-08-15  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/JTree.java
        (expandPath): called fireTreeWillExpand and fireTreeExpanded
        since it is not required that the calling class fires these
        events.
        (collapsePath): Likewise.
        * javax/swing/plaf/basic/BasicTreeUI.java
        (mouseClicked): Took out code that called fireTreeWillExpand/
        fireTreeWillCollapse and fireTreeExpanded/fireTreeCollapsed.
        (keyPressed): Likewise.

Index: javax/swing/JTree.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.33
diff -u -r1.33 JTree.java
--- javax/swing/JTree.java	10 Aug 2005 17:46:17 -0000	1.33
+++ javax/swing/JTree.java	15 Aug 2005 18:24:41 -0000
@@ -1277,9 +1277,17 @@
 	}
 
 	public void collapsePath(TreePath path)
-	{
-		setExpandedState(path, false);
-	}
+    {
+      try
+        {
+          fireTreeWillCollapse(path);
+        }
+      catch (ExpandVetoException ev)
+        {
+        }
+      setExpandedState(path, false);
+      fireTreeCollapsed(path);
+    }
 
 	public void collapseRow(int row)
 	{
@@ -1293,13 +1301,22 @@
 	}
 
 	public void expandPath(TreePath path)
-	{
-		// Don't expand if last path component is a leaf node.
-		if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent())))
-			return;
-
-		setExpandedState(path, true);
-	}
+    {
+      // Don't expand if last path component is a leaf node.
+      if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent())))
+        return;
+  
+      try
+        {
+          fireTreeWillExpand(path);
+        }
+      catch (ExpandVetoException ev)
+        {
+        }
+  
+      setExpandedState(path, true);
+      fireTreeExpanded(path);
+    }
 
 	public void expandRow(int row)
 	{
@@ -1506,13 +1523,8 @@
 	private void doExpandParents(TreePath path, boolean state)
 	{
 		TreePath parent = path.getParentPath();		
-		if (isExpanded(parent))
-		{
-			nodeStates.put(path, state ? EXPANDED : COLLAPSED);
-			return;
-		}
-
-		if (parent != null)
+        
+		if (!isExpanded(parent) && parent != null)
 			doExpandParents(parent, false);
 
 		nodeStates.put(path, state ? EXPANDED : COLLAPSED);
@@ -1522,7 +1534,6 @@
 	{
 		if (path == null)
 			return;
-
 		TreePath parent = path.getParentPath();
 
 		doExpandParents(path, state);
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.60
diff -u -r1.60 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	12 Aug 2005 17:56:48 -0000	1.60
+++ javax/swing/plaf/basic/BasicTreeUI.java	15 Aug 2005 18:24:42 -0000
@@ -1733,17 +1733,7 @@
                   if (e.isControlDown())
                     tree.setLeadSelectionPath(newPath);
                   else if (!mod.isLeaf(next) && e.isShiftDown())
-                    {
-                      BasicTreeUI.this.tree.expandPath(newPath);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeExpanded(newPath);
-                    }
+                    BasicTreeUI.this.tree.expandPath(newPath);
                 }
             }
           // UP, KP_UP
@@ -1761,17 +1751,7 @@
                   if (e.isControlDown())
                     tree.setLeadSelectionPath(newPath);
                   else if (!mod.isLeaf(prev) && e.isShiftDown())
-                    {
-                      BasicTreeUI.this.tree.expandPath(newPath);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeExpanded(newPath);
-                    }
+                    BasicTreeUI.this.tree.expandPath(newPath);
                 }
             }
           // LEFT, KP_LEFT
@@ -1782,17 +1762,7 @@
               Object p = getParent(mod.getRoot(), last);
 
               if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isExpanded(path))
-                {
-                  BasicTreeUI.this.tree.collapsePath(path);
-                  try
-                    {
-                      BasicTreeUI.this.tree.fireTreeWillCollapse(path);
-                    }
-                  catch (ExpandVetoException ev)
-                    {
-                    }
-                  BasicTreeUI.this.tree.fireTreeCollapsed(path);
-                }
+                BasicTreeUI.this.tree.collapsePath(path);
               else if (p != null)
                 BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,
                                             new TreePath(getPathToRoot(p, 0)));
@@ -1804,17 +1774,7 @@
               TreePath path = new TreePath(getPathToRoot(last, 0));
 
               if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isCollapsed(path))
-                {
-                  BasicTreeUI.this.tree.expandPath(path);
-                  try
-                    {
-                      BasicTreeUI.this.tree.fireTreeWillExpand(path);
-                    }
-                  catch (ExpandVetoException ev)
-                    {
-                    }
-                  BasicTreeUI.this.tree.fireTreeExpanded(path);
-                }
+                BasicTreeUI.this.tree.expandPath(path);
               else
                 {
                   Object next = BasicTreeUI.this.getNextVisibleNode(last);
@@ -1835,29 +1795,9 @@
               if (!mod.isLeaf(last))
                 {
                   if (BasicTreeUI.this.tree.isExpanded(path))
-                    {
-                      BasicTreeUI.this.tree.collapsePath(path);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillCollapse(path);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeCollapsed(path);
-                    }
+                    BasicTreeUI.this.tree.collapsePath(path);
                   else
-                    {
-                      BasicTreeUI.this.tree.expandPath(path);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillExpand(path);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeExpanded(path);
-                    }
+                    BasicTreeUI.this.tree.expandPath(path);
                 }
             }
         }
@@ -2013,29 +1953,9 @@
                   lastClicked = null;
                   BasicTreeUI.this.tree.getSelectionModel().clearSelection();
                   if (BasicTreeUI.this.tree.isExpanded(path))
-                    {
-                      BasicTreeUI.this.tree.collapsePath(path);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillCollapse(path);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeCollapsed(path);
-                    }
+                    BasicTreeUI.this.tree.collapsePath(path);
                   else
-                    {
-                      BasicTreeUI.this.tree.expandPath(path);
-                      try
-                        {
-                          BasicTreeUI.this.tree.fireTreeWillExpand(path);
-                        }
-                      catch (ExpandVetoException ev)
-                        {
-                        }
-                      BasicTreeUI.this.tree.fireTreeExpanded(path);
-                    }
+                    BasicTreeUI.this.tree.expandPath(path);
                 }
 
               BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path);
@@ -2620,7 +2540,7 @@
       }
 
     if (!mod.isLeaf(startNode)
-        && tree.isExpanded(new TreePath(getPathToRoot(startNode, 0))) 
+        && tree.isExpanded(new TreePath(getPathToRoot(startNode, 0)))
         && mod.getChildCount(startNode) > 0)
       {
         Object child = mod.getChild(startNode, 0);
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to