246 |
|
|
247 |
/** The current path of the visible nodes in the tree. */ |
/** The current path of the visible nodes in the tree. */ |
248 |
TreePath currentVisiblePath; |
TreePath currentVisiblePath; |
249 |
|
|
250 |
|
/** The gap between the icon and text. */ |
251 |
|
int gap = 4; |
252 |
|
|
253 |
/** Listeners */ |
/** Listeners */ |
254 |
private PropertyChangeListener propertyChangeListener; |
private PropertyChangeListener propertyChangeListener; |
634 |
if (treeModel != null) |
if (treeModel != null) |
635 |
{ |
{ |
636 |
Object root = treeModel.getRoot(); |
Object root = treeModel.getRoot(); |
637 |
|
|
638 |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
639 |
root = getNextNode(root); |
root = getNextNode(root); |
640 |
|
|
727 |
{ |
{ |
728 |
// FIXME: what if root is hidden? should not depend on (0,0) |
// FIXME: what if root is hidden? should not depend on (0,0) |
729 |
// should start counting rows from where root is. |
// should start counting rows from where root is. |
730 |
|
|
731 |
int row = Math.round(y / getRowHeight()); |
int row = Math.round(y / getRowHeight()); |
732 |
TreePath path = getPathForRow(tree, row); |
TreePath path = getPathForRow(tree, row); |
733 |
|
|
1181 |
for (int i = 0; i < path.length; i++) |
for (int i = 0; i < path.length; i++) |
1182 |
{ |
{ |
1183 |
TreePath curr = new TreePath(getPathToRoot(path[i], 0)); |
TreePath curr = new TreePath(getPathToRoot(path[i], 0)); |
1184 |
Rectangle bounds = getPathBounds(tree, |
Rectangle bounds = getPathBounds(tree, curr); |
1185 |
curr); |
|
1186 |
if (treeModel != null) |
if (treeModel != null) |
1187 |
isLeaf = treeModel.isLeaf(path[i]); |
isLeaf = treeModel.isLeaf(path[i]); |
1188 |
if (hasControlIcons()) |
if (!isLeaf && hasControlIcons()) |
1189 |
bounds.width += getCurrentControlIcon(curr).getIconWidth(); |
bounds.width += getCurrentControlIcon(curr).getIconWidth(); |
1190 |
|
|
1191 |
maxWidth = Math.max(maxWidth, bounds.x + bounds.width); |
maxWidth = Math.max(maxWidth, bounds.x + bounds.width); |
1192 |
} |
} |
1193 |
preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length)); |
preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length)); |
2308 |
int row = getRowForPath(tree, path); |
int row = getRowForPath(tree, path); |
2309 |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
2310 |
|
|
2311 |
if (isLeaf(row)) |
boolean isLeaf = isLeaf(row); |
2312 |
bounds.width += rightChildIndent + 4; |
if (isLeaf) |
2313 |
|
bounds.width += rightChildIndent + gap; |
2314 |
else if (hasControlIcons()) |
else if (hasControlIcons()) |
2315 |
bounds.width += getCurrentControlIcon(path).getIconWidth() + 4; |
bounds.width += getCurrentControlIcon(path).getIconWidth() + gap; |
2316 |
|
|
2317 |
boolean inBounds = bounds.contains(click.x, click.y); |
boolean inBounds = bounds.contains(click.x, click.y); |
2318 |
if ((inBounds || cntlClick) && tree.isVisible(path)) |
if ((inBounds || cntlClick) && tree.isVisible(path)) |
2319 |
{ |
{ |
3002 |
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
3003 |
|
|
3004 |
if (s != null) |
if (s != null) |
3005 |
return new Rectangle(x, y, |
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + gap, |
|
SwingUtilities.computeStringWidth(fm, s) + 4, |
|
3006 |
fm.getHeight()); |
fm.getHeight()); |
3007 |
} |
} |
3008 |
return new Rectangle(x, y, 0, 0); |
return new Rectangle(x, y, 0, 0); |
3086 |
int iconWidth = 0; |
int iconWidth = 0; |
3087 |
if (!isLeaf && hasControlIcons()) |
if (!isLeaf && hasControlIcons()) |
3088 |
iconWidth += getCurrentControlIcon(path).getIconWidth(); |
iconWidth += getCurrentControlIcon(path).getIconWidth(); |
3089 |
bounds.width += bounds.x + iconWidth; |
bounds.width += bounds.x + iconWidth + gap; |
3090 |
|
|
3091 |
if (isLeaf) |
if (isLeaf) |
3092 |
{ |
{ |
3683 |
dtcr = createDefaultCellRenderer(); |
dtcr = createDefaultCellRenderer(); |
3684 |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
3685 |
selected, isExpanded, isLeaf, row, false); |
selected, isExpanded, isLeaf, row, false); |
3686 |
bounds.x += 4; |
bounds.x += gap; |
3687 |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
3688 |
} |
} |
3689 |
} |
} |
3725 |
void updateCurrentVisiblePath() |
void updateCurrentVisiblePath() |
3726 |
{ |
{ |
3727 |
Object next = treeModel.getRoot(); |
Object next = treeModel.getRoot(); |
3728 |
if (!isRootVisible() && tree.isExpanded(new TreePath(next))) |
Rectangle bounds = getCellBounds(0, 0, next); |
3729 |
|
|
3730 |
|
// If root is not a valid size to be visible, or is |
3731 |
|
// not visible and the tree is expanded, then the next node acts |
3732 |
|
// as the root |
3733 |
|
if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible() |
3734 |
|
&& tree.isExpanded(new TreePath(next)))) |
3735 |
next = getNextNode(next); |
next = getNextNode(next); |
3736 |
TreePath current = null; |
TreePath current = null; |
3737 |
|
|