[Patch][gui] javax.swing.JTree
Michael Koch
konqueror@gmx.de
Tue Dec 14 20:43:00 GMT 2004
Hi list,
I just commited the attached patch to add most of the missing methods of
javax.swing.JTree.
Michael
2004-12-14 Michael Koch <konqueror@gmx.de>
* javax/swing/JTree.java
(collapsePath): New method.
(collapseRow): Likewise.
(expandPath): Likewise.
(expandRow): Likewise.
(checkExpandParents): Likewise.
(doExpandParents): Likewise.
(setExpandedState): Likewise.
(makeVisible): Likewise.
-------------- next part --------------
Index: javax/swing/JTree.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTree.java,v
retrieving revision 1.3.2.12
diff -u -r1.3.2.12 JTree.java
--- javax/swing/JTree.java 1 Dec 2004 13:45:53 -0000 1.3.2.12
+++ javax/swing/JTree.java 14 Dec 2004 07:30:01 -0000
@@ -1051,6 +1051,43 @@
return 0;
}
+
+ public void collapsePath(TreePath path)
+ {
+ setExpandedState(path, false);
+ }
+
+ public void collapseRow(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ collapsePath(path);
+ }
+
+ 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);
+ }
+
+ public void expandRow(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ expandPath(path);
+ }
public boolean isCollapsed(TreePath path)
{
@@ -1243,6 +1280,51 @@
return null;
}
+ private void checkExpandParents(TreePath path)
+ throws ExpandVetoException
+ {
+ TreePath parent = path.getParentPath();
+
+ if (parent != null)
+ checkExpandParents(parent);
+
+ fireTreeWillExpand(path);
+ }
+
+ private void doExpandParents(TreePath path, boolean state)
+ {
+ TreePath parent = path.getParentPath();
+
+ if (isExpanded(parent))
+ return;
+
+ if (parent != null)
+ doExpandParents(parent, false);
+
+ nodeStates.put(path, state ? EXPANDED : COLLAPSED);
+ }
+
+ protected void setExpandedState(TreePath path, boolean state)
+ {
+ if (path == null)
+ return;
+
+ TreePath parent = path.getParentPath();
+
+ try
+ {
+ while (parent != null)
+ checkExpandParents(parent);
+ }
+ catch (ExpandVetoException e)
+ {
+ // Expansion vetoed.
+ return;
+ }
+
+ doExpandParents(path, state);
+ }
+
protected void clearToggledPaths()
{
nodeStates.clear();
@@ -1288,6 +1370,14 @@
return isExpanded(parent);
}
+ public void makeVisible(TreePath path)
+ {
+ if (path == null)
+ return;
+
+ expandPath(path.getParentPath());
+ }
+
public boolean isPathEditable(TreePath path)
{
return isEditable();
More information about the Java-patches
mailing list