summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLillian Angel <langel@redhat.com>2005-11-14 20:40:39 +0000
committerLillian Angel <langel@redhat.com>2005-11-14 20:40:39 +0000
commiteeb751391d053f07ceb0be04c9527723d710fe59 (patch)
tree8bde5066c04bdebb8a35dc6b91506b2d5115a14a
parent27499fde3c71a83b34b6a3246e86f528f1194020 (diff)
downloadclasspath-eeb751391d053f07ceb0be04c9527723d710fe59.tar.gz
2005-11-14 Lillian Angel <langel@redhat.com>
* javax/swing/JTree.java (expandPath): No need to get the parent path. * javax/swing/event/TreeModelEvent.java: Variables should be initialized to null. (toString): Implemented. * javax/swing/plaf/basic/BasicTreeUI.java (treeStructureChanged): Implemented. (getParent): Added check to avoid infinite loop. (findNode): Fixed check to use getChild, instead of getIndexOfChild. (updateCurrentVisiblePath): Added a loop to check the parent's sibling, if the current node has no other siblings.
-rw-r--r--ChangeLog16
-rw-r--r--javax/swing/JTree.java5
-rw-r--r--javax/swing/event/TreeModelEvent.java8
-rw-r--r--javax/swing/plaf/basic/BasicTreeUI.java70
4 files changed, 67 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a20ca247..3bb9c025e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-11-14 Lillian Angel <langel@redhat.com>
+
+ * javax/swing/JTree.java
+ (expandPath): No need to get the parent path.
+ * javax/swing/event/TreeModelEvent.java:
+ Variables should be initialized to null.
+ (toString): Implemented.
+ * javax/swing/plaf/basic/BasicTreeUI.java
+ (treeStructureChanged): Implemented.
+ (getParent): Added check to avoid infinite loop.
+ (findNode): Fixed check to use getChild, instead of
+ getIndexOfChild.
+ (updateCurrentVisiblePath): Added a loop to check
+ the parent's sibling, if the current node has no
+ other siblings.
+
2005-11-14 Anthony Balkissoon <abalkiss@redhat.com>
* javax/swing/ActionMap.java:
diff --git a/javax/swing/JTree.java b/javax/swing/JTree.java
index a33ffba05..4422a1933 100644
--- a/javax/swing/JTree.java
+++ b/javax/swing/JTree.java
@@ -2589,7 +2589,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (!isExpanded(parent) && parent != null)
doExpandParents(parent, false);
-
+
nodeStates.put(path, state ? EXPANDED : COLLAPSED);
}
@@ -2597,7 +2597,6 @@ public class JTree extends JComponent implements Scrollable, Accessible
{
if (path == null)
return;
- TreePath parent = path.getParentPath();
doExpandParents(path, state);
}
@@ -2651,7 +2650,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
{
if (path == null)
return;
-
+
expandPath(path.getParentPath());
}
diff --git a/javax/swing/event/TreeModelEvent.java b/javax/swing/event/TreeModelEvent.java
index a217e3b40..8fa28a7ea 100644
--- a/javax/swing/event/TreeModelEvent.java
+++ b/javax/swing/event/TreeModelEvent.java
@@ -55,12 +55,12 @@ public class TreeModelEvent extends EventObject {
/**
* childIndices
*/
- protected int[] childIndices = new int[0];
+ protected int[] childIndices = null;
/**
* children
*/
- protected Object[] children = new Object[0];
+ protected Object[] children = null;
/**
* path
@@ -164,7 +164,9 @@ public class TreeModelEvent extends EventObject {
* @returns String representation
*/
public String toString() {
- return null; // TODO
+ return getClass() + " [Source: " + getSource() + ", TreePath: " + getTreePath() +
+ ", Child Indicies: " + getChildIndices() + ", Children: " + getChildren() +
+ ", Path: " + getPath() +"]";
} // toString()
diff --git a/javax/swing/plaf/basic/BasicTreeUI.java b/javax/swing/plaf/basic/BasicTreeUI.java
index d356f2647..e967cd424 100644
--- a/javax/swing/plaf/basic/BasicTreeUI.java
+++ b/javax/swing/plaf/basic/BasicTreeUI.java
@@ -634,7 +634,6 @@ public class BasicTreeUI extends TreeUI
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
root = getNextNode(root);
-
Point loc = getCellLocation(0, 0, tree, treeModel, cell, root);
return getCellBounds(loc.x, loc.y, cell);
}
@@ -723,9 +722,6 @@ public class BasicTreeUI extends TreeUI
*/
public TreePath getClosestPathForLocation(JTree tree, int x, int y)
{
- // FIXME: what if root is hidden? should not depend on (0,0)
- // should start counting rows from where root is.
-
int row = Math.round(y / getRowHeight());
TreePath path = getPathForRow(tree, row);
@@ -1183,8 +1179,7 @@ public class BasicTreeUI extends TreeUI
for (int i = 0; i < path.length; i++)
{
TreePath curr = new TreePath(getPathToRoot(path[i], 0));
- Rectangle bounds = getPathBounds(tree, curr);
-
+ Rectangle bounds = getPathBounds(tree, curr);
if (treeModel != null)
isLeaf = treeModel.isLeaf(path[i]);
if (!isLeaf && hasControlIcons())
@@ -2870,8 +2865,11 @@ public class BasicTreeUI extends TreeUI
*/
public void treeStructureChanged(TreeModelEvent e)
{
- validCachedPreferredSize = false;
+ if (e.getPath().length == 1
+ && !e.getPath()[0].equals(treeModel.getRoot()))
+ tree.expandPath(new TreePath(treeModel.getRoot()));
updateCurrentVisiblePath();
+ validCachedPreferredSize = false;
tree.revalidate();
tree.repaint();
}
@@ -3330,8 +3328,10 @@ public class BasicTreeUI extends TreeUI
*/
Object getParent(Object root, Object node)
{
- if (root == null || node == null)
+ if (root == null || node == null ||
+ root.equals(node))
return null;
+
if (node instanceof TreeNode)
return ((TreeNode) node).getParent();
return findNode(root, node);
@@ -3348,21 +3348,23 @@ public class BasicTreeUI extends TreeUI
*/
private Object findNode(Object root, Object node)
{
- int size = 0;
- if (!treeModel.isLeaf(root))
- size = treeModel.getChildCount(root);
- for (int i = 0; i < size; i++)
+ if (!treeModel.isLeaf(root) && !root.equals(node))
{
- if (treeModel.getIndexOfChild(root, node) != -1)
- return root;
+ int size = treeModel.getChildCount(root);
+ for (int j = 0; j < size; j++)
+ {
+ Object child = treeModel.getChild(root, j);
+ if (node.equals(child))
+ return root;
- Object n = findNode(treeModel.getChild(root, i), node);
- if (n != null)
- return n;
+ Object n = findNode(child, node);
+ if (n != null)
+ return n;
+ }
}
return null;
}
-
+
/**
* Get previous visible node in the tree. Package private for use in inner
* classes.
@@ -3402,14 +3404,13 @@ public class BasicTreeUI extends TreeUI
Object node = curr;
Object sibling = null;
-
do
{
sibling = getNextSibling(node);
node = getParent(treeModel.getRoot(), node);
}
while (sibling == null && node != null);
-
+
return sibling;
}
@@ -3471,7 +3472,7 @@ public class BasicTreeUI extends TreeUI
return treeModel.getChild(parent, index);
}
-
+
/**
* Returns the previous sibling in the tree Package private for use in inner
* classes.
@@ -3567,6 +3568,7 @@ public class BasicTreeUI extends TreeUI
int getLevel(Object node)
{
int count = -1;
+
Object current = node;
do
@@ -3575,7 +3577,7 @@ public class BasicTreeUI extends TreeUI
count++;
}
while (current != null);
-
+
return count;
}
@@ -3832,6 +3834,7 @@ public class BasicTreeUI extends TreeUI
&& tree.isExpanded(new TreePath(next))))
next = getNextNode(next);
+ Object root = next;
TreePath current = null;
while (next != null)
{
@@ -3842,13 +3845,28 @@ public class BasicTreeUI extends TreeUI
do
{
TreePath path = new TreePath(getPathToRoot(next, 0));
- if ((tree.isVisible(path) && tree.isExpanded(path)) ||
- treeModel.isLeaf(next))
+ if ((tree.isVisible(path) && tree.isExpanded(path))
+ || treeModel.isLeaf(next))
next = getNextNode(next);
else
- next = getNextSibling(next);
+ {
+ Object pNext = next;
+ next = getNextSibling(pNext);
+ // if no next sibling, check parent's next sibling.
+ if (next == null)
+ {
+ Object parent = getParent(root, pNext);
+ while (next == null && parent != null)
+ {
+ next = getNextSibling(parent);
+ if (next == null)
+ parent = getParent(treeModel.getRoot(), next);
+ }
+ }
+ }
}
- while (next != null && !tree.isVisible(new TreePath(getPathToRoot(next, 0))));
+ while (next != null &&
+ !tree.isVisible(new TreePath(getPathToRoot(next, 0))));
}
currentVisiblePath = current;