225 |
|
|
226 |
/** Set to true if the editor has a different size than the renderer. */ |
/** Set to true if the editor has a different size than the renderer. */ |
227 |
protected boolean editorHasDifferentSize; |
protected boolean editorHasDifferentSize; |
|
|
|
|
/** Leaf icon for the tree. */ |
|
|
Icon leafIcon; |
|
228 |
|
|
229 |
/** The action listener for the editor's Timer. */ |
/** The action listener for the editor's Timer. */ |
230 |
Timer editorTimer = new EditorUpdateTimer(); |
Timer editorTimer = new EditorUpdateTimer(); |
282 |
|
|
283 |
editingRow = -1; |
editingRow = -1; |
284 |
lastSelectedRow = -1; |
lastSelectedRow = -1; |
|
leafIcon = UIManager.getIcon("Tree.leafIcon"); |
|
285 |
} |
} |
286 |
|
|
287 |
/** |
/** |
1229 |
tree.setRowHeight(UIManager.getInt("Tree.rowHeight")); |
tree.setRowHeight(UIManager.getInt("Tree.rowHeight")); |
1230 |
tree.requestFocusInWindow(false); |
tree.requestFocusInWindow(false); |
1231 |
tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand")); |
tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand")); |
1232 |
setExpandedIcon(UIManager.getIcon("Tree.openIcon")); |
setExpandedIcon(UIManager.getIcon("Tree.expandedIcon")); |
1233 |
setCollapsedIcon(UIManager.getIcon("Tree.closedIcon")); |
setCollapsedIcon(UIManager.getIcon("Tree.collapsedIcon")); |
1234 |
} |
} |
1235 |
|
|
1236 |
/** |
/** |
1669 |
|
|
1670 |
if (!isLeaf(row)) |
if (!isLeaf(row)) |
1671 |
{ |
{ |
1672 |
if (bounds == null) |
bounds = getPathBounds(tree, path); |
|
bounds = getPathBounds(tree, path); |
|
1673 |
|
|
1674 |
if (hasControlIcons() && (mouseX < bounds.x) |
if (hasControlIcons() && (mouseX < bounds.x) |
1675 |
&& (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth()))) |
&& (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap))) |
1676 |
cntlClick = true; |
cntlClick = true; |
1677 |
} |
} |
1678 |
return cntlClick; |
return cntlClick; |
2305 |
bounds = getPathBounds(tree, path); |
bounds = getPathBounds(tree, path); |
2306 |
int row = getRowForPath(tree, path); |
int row = getRowForPath(tree, path); |
2307 |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
2308 |
|
|
2309 |
boolean isLeaf = isLeaf(row); |
boolean isLeaf = isLeaf(row); |
2310 |
|
|
2311 |
|
TreeCellRenderer tcr = getCellRenderer(); |
2312 |
|
Icon icon; |
2313 |
if (isLeaf) |
if (isLeaf) |
2314 |
bounds.width += rightChildIndent + gap; |
icon = UIManager.getIcon("Tree.leafIcon"); |
2315 |
else if (hasControlIcons()) |
else if (tree.isExpanded(path)) |
2316 |
bounds.width += getCurrentControlIcon(path).getIconWidth() + gap; |
icon = UIManager.getIcon("Tree.openIcon"); |
2317 |
|
else |
2318 |
|
icon = UIManager.getIcon("Tree.closedIcon"); |
2319 |
|
|
2320 |
|
if (tcr instanceof DefaultTreeCellRenderer) |
2321 |
|
{ |
2322 |
|
Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon(); |
2323 |
|
if (tmp != null) |
2324 |
|
icon = tmp; |
2325 |
|
} |
2326 |
|
|
2327 |
|
// add gap*2 for the space before and after the text |
2328 |
|
if (icon != null) |
2329 |
|
bounds.width += icon.getIconWidth() + gap*2; |
2330 |
|
|
2331 |
boolean inBounds = bounds.contains(click.x, click.y); |
boolean inBounds = bounds.contains(click.x, click.y); |
2332 |
if ((inBounds || cntlClick) && tree.isVisible(path)) |
if ((inBounds || cntlClick) && tree.isVisible(path)) |
2333 |
{ |
{ |
3024 |
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
3025 |
|
|
3026 |
if (s != null) |
if (s != null) |
3027 |
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + gap, |
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), |
3028 |
fm.getHeight()); |
fm.getHeight()); |
3029 |
} |
} |
3030 |
return new Rectangle(x, y, 0, 0); |
return new Rectangle(x, y, 0, 0); |
3243 |
*/ |
*/ |
3244 |
boolean hasControlIcons() |
boolean hasControlIcons() |
3245 |
{ |
{ |
3246 |
if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null |
if (expandedIcon != null || collapsedIcon != null) |
|
|| UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") != null) |
|
3247 |
return true; |
return true; |
3248 |
return false; |
return false; |
3249 |
} |
} |
3257 |
Icon getCurrentControlIcon(TreePath path) |
Icon getCurrentControlIcon(TreePath path) |
3258 |
{ |
{ |
3259 |
if (tree.isExpanded(path)) |
if (tree.isExpanded(path)) |
3260 |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); |
return expandedIcon; |
3261 |
return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); |
return collapsedIcon; |
3262 |
} |
} |
3263 |
|
|
3264 |
/** |
/** |
3699 |
|
|
3700 |
if (tree.isVisible(path)) |
if (tree.isVisible(path)) |
3701 |
{ |
{ |
3702 |
// need to set exact width of entire row |
bounds.width = preferredSize.width; |
3703 |
int iconWidth = 0; |
bounds.x += gap; |
|
if (!isLeaf && hasControlIcons()) |
|
|
iconWidth = getCurrentControlIcon(path).getIconWidth(); |
|
|
if (isLeaf && leafIcon != null) |
|
|
iconWidth += leafIcon.getIconWidth(); |
|
|
else if (isExpanded && expandedIcon != null) |
|
|
iconWidth += expandedIcon.getIconWidth(); |
|
|
else if (collapsedIcon != null) |
|
|
iconWidth += collapsedIcon.getIconWidth(); |
|
|
bounds.width += bounds.x + iconWidth + gap; |
|
3704 |
|
|
3705 |
if (editingComponent != null && editingPath != null && isEditing(tree) |
if (editingComponent != null && editingPath != null && isEditing(tree) |
3706 |
&& node.equals(editingPath.getLastPathComponent())) |
&& node.equals(editingPath.getLastPathComponent())) |
3716 |
|
|
3717 |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
Component c = dtcr.getTreeCellRendererComponent(tree, node, |
3718 |
selected, isExpanded, isLeaf, row, false); |
selected, isExpanded, isLeaf, row, false); |
|
bounds.x += gap; |
|
3719 |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
rendererPane.paintComponent(g, c, c.getParent(), bounds); |
3720 |
} |
} |
3721 |
} |
} |
3780 |
} |
} |
3781 |
currentVisiblePath = current; |
currentVisiblePath = current; |
3782 |
tree.setVisibleRowCount(getRowCount(tree)); |
tree.setVisibleRowCount(getRowCount(tree)); |
3783 |
|
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && |
3784 |
|
currentVisiblePath != null) |
3785 |
|
tree.addSelectionRow(0); |
3786 |
} |
} |
3787 |
|
|
3788 |
/** |
/** |