700 |
*/ |
*/ |
701 |
public int getRowCount(JTree tree) |
public int getRowCount(JTree tree) |
702 |
{ |
{ |
703 |
|
updateCurrentVisiblePath(); |
704 |
if (currentVisiblePath != null) |
if (currentVisiblePath != null) |
705 |
return currentVisiblePath.getPathCount(); |
return currentVisiblePath.getPathCount(); |
706 |
return 0; |
return 0; |
1414 |
if (currentVisiblePath == null) |
if (currentVisiblePath == null) |
1415 |
updateCurrentVisiblePath(); |
updateCurrentVisiblePath(); |
1416 |
|
|
1417 |
if (treeModel != null) |
if (currentVisiblePath != null && treeModel != null) |
1418 |
{ |
{ |
1419 |
Object root = treeModel.getRoot(); |
Object root = treeModel.getRoot(); |
1420 |
paintRecursive(g, 0, 0, 0, tree, treeModel, root); |
paintRecursive(g, 0, 0, 0, tree, treeModel, root); |
2511 |
*/ |
*/ |
2512 |
public void propertyChange(PropertyChangeEvent event) |
public void propertyChange(PropertyChangeEvent event) |
2513 |
{ |
{ |
2514 |
// TODO: What should be done here, if anything? |
if ((event.getPropertyName()).equals("rootVisible")) |
2515 |
|
{ |
2516 |
|
validCachedPreferredSize = false; |
2517 |
|
updateCurrentVisiblePath(); |
2518 |
|
tree.revalidate(); |
2519 |
|
tree.repaint(); |
2520 |
|
} |
2521 |
} |
} |
2522 |
} |
} |
2523 |
|
|
2716 |
if (e.getActionCommand().equals("selectPreviousChangeLead")) |
if (e.getActionCommand().equals("selectPreviousChangeLead")) |
2717 |
{ |
{ |
2718 |
Object prev = getPreviousVisibleNode(last); |
Object prev = getPreviousVisibleNode(last); |
2719 |
|
|
2720 |
if (prev != null) |
if (prev != null) |
2721 |
{ |
{ |
2722 |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
2737 |
else if (e.getActionCommand().equals("selectPrevious")) |
else if (e.getActionCommand().equals("selectPrevious")) |
2738 |
{ |
{ |
2739 |
Object prev = getPreviousVisibleNode(last); |
Object prev = getPreviousVisibleNode(last); |
2740 |
|
|
2741 |
if (prev != null) |
if (prev != null) |
2742 |
{ |
{ |
2743 |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
2747 |
else if (e.getActionCommand().equals("selectNext")) |
else if (e.getActionCommand().equals("selectNext")) |
2748 |
{ |
{ |
2749 |
Object next = getNextVisibleNode(last); |
Object next = getNextVisibleNode(last); |
2750 |
|
|
2751 |
if (next != null) |
if (next != null) |
2752 |
{ |
{ |
2753 |
TreePath newPath = new TreePath(getPathToRoot(next, 0)); |
TreePath newPath = new TreePath(getPathToRoot(next, 0)); |
3159 |
boolean isLeaf = mod.isLeaf(curr); |
boolean isLeaf = mod.isLeaf(curr); |
3160 |
Rectangle bounds = getPathBounds(tree, path); |
Rectangle bounds = getPathBounds(tree, path); |
3161 |
Object root = mod.getRoot(); |
Object root = mod.getRoot(); |
3162 |
|
|
3163 |
if (isLeaf) |
if (isLeaf) |
3164 |
{ |
{ |
3165 |
paintRow(g, clip, null, bounds, path, row, true, false, true); |
paintRow(g, clip, null, bounds, path, row, true, false, true); |
3179 |
int max = mod.getChildCount(curr); |
int max = mod.getChildCount(curr); |
3180 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
3181 |
{ |
{ |
3182 |
|
Object child = mod.getChild(curr, i); |
3183 |
|
boolean childVis = tree.isVisible(new TreePath |
3184 |
|
(getPathToRoot(child, 0))); |
3185 |
int indent = indentation + rightChildIndent; |
int indent = indentation + rightChildIndent; |
3186 |
if (!isRootVisible && depth == 0) |
if (!isRootVisible && depth == 0) |
3187 |
indent = 0; |
indent = 0; |
3188 |
else if (isRootVisible || |
else if (isRootVisible || |
3189 |
(!isRootVisible && !curr.equals(root))) |
(!isRootVisible && !curr.equals(root)) && childVis) |
3190 |
{ |
{ |
3191 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
3192 |
heightOfLine = descent + halfHeight; |
heightOfLine = descent + halfHeight; |
3195 |
} |
} |
3196 |
|
|
3197 |
descent = paintRecursive(g, indent, descent, depth + 1, |
descent = paintRecursive(g, indent, descent, depth + 1, |
3198 |
tree, mod, mod.getChild(curr, i)); |
tree, mod, child); |
3199 |
} |
} |
3200 |
} |
} |
3201 |
} |
} |
3202 |
|
|
3203 |
if (isExpanded) |
if (isExpanded) |
3204 |
if (y0 != heightOfLine && !isLeaf |
if (y0 != heightOfLine |
3205 |
&& mod.getChildCount(curr) > 0) |
&& (mod.getChildCount(curr) > 0 && |
3206 |
|
tree.isVisible(new TreePath(getPathToRoot(mod.getChild |
3207 |
|
(curr, 0), 0))))) |
3208 |
{ |
{ |
3209 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
3210 |
paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, |
paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, y0, |
3211 |
y0, heightOfLine); |
heightOfLine); |
3212 |
} |
} |
|
|
|
3213 |
return descent; |
return descent; |
3214 |
} |
} |
3215 |
|
|
3279 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
3280 |
{ |
{ |
3281 |
int indent = indentation + rightChildIndent; |
int indent = indentation + rightChildIndent; |
3282 |
|
Object child = mod.getChild(node, i); |
3283 |
if (depth == 0 && !tree.isRootVisible()) |
if (depth == 0 && !tree.isRootVisible()) |
3284 |
indent = 1; |
indent = 1; |
3285 |
|
if (tree.isVisible(new TreePath(getPathToRoot(child, 0)))) |
3286 |
descent = paintControlIcons(g, indent, descent, depth + 1, |
descent = paintControlIcons(g, indent, descent, depth + 1, |
3287 |
tree, mod, mod.getChild(node, i)); |
tree, mod, child); |
3288 |
} |
} |
3289 |
} |
} |
3290 |
} |
} |
3373 |
*/ |
*/ |
3374 |
Object getPreviousVisibleNode(Object node) |
Object getPreviousVisibleNode(Object node) |
3375 |
{ |
{ |
3376 |
|
updateCurrentVisiblePath(); |
3377 |
if (currentVisiblePath != null) |
if (currentVisiblePath != null) |
3378 |
{ |
{ |
3379 |
Object[] nodes = currentVisiblePath.getPath(); |
Object[] nodes = currentVisiblePath.getPath(); |
3381 |
while (i < nodes.length && !node.equals(nodes[i])) |
while (i < nodes.length && !node.equals(nodes[i])) |
3382 |
i++; |
i++; |
3383 |
// return the next node |
// return the next node |
3384 |
if (i-1 > 0) |
if (i-1 >= 0) |
3385 |
return nodes[i-1]; |
return nodes[i-1]; |
3386 |
} |
} |
3387 |
return null; |
return null; |
3775 |
dtcr = createDefaultCellRenderer(); |
dtcr = createDefaultCellRenderer(); |
3776 |
|
|
3777 |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
3778 |
selected, isExpanded, isLeaf, row, false); |
selected, isExpanded, isLeaf, row, true); |
3779 |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
3780 |
} |
} |
3781 |
} |
} |
3822 |
|
|
3823 |
Object next = treeModel.getRoot(); |
Object next = treeModel.getRoot(); |
3824 |
Rectangle bounds = getCellBounds(0, 0, next); |
Rectangle bounds = getCellBounds(0, 0, next); |
3825 |
|
boolean rootVisible = isRootVisible(); |
3826 |
|
|
3827 |
// If root is not a valid size to be visible, or is |
// If root is not a valid size to be visible, or is |
3828 |
// not visible and the tree is expanded, then the next node acts |
// not visible and the tree is expanded, then the next node acts |
3829 |
// as the root |
// as the root |
3830 |
if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible() |
if ((bounds.width == 0 && bounds.height == 0) || (!rootVisible |
3831 |
&& tree.isExpanded(new TreePath(next)))) |
&& tree.isExpanded(new TreePath(next)))) |
3832 |
next = getNextNode(next); |
next = getNextNode(next); |
3833 |
|
|
3841 |
do |
do |
3842 |
{ |
{ |
3843 |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
3844 |
if (tree.isVisible(path) && tree.isExpanded(path)) |
if ((tree.isVisible(path) && tree.isExpanded(path)) || |
3845 |
|
treeModel.isLeaf(next)) |
3846 |
next = getNextNode(next); |
next = getNextNode(next); |
3847 |
else next = getNextSibling(next); |
else |
3848 |
|
next = getNextSibling(next); |
3849 |
} |
} |
3850 |
while (next != null && !tree.isVisible(new TreePath(getPathToRoot(next, 0)))); |
while (next != null && !tree.isVisible(new TreePath(getPathToRoot(next, 0)))); |
3851 |
} |
} |
3852 |
currentVisiblePath = current; |
currentVisiblePath = current; |
3853 |
tree.setVisibleRowCount(getRowCount(tree)); |
if (currentVisiblePath != null) |
3854 |
|
tree.setVisibleRowCount(currentVisiblePath.getPathCount()); |
3855 |
|
else |
3856 |
|
tree.setVisibleRowCount(0); |
3857 |
|
|
3858 |
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && |
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && |
3859 |
currentVisiblePath != null) |
currentVisiblePath != null) |
3860 |
tree.addSelectionRow(0); |
selectPath(tree, new TreePath(currentVisiblePath.getPathComponent(0))); |
3861 |
} |
} |
3862 |
|
|
3863 |
/** |
/** |