242 |
|
|
243 |
/** The bounds of the current cell. */ |
/** The bounds of the current cell. */ |
244 |
Rectangle bounds; |
Rectangle bounds; |
245 |
|
|
246 |
|
/** The current path of the visible nodes in the tree. */ |
247 |
|
TreePath currentVisiblePath; |
248 |
|
|
249 |
/** Listeners */ |
/** Listeners */ |
250 |
private PropertyChangeListener propertyChangeListener; |
private PropertyChangeListener propertyChangeListener; |
651 |
{ |
{ |
652 |
if (treeModel != null) |
if (treeModel != null) |
653 |
{ |
{ |
654 |
Object node = treeModel.getRoot(); |
Object[] nodes = currentVisiblePath.getPath(); |
655 |
if (!tree.isRootVisible() |
if (row < nodes.length) |
656 |
&& tree.isExpanded(new TreePath(getPathToRoot(node, 0)))) |
return new TreePath(getPathToRoot(nodes[row], 0)); |
|
node = getNextNode(node); |
|
|
|
|
|
for (int i = 0; i < row; i++) |
|
|
node = getNextVisibleNode(node); |
|
|
|
|
|
if (node == null) |
|
|
return null; |
|
|
|
|
|
return new TreePath(getPathToRoot(node, 0)); |
|
657 |
} |
} |
658 |
return null; |
return null; |
659 |
} |
} |
674 |
{ |
{ |
675 |
int row = 0; |
int row = 0; |
676 |
Object dest = path.getLastPathComponent(); |
Object dest = path.getLastPathComponent(); |
677 |
Object curr = treeModel.getRoot(); |
int rowCount = getRowCount(tree); |
678 |
while (curr != null && !curr.equals(dest)) |
Object[] nodes = currentVisiblePath.getPath(); |
679 |
{ |
while (row < rowCount) |
680 |
++row; |
{ |
681 |
curr = getNextVisibleNode(curr); |
if (dest.equals(nodes[row])) |
682 |
|
return row; |
683 |
|
row++; |
684 |
} |
} |
685 |
return row; |
|
686 |
|
return -1; |
687 |
} |
} |
688 |
|
|
689 |
/** |
/** |
695 |
*/ |
*/ |
696 |
public int getRowCount(JTree tree) |
public int getRowCount(JTree tree) |
697 |
{ |
{ |
698 |
int count = 0; |
return currentVisiblePath.getPathCount(); |
|
if (treeModel != null) |
|
|
{ |
|
|
Object node = treeModel.getRoot(); |
|
|
if (!tree.isRootVisible() |
|
|
&& tree.isExpanded(new TreePath((getPathToRoot(node, 0))))) |
|
|
node = getNextNode(node); |
|
|
|
|
|
while (node != null) |
|
|
{ |
|
|
count++; |
|
|
node = getNextVisibleNode(node); |
|
|
} |
|
|
} |
|
|
return count; |
|
699 |
} |
} |
700 |
|
|
701 |
/** |
/** |
1070 |
protected void updateLayoutCacheExpandedNodes() |
protected void updateLayoutCacheExpandedNodes() |
1071 |
{ |
{ |
1072 |
if (treeModel != null) |
if (treeModel != null) |
1073 |
updateExpandedDescendants(new TreePath(getPathToRoot(treeModel. |
updateExpandedDescendants(new TreePath(treeModel.getRoot())); |
|
getRoot(), 0))); |
|
1074 |
} |
} |
1075 |
|
|
1076 |
/** |
/** |
1322 |
TreeModel mod = tree.getModel(); |
TreeModel mod = tree.getModel(); |
1323 |
setModel(mod); |
setModel(mod); |
1324 |
if (mod != null) |
if (mod != null) |
1325 |
tree.expandPath(new TreePath(mod.getRoot())); |
{ |
1326 |
|
TreePath path = new TreePath(mod.getRoot()); |
1327 |
|
if (!tree.isExpanded(path)) |
1328 |
|
toggleExpandState(path); |
1329 |
|
} |
1330 |
treeSelectionModel = tree.getSelectionModel(); |
treeSelectionModel = tree.getSelectionModel(); |
1331 |
|
|
1332 |
installKeyboardActions(); |
installKeyboardActions(); |
1380 |
public void paint(Graphics g, JComponent c) |
public void paint(Graphics g, JComponent c) |
1381 |
{ |
{ |
1382 |
JTree tree = (JTree) c; |
JTree tree = (JTree) c; |
|
|
|
1383 |
if (treeModel != null) |
if (treeModel != null) |
1384 |
{ |
{ |
1385 |
Object root = treeModel.getRoot(); |
Object root = treeModel.getRoot(); |
1386 |
|
paintRecursive(g, 0, 0, 0, tree, treeModel, root); |
1387 |
|
|
|
paintRecursive(g, 0, 0, 0, 0, tree, treeModel, root); |
|
|
|
|
1388 |
if (hasControlIcons()) |
if (hasControlIcons()) |
1389 |
paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root); |
paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root); |
1390 |
} |
} |
1466 |
{ |
{ |
1467 |
// FIXME: checkConsistancy not implemented, c not used |
// FIXME: checkConsistancy not implemented, c not used |
1468 |
int maxWidth = 0; |
int maxWidth = 0; |
1469 |
int count = 0; |
Object[] path = currentVisiblePath.getPath(); |
1470 |
if (treeModel != null) |
for (int i = 0; i < path.length; i++) |
1471 |
{ |
maxWidth = Math.max(maxWidth, |
1472 |
Object node = treeModel.getRoot(); |
(int) (getCellBounds(0, 0, path[i]).getWidth())); |
1473 |
if (node != null) |
return new Dimension(maxWidth, (getRowHeight() * path.length)); |
|
{ |
|
|
maxWidth = (int) (getCellBounds(0, 0, node).getWidth()); |
|
|
while (node != null) |
|
|
{ |
|
|
count++; |
|
|
Object nextNode = getNextVisibleNode(node); |
|
|
if (nextNode != null) |
|
|
maxWidth = Math.max(maxWidth, |
|
|
(int) (getCellBounds(0, 0, nextNode).getWidth())); |
|
|
node = nextNode; |
|
|
} |
|
|
} |
|
|
} |
|
|
return new Dimension(maxWidth, (getRowHeight() * count)); |
|
1474 |
} |
} |
1475 |
|
|
1476 |
/** |
/** |
1564 |
int y; |
int y; |
1565 |
if (event == null) |
if (event == null) |
1566 |
{ |
{ |
1567 |
Rectangle bounds = getPathBounds(tree, path); |
if (bounds == null) |
1568 |
|
bounds = getPathBounds(tree, path); |
1569 |
x = bounds.x; |
x = bounds.x; |
1570 |
y = bounds.y; |
y = bounds.y; |
1571 |
} |
} |
1645 |
{ |
{ |
1646 |
if (bounds == null) |
if (bounds == null) |
1647 |
bounds = getPathBounds(tree, path); |
bounds = getPathBounds(tree, path); |
|
if (tree.isExpanded(path) && expandedIcon != null) |
|
|
bounds.x -= expandedIcon.getIconWidth() - 4; |
|
|
else if (collapsedIcon != null) |
|
|
bounds.x -= collapsedIcon.getIconWidth() - 4; |
|
1648 |
|
|
1649 |
Icon controlIcon = getCurrentControlIcon(path); |
Icon controlIcon = getCurrentControlIcon(path); |
1650 |
if (controlIcon != null && (mouseX < bounds.x) |
if (controlIcon != null && (mouseX < bounds.x) |
1685 |
tree.collapsePath(path); |
tree.collapsePath(path); |
1686 |
else |
else |
1687 |
tree.expandPath(path); |
tree.expandPath(path); |
1688 |
|
updateCurrentVisiblePath(); |
1689 |
} |
} |
1690 |
|
|
1691 |
/** |
/** |
1820 |
(new TreeTraverseAction(0, "")).actionPerformed(e); |
(new TreeTraverseAction(0, "")).actionPerformed(e); |
1821 |
else if (e.getActionCommand().equals("selectAll")) |
else if (e.getActionCommand().equals("selectAll")) |
1822 |
{ |
{ |
1823 |
TreePath[] paths = new TreePath[tree.getRowCount()]; |
TreePath[] paths = new TreePath[tree.getVisibleRowCount()]; |
1824 |
|
|
1825 |
Object curr = getNextVisibleNode(treeModel.getRoot()); |
Object curr = getNextVisibleNode(treeModel.getRoot()); |
1826 |
int i = 0; |
int i = 0; |
2625 |
if (prev != null) |
if (prev != null) |
2626 |
{ |
{ |
2627 |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
2628 |
selectPath(tree, new TreePath(getPathToRoot(prev, 0))); |
selectPath(tree, newPath); |
2629 |
tree.setLeadSelectionPath(newPath); |
tree.setLeadSelectionPath(newPath); |
2630 |
} |
} |
2631 |
} |
} |
2645 |
if (prev != null) |
if (prev != null) |
2646 |
{ |
{ |
2647 |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
TreePath newPath = new TreePath(getPathToRoot(prev, 0)); |
2648 |
selectPath(tree, new TreePath(getPathToRoot(prev, 0))); |
selectPath(tree, newPath); |
2649 |
} |
} |
2650 |
} |
} |
2651 |
else if (e.getActionCommand().equals("selectNext")) |
else if (e.getActionCommand().equals("selectNext")) |
2912 |
TreePath path = new TreePath(getPathToRoot(last, 0)); |
TreePath path = new TreePath(getPathToRoot(last, 0)); |
2913 |
Object p = getParent(treeModel.getRoot(), last); |
Object p = getParent(treeModel.getRoot(), last); |
2914 |
|
|
2915 |
if (!treeModel.isLeaf(last) && tree.isExpanded(path)) |
if (!treeModel.isLeaf(last)) |
2916 |
tree.collapsePath(path); |
toggleExpandState(path); |
2917 |
else if (p != null) |
else if (p != null) |
2918 |
selectPath(tree, new TreePath(getPathToRoot(p, 0))); |
selectPath(tree, new TreePath(getPathToRoot(p, 0))); |
2919 |
} |
} |
2921 |
{ |
{ |
2922 |
TreePath path = new TreePath(getPathToRoot(last, 0)); |
TreePath path = new TreePath(getPathToRoot(last, 0)); |
2923 |
|
|
2924 |
if (!treeModel.isLeaf(last) && tree.isCollapsed(path)) |
if (!treeModel.isLeaf(last)) |
2925 |
tree.expandPath(path); |
toggleExpandState(path); |
2926 |
else |
else |
2927 |
{ |
{ |
2928 |
Object next = getNextVisibleNode(last); |
Object next = getNextVisibleNode(last); |
2996 |
int rowHeight = getRowHeight(); |
int rowHeight = getRowHeight(); |
2997 |
if (startNode == null || startNode.equals(node)) |
if (startNode == null || startNode.equals(node)) |
2998 |
{ |
{ |
2999 |
if (!tree.isRootVisible() |
int level = getLevel(node); |
3000 |
&& tree.isExpanded(new TreePath(mod.getRoot()))) |
if (level == 0) |
3001 |
return new Point(x + ((getLevel(node)) * rightChildIndent), y); |
return new Point(x, y); |
3002 |
|
if (!tree.isRootVisible() && |
3003 |
return new Point(x + ((getLevel(node) + 1) * rightChildIndent), y); |
tree.isExpanded(new TreePath(mod.getRoot()))) |
3004 |
|
return new Point(x + ((level - 1) * rightChildIndent), y); |
3005 |
|
return new Point(x + (level * rightChildIndent), y); |
3006 |
} |
} |
|
|
|
|
if (!mod.isLeaf(startNode) |
|
|
&& tree.isExpanded(new TreePath(getPathToRoot(startNode, 0))) |
|
|
&& !mod.isLeaf(startNode) && mod.getChildCount(startNode) > 0) |
|
|
{ |
|
|
Object child = mod.getChild(startNode, 0); |
|
|
if (child != null) |
|
|
return getCellLocation(x, y + rowHeight, tree, mod, node, child); |
|
|
} |
|
|
|
|
3007 |
return getCellLocation(x, y + rowHeight, tree, mod, node, |
return getCellLocation(x, y + rowHeight, tree, mod, node, |
3008 |
getNextVisibleNode(startNode)); |
getNextVisibleNode(startNode)); |
3009 |
} |
} |
3010 |
|
|
3011 |
/** |
/** |
|
* Paints a node in the tree Package private for use in inner classes. |
|
|
* |
|
|
* @param g |
|
|
* the Graphics context in which to paint |
|
|
* @param x |
|
|
* the x location of the node |
|
|
* @param y |
|
|
* the y location of the node |
|
|
* @param tree |
|
|
* the tree to draw on |
|
|
* @param node |
|
|
* the object to draw |
|
|
*/ |
|
|
void paintNode(Graphics g, int x, int y, JTree tree, Object node, |
|
|
boolean isLeaf) |
|
|
{ |
|
|
TreePath curr = new TreePath(getPathToRoot(node, 0)); |
|
|
boolean selected = tree.isPathSelected(curr); |
|
|
boolean expanded = false; |
|
|
boolean hasIcons = false; |
|
|
|
|
|
if (tree.isVisible(curr)) |
|
|
{ |
|
|
if (!isLeaf) |
|
|
expanded = tree.isExpanded(curr); |
|
|
|
|
|
if (editingComponent != null && editingPath != null && isEditing(tree) |
|
|
&& node.equals(editingPath.getLastPathComponent())) |
|
|
{ |
|
|
Rectangle bounds = getPathBounds(tree, editingPath); |
|
|
rendererPane.paintComponent(g, editingComponent.getParent(), null, |
|
|
new Rectangle(0, 0, bounds.width, |
|
|
bounds.height)); |
|
|
} |
|
|
else |
|
|
{ |
|
|
TreeCellRenderer dtcr = tree.getCellRenderer(); |
|
|
if (dtcr == null) |
|
|
dtcr = createDefaultCellRenderer(); |
|
|
|
|
|
int row = getRowForPath(tree, curr); |
|
|
|
|
|
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
|
|
selected, expanded, |
|
|
isLeaf, row, false); |
|
|
|
|
|
rendererPane.paintComponent(g, c, c.getParent(), |
|
|
getCellBounds(x, y, node)); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
3012 |
* Recursively paints all elements of the tree Package private for use in |
* Recursively paints all elements of the tree Package private for use in |
3013 |
* inner classes. |
* inner classes. |
3014 |
* |
* |
3018 |
* of the current object |
* of the current object |
3019 |
* @param descent |
* @param descent |
3020 |
* is the number of elements drawn |
* is the number of elements drawn |
|
* @param childNumber |
|
|
* is the index of the current child in the tree |
|
3021 |
* @param depth |
* @param depth |
3022 |
* is the depth of the current object in the tree |
* is the depth of the current object in the tree |
3023 |
* @param tree |
* @param tree |
3028 |
* is the current object to draw |
* is the current object to draw |
3029 |
* @return int - current descent of the tree |
* @return int - current descent of the tree |
3030 |
*/ |
*/ |
3031 |
int paintRecursive(Graphics g, int indentation, int descent, int childNumber, |
int paintRecursive(Graphics g, int indentation, int descent, |
3032 |
int depth, JTree tree, TreeModel mod, Object curr) |
int depth, JTree tree, TreeModel mod, Object curr) |
3033 |
{ |
{ |
3034 |
Rectangle clip = tree.getVisibleRect(); |
Rectangle clip = tree.getVisibleRect(); |
3036 |
|| descent > clip.y + clip.height + getRowHeight()) |
|| descent > clip.y + clip.height + getRowHeight()) |
3037 |
return descent; |
return descent; |
3038 |
|
|
3039 |
|
TreePath path = new TreePath(getPathToRoot(curr, 0)); |
3040 |
int halfHeight = getRowHeight() / 2; |
int halfHeight = getRowHeight() / 2; |
3041 |
int halfWidth = rightChildIndent / 2; |
int halfWidth = rightChildIndent / 2; |
3042 |
int y0 = descent + halfHeight; |
int y0 = descent + halfHeight; |
3043 |
int heightOfLine = descent + halfHeight; |
int heightOfLine = descent + halfHeight; |
3044 |
|
int row = getRowForPath(tree, path); |
3045 |
boolean isRootVisible = tree.isRootVisible(); |
boolean isRootVisible = tree.isRootVisible(); |
3046 |
|
boolean isExpanded = tree.isExpanded(path); |
3047 |
if (mod.isLeaf(curr)) |
boolean isLeaf = mod.isLeaf(curr); |
3048 |
|
Rectangle bounds = getPathBounds(tree, path); |
3049 |
|
Object root = mod.getRoot(); |
3050 |
|
|
3051 |
|
if (isLeaf) |
3052 |
{ |
{ |
3053 |
paintNode(g, indentation + 4, descent, tree, curr, true); |
paintRow(g, clip, null, bounds, path, row, true, false, true); |
3054 |
descent += getRowHeight(); |
descent += getRowHeight(); |
3055 |
} |
} |
3056 |
else |
else |
3057 |
{ |
{ |
3058 |
if (depth > 0 || isRootVisible) |
if (depth > 0 || isRootVisible) |
3059 |
{ |
{ |
3060 |
paintNode(g, indentation + 4, descent, tree, curr, false); |
paintRow(g, clip, null, bounds, path, row, isExpanded, false, false); |
3061 |
descent += getRowHeight(); |
descent += getRowHeight(); |
3062 |
y0 += halfHeight; |
y0 += halfHeight; |
3063 |
} |
} |
3064 |
|
|
3065 |
int max = 0; |
int max = mod.getChildCount(curr); |
3066 |
if (!mod.isLeaf(curr)) |
if (isExpanded) |
|
max = mod.getChildCount(curr); |
|
|
if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0)))) |
|
3067 |
{ |
{ |
3068 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
3069 |
{ |
{ |
3070 |
int indent = indentation + rightChildIndent; |
int indent = indentation + rightChildIndent; |
3071 |
if (!isRootVisible && depth == 0) |
if (!isRootVisible && depth == 0) |
3072 |
indent = 0; |
indent = 0; |
3073 |
else if ((!isRootVisible && !curr.equals(mod.getRoot())) |
else if (isRootVisible || |
3074 |
|| isRootVisible) |
(!isRootVisible && !curr.equals(root))) |
3075 |
{ |
{ |
3076 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
3077 |
heightOfLine = descent + halfHeight; |
heightOfLine = descent + halfHeight; |
3079 |
indentation + halfWidth, indentation + rightChildIndent); |
indentation + halfWidth, indentation + rightChildIndent); |
3080 |
} |
} |
3081 |
|
|
3082 |
descent = paintRecursive(g, indent, descent, i, depth + 1, |
descent = paintRecursive(g, indent, descent, depth + 1, |
3083 |
tree, mod, mod.getChild(curr, i)); |
tree, mod, mod.getChild(curr, i)); |
3084 |
} |
} |
3085 |
} |
} |
3086 |
} |
} |
3087 |
|
|
3088 |
if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0)))) |
if (isExpanded) |
3089 |
if (y0 != heightOfLine && !mod.isLeaf(curr) |
if (y0 != heightOfLine && !isLeaf |
3090 |
&& mod.getChildCount(curr) > 0) |
&& mod.getChildCount(curr) > 0) |
3091 |
{ |
{ |
3092 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
3096 |
|
|
3097 |
return descent; |
return descent; |
3098 |
} |
} |
3099 |
|
|
3100 |
/** |
/** |
3101 |
* Recursively paints all the control icons on the tree. Package private for |
* Recursively paints all the control icons on the tree. Package private for |
3102 |
* use in inner classes. |
* use in inner classes. |
3115 |
* is the tree to draw to |
* is the tree to draw to |
3116 |
* @param mod |
* @param mod |
3117 |
* is the TreeModel we are using to draw |
* is the TreeModel we are using to draw |
3118 |
* @param curr |
* @param node |
3119 |
* is the current object to draw |
* is the current object to draw |
3120 |
* @return int - current descent of the tree |
* @return int current descent of the tree |
3121 |
*/ |
*/ |
3122 |
int paintControlIcons(Graphics g, int indentation, int descent, |
int paintControlIcons(Graphics g, int indentation, int descent, |
3123 |
int childNumber, int depth, JTree tree, TreeModel mod, |
int childNumber, int depth, JTree tree, TreeModel mod, |
3124 |
Object node) |
Object node) |
3125 |
{ |
{ |
3126 |
int h = descent; |
int h = descent; |
3127 |
int rowHeight = getRowHeight(); |
int rowHeight = getRowHeight(); |
3128 |
TreePath path = new TreePath(getPathToRoot(node, 0)); |
TreePath path = new TreePath(getPathToRoot(node, 0)); |
3129 |
Icon icon = getCurrentControlIcon(path); |
Icon icon = getCurrentControlIcon(path); |
3130 |
|
|
3131 |
Rectangle clip = tree.getVisibleRect(); |
Rectangle clip = tree.getVisibleRect(); |
3132 |
if (indentation > clip.x + clip.width + rightChildIndent |
if (indentation > clip.x + clip.width + rightChildIndent |
3133 |
|| descent > clip.y + clip.height + getRowHeight()) |
|| descent > clip.y + clip.height + getRowHeight()) |
3134 |
return descent; |
return descent; |
3135 |
|
|
3136 |
if (mod.isLeaf(node)) |
if (mod.isLeaf(node)) |
3137 |
descent += rowHeight; |
descent += rowHeight; |
3138 |
else |
else |
3139 |
{ |
{ |
3140 |
if (depth > 0 || tree.isRootVisible()) |
if (depth > 0 || tree.isRootVisible()) |
3141 |
descent += rowHeight; |
descent += rowHeight; |
3142 |
|
|
3143 |
int max = 0; |
int max = 0; |
3144 |
if (!mod.isLeaf(node)) |
if (!mod.isLeaf(node)) |
3145 |
max = mod.getChildCount(node); |
max = mod.getChildCount(node); |
3146 |
|
|
3147 |
if (!node.equals(mod.getRoot())) |
if (!node.equals(mod.getRoot())) |
3148 |
icon.paintIcon(tree, g, indentation - rightChildIndent - 3, h); |
icon.paintIcon(tree, g, indentation - rightChildIndent - 3, h); |
3149 |
|
|
3150 |
if (tree.isExpanded(path)) |
if (tree.isExpanded(path)) |
3151 |
{ |
{ |
3152 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
3153 |
{ |
{ |
3154 |
int indent = indentation + rightChildIndent; |
int indent = indentation + rightChildIndent; |
3155 |
if (depth == 0 && !tree.isRootVisible()) |
if (depth == 0 && !tree.isRootVisible()) |
3156 |
indent = -1; |
indent = 1; |
3157 |
|
|
3158 |
descent = paintControlIcons(g, indent, descent, i, depth + 1, |
descent = paintControlIcons(g, indent, descent, i, depth + 1, |
3159 |
tree, mod, mod.getChild(node, i)); |
tree, mod, mod.getChild(node, i)); |
3160 |
} |
} |
3161 |
} |
} |
3162 |
} |
} |
3163 |
|
|
3164 |
return descent; |
return descent; |
3165 |
} |
} |
3166 |
|
|
3167 |
/** |
/** |
3168 |
* Returns control icon. It is null if the LookAndFeel does not |
* Returns true if the LookAndFeel implements the control icons. Package |
3169 |
* implements the control icons. |
* private for use in inner classes. |
|
* Package private for use in inner classes. |
|
3170 |
* |
* |
3171 |
* @return control icon if it exists. |
* @returns true if there are control icons |
3172 |
*/ |
*/ |
3173 |
Icon getCurrentControlIcon(TreePath path) |
boolean hasControlIcons() |
3174 |
{ |
{ |
3175 |
if (tree.isExpanded(path)) |
if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null |
3176 |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); |
|| UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") != null) |
3177 |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); |
return true; |
3178 |
|
return false; |
3179 |
} |
} |
3180 |
|
|
3181 |
/** |
/** |
3182 |
* Returns true if the LookAndFeel implements the control icons. |
* Returns control icon. It is null if the LookAndFeel does not implements the |
3183 |
* Package private for use in inner classes. |
* control icons. Package private for use in inner classes. |
3184 |
* |
* |
3185 |
* @returns true if there are control icons |
* @return control icon if it exists. |
3186 |
*/ |
*/ |
3187 |
boolean hasControlIcons() |
Icon getCurrentControlIcon(TreePath path) |
3188 |
{ |
{ |
3189 |
if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null |
if (tree.isExpanded(path)) |
3190 |
|| UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); |
3191 |
!= null) |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); |
|
return true; |
|
|
return false; |
|
3192 |
} |
} |
3193 |
|
|
3194 |
/** |
/** |
3236 |
} |
} |
3237 |
|
|
3238 |
/** |
/** |
|
* Get next visible node in the tree. Package private for use in inner |
|
|
* classes. |
|
|
* |
|
|
* @param the |
|
|
* current node |
|
|
* @return the next visible node in the JTree. Return null if there are no |
|
|
* more. |
|
|
*/ |
|
|
Object getNextVisibleNode(Object node) |
|
|
{ |
|
|
Object next = null; |
|
|
TreePath current = null; |
|
|
|
|
|
if (node != null) |
|
|
next = getNextNode(node); |
|
|
|
|
|
if (next != null) |
|
|
{ |
|
|
current = new TreePath(getPathToRoot(next, 0)); |
|
|
if (tree.isVisible(current)) |
|
|
return next; |
|
|
|
|
|
while (next != null && !tree.isVisible(current)) |
|
|
{ |
|
|
next = getNextNode(next); |
|
|
|
|
|
if (next != null) |
|
|
current = new TreePath(getPathToRoot(next, 0)); |
|
|
} |
|
|
} |
|
|
return next; |
|
|
} |
|
|
|
|
|
/** |
|
3239 |
* 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 |
3240 |
* classes. |
* classes. |
3241 |
* |
* |
3246 |
*/ |
*/ |
3247 |
Object getPreviousVisibleNode(Object node) |
Object getPreviousVisibleNode(Object node) |
3248 |
{ |
{ |
3249 |
Object prev = null; |
Object[] nodes = currentVisiblePath.getPath(); |
3250 |
TreePath current = null; |
int i = 0; |
3251 |
|
while (i < nodes.length && !node.equals(nodes[i])) |
3252 |
if (node != null) |
i++; |
3253 |
prev = getPreviousNode(node); |
// return the next node |
3254 |
|
if (i-1 > 0) |
3255 |
if (prev != null) |
return nodes[i-1]; |
3256 |
{ |
return null; |
|
current = new TreePath(getPathToRoot(prev, 0)); |
|
|
if (tree.isVisible(current)) |
|
|
return prev; |
|
|
|
|
|
while (prev != null && !tree.isVisible(current)) |
|
|
{ |
|
|
prev = getPreviousNode(prev); |
|
|
|
|
|
if (prev != null) |
|
|
current = new TreePath(getPathToRoot(prev, 0)); |
|
|
} |
|
|
} |
|
|
return prev; |
|
3257 |
} |
} |
3258 |
|
|
3259 |
/** |
/** |
3285 |
* Returns the previous node in the tree Package private for use in inner |
* Returns the previous node in the tree Package private for use in inner |
3286 |
* classes. |
* classes. |
3287 |
* |
* |
3288 |
* @param the |
* @param node |
3289 |
* current node |
* current node |
3290 |
* @return the previous node in the tree |
* @return the previous node in the tree |
3291 |
*/ |
*/ |
3620 |
boolean isExpanded, boolean hasBeenExpanded, |
boolean isExpanded, boolean hasBeenExpanded, |
3621 |
boolean isLeaf) |
boolean isLeaf) |
3622 |
{ |
{ |
3623 |
// FIXME: not implemented. |
boolean selected = tree.isPathSelected(path); |
3624 |
|
boolean hasIcons = false; |
3625 |
|
Object node = path.getLastPathComponent(); |
3626 |
|
|
3627 |
|
if (tree.isVisible(path)) |
3628 |
|
{ |
3629 |
|
if (editingComponent != null && editingPath != null && isEditing(tree) |
3630 |
|
&& node.equals(editingPath.getLastPathComponent())) |
3631 |
|
{ |
3632 |
|
rendererPane.paintComponent(g, editingComponent.getParent(), null, |
3633 |
|
new Rectangle(0, 0, bounds.width, bounds.height)); |
3634 |
|
} |
3635 |
|
else |
3636 |
|
{ |
3637 |
|
TreeCellRenderer dtcr = tree.getCellRenderer(); |
3638 |
|
if (dtcr == null) |
3639 |
|
dtcr = createDefaultCellRenderer(); |
3640 |
|
|
3641 |
|
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
3642 |
|
selected, isExpanded, |
3643 |
|
isLeaf, row, false); |
3644 |
|
// add padding between line and node |
3645 |
|
bounds.x += 4; |
3646 |
|
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
3647 |
|
} |
3648 |
|
} |
3649 |
} |
} |
3650 |
|
|
3651 |
/** |
/** |
3673 |
// FIXME: not implemented. |
// FIXME: not implemented. |
3674 |
return false; |
return false; |
3675 |
} |
} |
3676 |
|
|
3677 |
|
/** |
3678 |
|
* Updates the cached current TreePath of all visible |
3679 |
|
* nodes in the tree. |
3680 |
|
*/ |
3681 |
|
void updateCurrentVisiblePath() |
3682 |
|
{ |
3683 |
|
Object next = treeModel.getRoot(); |
3684 |
|
if (!isRootVisible() && tree.isExpanded(new TreePath(next))) |
3685 |
|
next = getNextNode(next); |
3686 |
|
TreePath current = null; |
3687 |
|
|
3688 |
|
while (next != null) |
3689 |
|
{ |
3690 |
|
if (current != null) |
3691 |
|
current = current.pathByAddingChild(next); |
3692 |
|
else |
3693 |
|
current = new TreePath(next); |
3694 |
|
|
3695 |
|
do |
3696 |
|
next = getNextNode(next); |
3697 |
|
while (next != null |
3698 |
|
&& !tree.isVisible(new TreePath(getPathToRoot(next, 0)))); |
3699 |
|
} |
3700 |
|
currentVisiblePath = current; |
3701 |
|
} |
3702 |
|
|
3703 |
|
/** |
3704 |
|
* Get next visible node in the currentVisiblePath. Package private for use in |
3705 |
|
* inner classes. |
3706 |
|
* |
3707 |
|
* @param node |
3708 |
|
* current node |
3709 |
|
* @return the next visible node in the JTree. Return null if there are no |
3710 |
|
* more. |
3711 |
|
*/ |
3712 |
|
Object getNextVisibleNode(Object node) |
3713 |
|
{ |
3714 |
|
Object[] nodes = currentVisiblePath.getPath(); |
3715 |
|
int i = 0; |
3716 |
|
while (i < nodes.length && !node.equals(nodes[i])) |
3717 |
|
i++; |
3718 |
|
// return the next node |
3719 |
|
if (i+1 < nodes.length) |
3720 |
|
return nodes[i+1]; |
3721 |
|
return null; |
3722 |
|
} |
3723 |
} // BasicTreeUI |
} // BasicTreeUI |