634 |
|
|
635 |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
636 |
root = getNextNode(root); |
root = getNextNode(root); |
|
|
|
637 |
Point loc = getCellLocation(0, 0, tree, treeModel, cell, root); |
Point loc = getCellLocation(0, 0, tree, treeModel, cell, root); |
638 |
return getCellBounds(loc.x, loc.y, cell); |
return getCellBounds(loc.x, loc.y, cell); |
639 |
} |
} |
722 |
*/ |
*/ |
723 |
public TreePath getClosestPathForLocation(JTree tree, int x, int y) |
public TreePath getClosestPathForLocation(JTree tree, int x, int y) |
724 |
{ |
{ |
|
// FIXME: what if root is hidden? should not depend on (0,0) |
|
|
// should start counting rows from where root is. |
|
|
|
|
725 |
int row = Math.round(y / getRowHeight()); |
int row = Math.round(y / getRowHeight()); |
726 |
TreePath path = getPathForRow(tree, row); |
TreePath path = getPathForRow(tree, row); |
727 |
|
|
1179 |
for (int i = 0; i < path.length; i++) |
for (int i = 0; i < path.length; i++) |
1180 |
{ |
{ |
1181 |
TreePath curr = new TreePath(getPathToRoot(path[i], 0)); |
TreePath curr = new TreePath(getPathToRoot(path[i], 0)); |
1182 |
Rectangle bounds = getPathBounds(tree, curr); |
Rectangle bounds = getPathBounds(tree, curr); |
|
|
|
1183 |
if (treeModel != null) |
if (treeModel != null) |
1184 |
isLeaf = treeModel.isLeaf(path[i]); |
isLeaf = treeModel.isLeaf(path[i]); |
1185 |
if (!isLeaf && hasControlIcons()) |
if (!isLeaf && hasControlIcons()) |
2865 |
*/ |
*/ |
2866 |
public void treeStructureChanged(TreeModelEvent e) |
public void treeStructureChanged(TreeModelEvent e) |
2867 |
{ |
{ |
2868 |
validCachedPreferredSize = false; |
if (e.getPath().length == 1 |
2869 |
|
&& !e.getPath()[0].equals(treeModel.getRoot())) |
2870 |
|
tree.expandPath(new TreePath(treeModel.getRoot())); |
2871 |
updateCurrentVisiblePath(); |
updateCurrentVisiblePath(); |
2872 |
|
validCachedPreferredSize = false; |
2873 |
tree.revalidate(); |
tree.revalidate(); |
2874 |
tree.repaint(); |
tree.repaint(); |
2875 |
} |
} |
3328 |
*/ |
*/ |
3329 |
Object getParent(Object root, Object node) |
Object getParent(Object root, Object node) |
3330 |
{ |
{ |
3331 |
if (root == null || node == null) |
if (root == null || node == null || |
3332 |
|
root.equals(node)) |
3333 |
return null; |
return null; |
3334 |
|
|
3335 |
if (node instanceof TreeNode) |
if (node instanceof TreeNode) |
3336 |
return ((TreeNode) node).getParent(); |
return ((TreeNode) node).getParent(); |
3337 |
return findNode(root, node); |
return findNode(root, node); |
3348 |
*/ |
*/ |
3349 |
private Object findNode(Object root, Object node) |
private Object findNode(Object root, Object node) |
3350 |
{ |
{ |
3351 |
int size = 0; |
if (!treeModel.isLeaf(root) && !root.equals(node)) |
3352 |
if (!treeModel.isLeaf(root)) |
{ |
3353 |
size = treeModel.getChildCount(root); |
int size = treeModel.getChildCount(root); |
3354 |
for (int i = 0; i < size; i++) |
for (int j = 0; j < size; j++) |
3355 |
{ |
{ |
3356 |
if (treeModel.getIndexOfChild(root, node) != -1) |
Object child = treeModel.getChild(root, j); |
3357 |
return root; |
if (node.equals(child)) |
3358 |
|
return root; |
3359 |
Object n = findNode(treeModel.getChild(root, i), node); |
|
3360 |
if (n != null) |
Object n = findNode(child, node); |
3361 |
return n; |
if (n != null) |
3362 |
|
return n; |
3363 |
|
} |
3364 |
} |
} |
3365 |
return null; |
return null; |
3366 |
} |
} |
3367 |
|
|
3368 |
/** |
/** |
3369 |
* Get previous visible node in the tree. Package private for use in inner |
* Get previous visible node in the tree. Package private for use in inner |
3370 |
* classes. |
* classes. |
3404 |
|
|
3405 |
Object node = curr; |
Object node = curr; |
3406 |
Object sibling = null; |
Object sibling = null; |
|
|
|
3407 |
do |
do |
3408 |
{ |
{ |
3409 |
sibling = getNextSibling(node); |
sibling = getNextSibling(node); |
3410 |
node = getParent(treeModel.getRoot(), node); |
node = getParent(treeModel.getRoot(), node); |
3411 |
} |
} |
3412 |
while (sibling == null && node != null); |
while (sibling == null && node != null); |
3413 |
|
|
3414 |
return sibling; |
return sibling; |
3415 |
} |
} |
3416 |
|
|
3472 |
|
|
3473 |
return treeModel.getChild(parent, index); |
return treeModel.getChild(parent, index); |
3474 |
} |
} |
3475 |
|
|
3476 |
/** |
/** |
3477 |
* Returns the previous sibling in the tree Package private for use in inner |
* Returns the previous sibling in the tree Package private for use in inner |
3478 |
* classes. |
* classes. |
3568 |
int getLevel(Object node) |
int getLevel(Object node) |
3569 |
{ |
{ |
3570 |
int count = -1; |
int count = -1; |
3571 |
|
|
3572 |
Object current = node; |
Object current = node; |
3573 |
|
|
3574 |
do |
do |
3577 |
count++; |
count++; |
3578 |
} |
} |
3579 |
while (current != null); |
while (current != null); |
3580 |
|
|
3581 |
return count; |
return count; |
3582 |
} |
} |
3583 |
|
|
3834 |
&& tree.isExpanded(new TreePath(next)))) |
&& tree.isExpanded(new TreePath(next)))) |
3835 |
next = getNextNode(next); |
next = getNextNode(next); |
3836 |
|
|
3837 |
|
Object root = next; |
3838 |
TreePath current = null; |
TreePath current = null; |
3839 |
while (next != null) |
while (next != null) |
3840 |
{ |
{ |
3845 |
do |
do |
3846 |
{ |
{ |
3847 |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
3848 |
if ((tree.isVisible(path) && tree.isExpanded(path)) || |
if ((tree.isVisible(path) && tree.isExpanded(path)) |
3849 |
treeModel.isLeaf(next)) |
|| treeModel.isLeaf(next)) |
3850 |
next = getNextNode(next); |
next = getNextNode(next); |
3851 |
else |
else |
3852 |
next = getNextSibling(next); |
{ |
3853 |
|
Object pNext = next; |
3854 |
|
next = getNextSibling(pNext); |
3855 |
|
// if no next sibling, check parent's next sibling. |
3856 |
|
if (next == null) |
3857 |
|
{ |
3858 |
|
Object parent = getParent(root, pNext); |
3859 |
|
while (next == null && parent != null) |
3860 |
|
{ |
3861 |
|
next = getNextSibling(parent); |
3862 |
|
if (next == null) |
3863 |
|
parent = getParent(treeModel.getRoot(), next); |
3864 |
|
} |
3865 |
|
} |
3866 |
|
} |
3867 |
} |
} |
3868 |
while (next != null && !tree.isVisible(new TreePath(getPathToRoot(next, 0)))); |
while (next != null && |
3869 |
|
!tree.isVisible(new TreePath(getPathToRoot(next, 0)))); |
3870 |
} |
} |
3871 |
|
|
3872 |
currentVisiblePath = current; |
currentVisiblePath = current; |