239 |
/** Boolean to keep track of editing. */ |
/** Boolean to keep track of editing. */ |
240 |
boolean isEditing; |
boolean isEditing; |
241 |
|
|
|
/** The bounds of the current cell. */ |
|
|
Rectangle bounds; |
|
|
|
|
242 |
/** The current path of the visible nodes in the tree. */ |
/** The current path of the visible nodes in the tree. */ |
243 |
TreePath currentVisiblePath; |
TreePath currentVisiblePath; |
244 |
|
|
621 |
*/ |
*/ |
622 |
public Rectangle getPathBounds(JTree tree, TreePath path) |
public Rectangle getPathBounds(JTree tree, TreePath path) |
623 |
{ |
{ |
624 |
|
Rectangle bounds = null; |
625 |
|
int row = -1; |
626 |
|
Object cell = null; |
627 |
if (path != null) |
if (path != null) |
628 |
{ |
{ |
629 |
Object cell = path.getLastPathComponent(); |
row = getRowForPath(tree, path); |
630 |
|
cell = path.getLastPathComponent(); |
631 |
if (treeModel != null) |
bounds = new Rectangle(0, row * getRowHeight(), 0, 0); |
632 |
{ |
} |
633 |
Object root = treeModel.getRoot(); |
return nodeDimensions.getNodeDimensions(cell, row, |
634 |
|
getLevel(cell), |
635 |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
tree.isExpanded(path), |
636 |
root = getNextNode(root); |
bounds); |
|
Point loc = getCellLocation(0, 0, tree, treeModel, cell, root); |
|
|
return getCellBounds(loc.x, loc.y, cell); |
|
|
} |
|
|
} |
|
|
return null; |
|
637 |
} |
} |
638 |
|
|
639 |
/** |
/** |
695 |
*/ |
*/ |
696 |
public int getRowCount(JTree tree) |
public int getRowCount(JTree tree) |
697 |
{ |
{ |
|
updateCurrentVisiblePath(); |
|
698 |
if (currentVisiblePath != null) |
if (currentVisiblePath != null) |
699 |
return currentVisiblePath.getPathCount(); |
return currentVisiblePath.getPathCount(); |
700 |
return 0; |
return 0; |
1029 |
*/ |
*/ |
1030 |
protected void uninstallKeyboardActions() |
protected void uninstallKeyboardActions() |
1031 |
{ |
{ |
1032 |
// TODO: Implement this properly. |
action = null; |
1033 |
|
tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).setParent(null); |
1034 |
|
tree.getActionMap().setParent(null); |
1035 |
} |
} |
1036 |
|
|
1037 |
/** |
/** |
1405 |
JTree tree = (JTree) c; |
JTree tree = (JTree) c; |
1406 |
if (currentVisiblePath == null) |
if (currentVisiblePath == null) |
1407 |
updateCurrentVisiblePath(); |
updateCurrentVisiblePath(); |
1408 |
|
|
1409 |
if (currentVisiblePath != null && treeModel != null) |
Rectangle clip = g.getClipBounds(); |
1410 |
|
Insets insets = tree.getInsets(); |
1411 |
|
|
1412 |
|
if (clip != null && treeModel != null) |
1413 |
{ |
{ |
1414 |
Object root = treeModel.getRoot(); |
int startIndex = tree.getClosestRowForLocation(clip.x, clip.y); |
1415 |
paintRecursive(g, 0, 0, 0, tree, treeModel, root); |
int endIndex = tree.getClosestRowForLocation(clip.x + clip.width, |
1416 |
|
clip.y + clip.height); |
1417 |
if (hasControlIcons()) |
|
1418 |
paintControlIcons(g, 0, 0, 0, tree, treeModel, root); |
paintVerticalPartOfLeg(g, clip, insets, currentVisiblePath); |
1419 |
|
for (int i = startIndex; i <= endIndex; i++) |
1420 |
|
{ |
1421 |
|
Object curr = currentVisiblePath.getPathComponent(i); |
1422 |
|
boolean isLeaf = treeModel.isLeaf(curr); |
1423 |
|
TreePath path = new TreePath(getPathToRoot(curr, 0)); |
1424 |
|
|
1425 |
|
boolean isExpanded = tree.isExpanded(path); |
1426 |
|
Rectangle bounds = getPathBounds(tree, path); |
1427 |
|
paintHorizontalPartOfLeg(g, clip, insets, bounds, path, i, |
1428 |
|
isExpanded, false, isLeaf); |
1429 |
|
paintRow(g, clip, insets, bounds, path, i, isExpanded, false, |
1430 |
|
isLeaf); |
1431 |
|
} |
1432 |
} |
} |
1433 |
} |
} |
1434 |
|
|
1602 |
int y; |
int y; |
1603 |
if (event == null) |
if (event == null) |
1604 |
{ |
{ |
1605 |
bounds = getPathBounds(tree, path); |
Rectangle bounds = getPathBounds(tree, path); |
1606 |
x = bounds.x; |
x = bounds.x; |
1607 |
y = bounds.y; |
y = bounds.y; |
1608 |
} |
} |
1682 |
|
|
1683 |
if (!isLeaf(row)) |
if (!isLeaf(row)) |
1684 |
{ |
{ |
1685 |
bounds = getPathBounds(tree, path); |
Rectangle bounds = getPathBounds(tree, path); |
1686 |
|
|
1687 |
if (hasControlIcons() && (mouseX < bounds.x) |
if (hasControlIcons() && (mouseX < bounds.x) |
1688 |
&& (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap))) |
&& (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap))) |
2003 |
} |
} |
2004 |
|
|
2005 |
/** |
/** |
2006 |
* Creats, if necessary, and starts a Timer to check if needed to resize the |
* Creates, if necessary, and starts a Timer to check if needed to resize the |
2007 |
* bounds |
* bounds |
2008 |
*/ |
*/ |
2009 |
protected void startTimer() |
protected void startTimer() |
2239 |
|
|
2240 |
if (path != null) |
if (path != null) |
2241 |
{ |
{ |
2242 |
bounds = getPathBounds(tree, path); |
Rectangle bounds = getPathBounds(tree, path); |
2243 |
int row = getRowForPath(tree, path); |
int row = getRowForPath(tree, path); |
2244 |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
2245 |
|
|
2280 |
handleExpandControlClick(path, click.x, click.y); |
handleExpandControlClick(path, click.x, click.y); |
2281 |
if (cellEditor != null) |
if (cellEditor != null) |
2282 |
cellEditor.cancelCellEditing(); |
cellEditor.cancelCellEditing(); |
2283 |
|
tree.scrollPathToVisible(path); |
2284 |
} |
} |
2285 |
else if (tree.isEditable()) |
else if (tree.isEditable()) |
2286 |
startEditing(path, e); |
startEditing(path, e); |
2464 |
} |
} |
2465 |
|
|
2466 |
/** |
/** |
2467 |
* Responsible for getting the size of a particular node. |
* Returns, by reference in bounds, the size and x origin to place value at. |
2468 |
|
* The calling method is responsible for determining the Y location. |
2469 |
|
* If bounds is null, a newly created Rectangle should be returned, |
2470 |
|
* otherwise the value should be placed in bounds and returned. |
2471 |
* |
* |
2472 |
* @param value |
* @param cell |
2473 |
* the value to be represented |
* the value to be represented |
2474 |
* @param row |
* @param row |
2475 |
* row being queried |
* row being queried |
2481 |
* a Rectangle containing the size needed to represent value |
* a Rectangle containing the size needed to represent value |
2482 |
* @return containing the node dimensions, or null if node has no dimension |
* @return containing the node dimensions, or null if node has no dimension |
2483 |
*/ |
*/ |
2484 |
public Rectangle getNodeDimensions(Object value, int row, int depth, |
public Rectangle getNodeDimensions(Object cell, int row, int depth, |
2485 |
boolean expanded, Rectangle size) |
boolean expanded, Rectangle size) |
2486 |
{ |
{ |
2487 |
return null; |
if (size == null || cell == null) |
2488 |
|
return null; |
2489 |
|
|
2490 |
|
String s = cell.toString(); |
2491 |
|
Font f = tree.getFont(); |
2492 |
|
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
2493 |
|
|
2494 |
|
if (s != null) |
2495 |
|
{ |
2496 |
|
size.x = getRowX(row, depth); |
2497 |
|
size.width = SwingUtilities.computeStringWidth(fm, s); |
2498 |
|
size.height = fm.getHeight(); |
2499 |
|
} |
2500 |
|
return size; |
2501 |
} |
} |
2502 |
|
|
2503 |
/** |
/** |
2507 |
*/ |
*/ |
2508 |
protected int getRowX(int row, int depth) |
protected int getRowX(int row, int depth) |
2509 |
{ |
{ |
2510 |
return 0; |
if (row == 0) |
2511 |
|
return 0; |
2512 |
|
return depth * rightChildIndent; |
2513 |
} |
} |
2514 |
}// NodeDimensionsHandler |
}// NodeDimensionsHandler |
2515 |
|
|
3088 |
} |
} |
3089 |
|
|
3090 |
/** |
/** |
|
* Returns the cell bounds for painting selected cells Package private for use |
|
|
* in inner classes. |
|
|
* |
|
|
* @param x |
|
|
* is the x location of the cell |
|
|
* @param y |
|
|
* is the y location of the cell |
|
|
* @param cell |
|
|
* is the Object to get the bounds for |
|
|
* @returns Rectangle that represents the cell bounds |
|
|
*/ |
|
|
Rectangle getCellBounds(int x, int y, Object cell) |
|
|
{ |
|
|
if (cell != null) |
|
|
{ |
|
|
String s = cell.toString(); |
|
|
Font f = tree.getFont(); |
|
|
FontMetrics fm = tree.getToolkit().getFontMetrics(f); |
|
|
|
|
|
if (s != null) |
|
|
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), |
|
|
fm.getHeight()); |
|
|
} |
|
|
return new Rectangle(x, y, 0, 0); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Retrieves the location of some node, recursively starting at from some |
|
|
* node. Package private for use in inner classes. |
|
|
* |
|
|
* @param x |
|
|
* is the starting x position, offset |
|
|
* @param y |
|
|
* is the starting y position, offset |
|
|
* @param tree |
|
|
* is the tree to traverse |
|
|
* @param mod |
|
|
* is the TreeModel to use |
|
|
* @param node |
|
|
* is the node to get the location for |
|
|
* @param startNode |
|
|
* is the node to start searching from |
|
|
* @return Point - the location of node |
|
|
*/ |
|
|
Point getCellLocation(int x, int y, JTree tree, TreeModel mod, Object node, |
|
|
Object startNode) |
|
|
{ |
|
|
int rowHeight = getRowHeight(); |
|
|
if (startNode == null || startNode.equals(node)) |
|
|
{ |
|
|
int level = getLevel(node); |
|
|
if (level == 0) |
|
|
return new Point(x, y); |
|
|
if (!tree.isRootVisible() && |
|
|
tree.isExpanded(new TreePath(mod.getRoot()))) |
|
|
return new Point(x + ((level - 1) * rightChildIndent), y); |
|
|
return new Point(x + (level * rightChildIndent), y); |
|
|
} |
|
|
return getCellLocation(x, y + rowHeight, tree, mod, node, |
|
|
getNextVisibleNode(startNode)); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Recursively paints all elements of the tree Package private for use in |
|
|
* inner classes. |
|
|
* |
|
|
* @param g |
|
|
* the Graphics context in which to paint |
|
|
* @param indentation |
|
|
* of the current object |
|
|
* @param descent |
|
|
* is the number of elements drawn |
|
|
* @param depth |
|
|
* is the depth of the current object in the tree |
|
|
* @param tree |
|
|
* is the tree to draw to |
|
|
* @param mod |
|
|
* is the TreeModel we are using to draw |
|
|
* @param curr |
|
|
* is the current object to draw |
|
|
* @return int - current descent of the tree |
|
|
*/ |
|
|
int paintRecursive(Graphics g, int indentation, int descent, |
|
|
int depth, JTree tree, TreeModel mod, Object curr) |
|
|
{ |
|
|
Rectangle clip = tree.getVisibleRect(); |
|
|
if (indentation > clip.x + clip.width + rightChildIndent |
|
|
|| descent > clip.y + clip.height + getRowHeight()) |
|
|
return descent; |
|
|
|
|
|
TreePath path = new TreePath(getPathToRoot(curr, 0)); |
|
|
int halfHeight = getRowHeight() / 2; |
|
|
int halfWidth = rightChildIndent / 2; |
|
|
int y0 = descent + halfHeight; |
|
|
int heightOfLine = descent + halfHeight; |
|
|
int row = getRowForPath(tree, path); |
|
|
boolean isRootVisible = tree.isRootVisible(); |
|
|
boolean isExpanded = tree.isExpanded(path); |
|
|
boolean isLeaf = mod.isLeaf(curr); |
|
|
Rectangle bounds = getPathBounds(tree, path); |
|
|
Object root = mod.getRoot(); |
|
|
|
|
|
if (isLeaf) |
|
|
{ |
|
|
paintRow(g, clip, null, bounds, path, row, true, false, true); |
|
|
descent += getRowHeight(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (depth > 0 || isRootVisible) |
|
|
{ |
|
|
paintRow(g, clip, null, bounds, path, row, isExpanded, false, false); |
|
|
descent += getRowHeight(); |
|
|
y0 += halfHeight; |
|
|
} |
|
|
|
|
|
if (isExpanded) |
|
|
{ |
|
|
int max = mod.getChildCount(curr); |
|
|
for (int i = 0; i < max; i++) |
|
|
{ |
|
|
Object child = mod.getChild(curr, i); |
|
|
boolean childVis = tree.isVisible(new TreePath |
|
|
(getPathToRoot(child, 0))); |
|
|
int indent = indentation + rightChildIndent; |
|
|
if (!isRootVisible && depth == 0) |
|
|
indent = 0; |
|
|
else if (isRootVisible || |
|
|
(!isRootVisible && !curr.equals(root)) && childVis) |
|
|
{ |
|
|
g.setColor(getHashColor()); |
|
|
heightOfLine = descent + halfHeight; |
|
|
paintHorizontalLine(g, (JComponent) tree, heightOfLine, |
|
|
indentation + halfWidth, indentation + rightChildIndent); |
|
|
} |
|
|
|
|
|
descent = paintRecursive(g, indent, descent, depth + 1, |
|
|
tree, mod, child); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (isExpanded) |
|
|
if (y0 != heightOfLine |
|
|
&& (mod.getChildCount(curr) > 0 && |
|
|
tree.isVisible(new TreePath(getPathToRoot(mod.getChild |
|
|
(curr, 0), 0))))) |
|
|
{ |
|
|
g.setColor(getHashColor()); |
|
|
paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, y0, |
|
|
heightOfLine); |
|
|
} |
|
|
return descent; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Recursively paints all the control icons on the tree. Package private for |
|
|
* use in inner classes. |
|
|
* |
|
|
* @param g |
|
|
* the Graphics context in which to paint |
|
|
* @param indentation |
|
|
* of the current object |
|
|
* @param descent |
|
|
* is the number of elements drawn |
|
|
* @param depth |
|
|
* is the depth of the current object in the tree |
|
|
* @param tree |
|
|
* is the tree to draw to |
|
|
* @param mod |
|
|
* is the TreeModel we are using to draw |
|
|
* @param node |
|
|
* is the current object to draw |
|
|
* @return int current descent of the tree |
|
|
*/ |
|
|
int paintControlIcons(Graphics g, int indentation, int descent, |
|
|
int depth, JTree tree, TreeModel mod, |
|
|
Object node) |
|
|
{ |
|
|
int rowHeight = getRowHeight(); |
|
|
TreePath path = new TreePath(getPathToRoot(node, 0)); |
|
|
Icon icon = getCurrentControlIcon(path); |
|
|
|
|
|
Rectangle clip = tree.getVisibleRect(); |
|
|
if (indentation > clip.x + clip.width + rightChildIndent |
|
|
|| descent > clip.y + clip.height + getRowHeight()) |
|
|
return descent; |
|
|
|
|
|
if (mod.isLeaf(node)) |
|
|
descent += rowHeight; |
|
|
else |
|
|
{ |
|
|
if (!node.equals(mod.getRoot()) && |
|
|
(tree.isRootVisible() || getLevel(node) != 1)) |
|
|
{ |
|
|
int width = icon.getIconWidth(); |
|
|
int height = icon.getIconHeight() + 2; |
|
|
int posX = indentation - rightChildIndent; |
|
|
int posY = descent; |
|
|
if (width > rightChildIndent) |
|
|
posX -= gap; |
|
|
else posX += width/2; |
|
|
|
|
|
if (height < rowHeight) |
|
|
posY += height/2; |
|
|
|
|
|
icon.paintIcon(tree, g, posX, posY); |
|
|
} |
|
|
|
|
|
if (depth > 0 || tree.isRootVisible()) |
|
|
descent += rowHeight; |
|
|
|
|
|
if (tree.isExpanded(path)) |
|
|
{ |
|
|
int max = 0; |
|
|
if (!mod.isLeaf(node)) |
|
|
max = mod.getChildCount(node); |
|
|
|
|
|
for (int i = 0; i < max; i++) |
|
|
{ |
|
|
int indent = indentation + rightChildIndent; |
|
|
Object child = mod.getChild(node, i); |
|
|
if (depth == 0 && !tree.isRootVisible()) |
|
|
indent = 1; |
|
|
if (tree.isVisible(new TreePath(getPathToRoot(child, 0)))) |
|
|
descent = paintControlIcons(g, indent, descent, depth + 1, |
|
|
tree, mod, child); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return descent; |
|
|
} |
|
|
|
|
|
/** |
|
3091 |
* Returns true if the LookAndFeel implements the control icons. Package |
* Returns true if the LookAndFeel implements the control icons. Package |
3092 |
* private for use in inner classes. |
* private for use in inner classes. |
3093 |
* |
* |
3172 |
*/ |
*/ |
3173 |
Object getPreviousVisibleNode(Object node) |
Object getPreviousVisibleNode(Object node) |
3174 |
{ |
{ |
|
updateCurrentVisiblePath(); |
|
3175 |
if (currentVisiblePath != null) |
if (currentVisiblePath != null) |
3176 |
{ |
{ |
3177 |
Object[] nodes = currentVisiblePath.getPath(); |
Object[] nodes = currentVisiblePath.getPath(); |
3363 |
int getLevel(Object node) |
int getLevel(Object node) |
3364 |
{ |
{ |
3365 |
int count = -1; |
int count = -1; |
3366 |
|
|
3367 |
Object current = node; |
Object current = node; |
3368 |
|
|
3369 |
do |
if (treeModel != null) |
3370 |
{ |
{ |
3371 |
current = getParent(treeModel.getRoot(), current); |
Object root = treeModel.getRoot(); |
3372 |
count++; |
if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) |
3373 |
|
count--; |
3374 |
|
|
3375 |
|
do |
3376 |
|
{ |
3377 |
|
current = getParent(root, current); |
3378 |
|
count++; |
3379 |
|
} |
3380 |
|
while (current != null); |
3381 |
} |
} |
|
while (current != null); |
|
|
|
|
3382 |
return count; |
return count; |
3383 |
} |
} |
3384 |
|
|
3399 |
protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, |
protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, |
3400 |
int bottom) |
int bottom) |
3401 |
{ |
{ |
3402 |
|
// FIXME: Check if drawing a dashed line or not. |
3403 |
|
g.setColor(getHashColor()); |
3404 |
g.drawLine(x, top, x, bottom); |
g.drawLine(x, top, x, bottom); |
3405 |
} |
} |
3406 |
|
|
3421 |
protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, |
protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, |
3422 |
int right) |
int right) |
3423 |
{ |
{ |
3424 |
|
// FIXME: Check if drawing a dashed line or not. |
3425 |
|
g.setColor(getHashColor()); |
3426 |
g.drawLine(left, y, right, y); |
g.drawLine(left, y, right, y); |
3427 |
} |
} |
3428 |
|
|
3438 |
* @param x |
* @param x |
3439 |
* is the center position in x-direction |
* is the center position in x-direction |
3440 |
* @param y |
* @param y |
3441 |
* is the center position in y-direction FIXME what to do if x < |
* is the center position in y-direction |
|
* (icon.width / 2). Same with y |
|
3442 |
*/ |
*/ |
3443 |
protected void drawCentered(Component c, Graphics g, Icon icon, int x, int y) |
protected void drawCentered(Component c, Graphics g, Icon icon, int x, int y) |
3444 |
{ |
{ |
3445 |
int beginPositionX = x - icon.getIconWidth() / 2; |
x -= icon.getIconWidth() / 2; |
3446 |
int beginPositionY = y - icon.getIconHeight() / 2; |
y -= icon.getIconHeight() / 2; |
3447 |
icon.paintIcon(c, g, beginPositionX, beginPositionY); |
|
3448 |
|
if (x < 0) |
3449 |
|
x = 0; |
3450 |
|
if (y < 0) |
3451 |
|
y = 0; |
3452 |
|
|
3453 |
|
icon.paintIcon(c, g, x, y); |
3454 |
} |
} |
3455 |
|
|
3456 |
/** |
/** |
3463 |
*/ |
*/ |
3464 |
protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2) |
protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2) |
3465 |
{ |
{ |
3466 |
|
g.setColor(getHashColor()); |
3467 |
for (int i = x1; i < x2; i += 2) |
for (int i = x1; i < x2; i += 2) |
3468 |
g.drawLine(i, y, i + 1, y); |
g.drawLine(i, y, i + 1, y); |
3469 |
} |
} |
3478 |
*/ |
*/ |
3479 |
protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) |
protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) |
3480 |
{ |
{ |
3481 |
|
g.setColor(getHashColor()); |
3482 |
for (int i = y1; i < y2; i += 2) |
for (int i = y1; i < y2; i += 2) |
3483 |
g.drawLine(x, i, x, i + 1); |
g.drawLine(x, i, x, i + 1); |
3484 |
} |
} |
3503 |
boolean isExpanded, boolean hasBeenExpanded, |
boolean isExpanded, boolean hasBeenExpanded, |
3504 |
boolean isLeaf) |
boolean isLeaf) |
3505 |
{ |
{ |
3506 |
if (treeModel != null && hasControlIcons()) |
if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) |
3507 |
paintControlIcons(g, 0, 0, 0, tree, treeModel, path.getLastPathComponent()); |
{ |
3508 |
|
Icon icon = getCurrentControlIcon(path); |
3509 |
|
int iconW = icon.getIconWidth(); |
3510 |
|
int x = bounds.x - rightChildIndent + iconW/2; |
3511 |
|
if (x + iconW > bounds.x) |
3512 |
|
x = bounds.x - rightChildIndent - gap; |
3513 |
|
icon.paintIcon(tree, g, x, bounds.y + bounds.height/2 - icon.getIconHeight()/2); |
3514 |
|
} |
3515 |
} |
} |
3516 |
|
|
3517 |
/** |
/** |
3522 |
* @param g - the graphics configuration |
* @param g - the graphics configuration |
3523 |
* @param clipBounds - |
* @param clipBounds - |
3524 |
* @param insets - |
* @param insets - |
3525 |
* @param bounds - bounds of expand control |
* @param bounds - bounds of the cell |
3526 |
* @param path - path to draw control for |
* @param path - path to draw leg for |
3527 |
* @param row - row to draw control for |
* @param row - row to start drawing at |
3528 |
* @param isExpanded - is the row expanded |
* @param isExpanded - is the row expanded |
3529 |
* @param hasBeenExpanded - has the row already been expanded |
* @param hasBeenExpanded - has the row already been expanded |
3530 |
* @param isLeaf - is the path a leaf |
* @param isLeaf - is the path a leaf |
3535 |
boolean isExpanded, boolean hasBeenExpanded, |
boolean isExpanded, boolean hasBeenExpanded, |
3536 |
boolean isLeaf) |
boolean isLeaf) |
3537 |
{ |
{ |
3538 |
// FIXME: not implemented |
if (row != 0) |
3539 |
|
paintHorizontalLine(g, tree, bounds.y + bounds.height/2, bounds.x - gap - 2, |
3540 |
|
bounds.x); |
3541 |
} |
} |
3542 |
|
|
3543 |
/** |
/** |
3552 |
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, |
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, |
3553 |
Insets insets, TreePath path) |
Insets insets, TreePath path) |
3554 |
{ |
{ |
3555 |
// FIXME: not implemented |
int max = tree.getVisibleRowCount(); |
3556 |
|
for (int i = 0; i < max; i++) |
3557 |
|
{ |
3558 |
|
Object curr = path.getPathComponent(i); |
3559 |
|
TreePath currPath = new TreePath(getPathToRoot(curr, 0)); |
3560 |
|
if (!treeModel.isLeaf(curr) && tree.isExpanded(currPath)) |
3561 |
|
{ |
3562 |
|
Rectangle bounds = getPathBounds(tree, currPath); |
3563 |
|
Rectangle lastChildBounds = getPathBounds(tree, |
3564 |
|
new TreePath(getPathToRoot( |
3565 |
|
treeModel.getChild(curr, |
3566 |
|
treeModel.getChildCount(curr) - 1), |
3567 |
|
0))); |
3568 |
|
paintVerticalLine(g, tree, bounds.x + gap + 2, bounds.y + |
3569 |
|
bounds.height - 2, lastChildBounds.y + |
3570 |
|
lastChildBounds.height/2); |
3571 |
|
} |
3572 |
|
} |
3573 |
} |
} |
3574 |
|
|
3575 |
/** |
/** |
3600 |
{ |
{ |
3601 |
if (!validCachedPreferredSize) |
if (!validCachedPreferredSize) |
3602 |
updateCachedPreferredSize(); |
updateCachedPreferredSize(); |
3603 |
bounds.x += gap; |
|
3604 |
|
|
3605 |
|
paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); |
3606 |
|
|
3607 |
|
if (row != 0) |
3608 |
|
bounds.x += gap; |
3609 |
bounds.width = preferredSize.width + bounds.x; |
bounds.width = preferredSize.width + bounds.x; |
3610 |
|
|
3611 |
if (editingComponent != null && editingPath != null && isEditing(tree) |
if (editingComponent != null && editingPath != null && isEditing(tree) |
3651 |
boolean isLeaf) |
boolean isLeaf) |
3652 |
{ |
{ |
3653 |
Object node = path.getLastPathComponent(); |
Object node = path.getLastPathComponent(); |
3654 |
if (treeModel != null && (!isLeaf && !node.equals(treeModel.getRoot())) && |
return (!isLeaf && getLevel(node) != 0); |
|
(tree.isRootVisible() || getLevel(node) != 1)) |
|
|
return true; |
|
|
return false; |
|
3655 |
} |
} |
3656 |
|
|
3657 |
/** |
/** |
3664 |
return; |
return; |
3665 |
|
|
3666 |
Object next = treeModel.getRoot(); |
Object next = treeModel.getRoot(); |
3667 |
Rectangle bounds = getCellBounds(0, 0, next); |
TreePath rootPath = new TreePath(next); |
3668 |
boolean rootVisible = isRootVisible(); |
Rectangle bounds = getPathBounds(tree, rootPath); |
3669 |
|
|
3670 |
// If root is not a valid size to be visible, or is |
// If root is not a valid size to be visible, or is |
3671 |
// not visible and the tree is expanded, then the next node acts |
// not visible and the tree is expanded, then the next node acts |
3672 |
// as the root |
// as the root |
3673 |
if ((bounds.width == 0 && bounds.height == 0) || (!rootVisible |
if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible() |
3674 |
&& tree.isExpanded(new TreePath(next)))) |
&& tree.isExpanded(new TreePath(next)))) |
3675 |
|
{ |
3676 |
next = getNextNode(next); |
next = getNextNode(next); |
3677 |
|
rootPath = new TreePath(next); |
3678 |
|
} |
3679 |
|
|
3680 |
Object root = next; |
Object root = next; |
3681 |
TreePath current = null; |
TreePath current = null; |
3682 |
while (next != null) |
while (next != null) |
3683 |
{ |
{ |
3684 |
if (current == null) |
if (current == null) |
3685 |
current = new TreePath(next); |
current = rootPath; |
3686 |
else |
else |
3687 |
current = current.pathByAddingChild(next); |
current = current.pathByAddingChild(next); |
3688 |
|
|
3689 |
do |
do |
3690 |
{ |
{ |
3691 |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
TreePath path = new TreePath(getPathToRoot(next, 0)); |
3704 |
{ |
{ |
3705 |
next = getNextSibling(parent); |
next = getNextSibling(parent); |
3706 |
if (next == null) |
if (next == null) |
3707 |
parent = getParent(treeModel.getRoot(), next); |
parent = getParent(root, parent); |
3708 |
} |
} |
3709 |
} |
} |
3710 |
} |
} |
3714 |
} |
} |
3715 |
|
|
3716 |
currentVisiblePath = current; |
currentVisiblePath = current; |
3717 |
if (currentVisiblePath != null) |
tree.setVisibleRowCount(getRowCount(tree)); |
|
tree.setVisibleRowCount(currentVisiblePath.getPathCount()); |
|
|
else tree.setVisibleRowCount(0); |
|
3718 |
|
|
3719 |
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && |
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && |
3720 |
currentVisiblePath != null) |
currentVisiblePath != null) |