1223 |
tree = (JTree) c; |
tree = (JTree) c; |
1224 |
setModel(tree.getModel()); |
setModel(tree.getModel()); |
1225 |
tree.setRootVisible(true); |
tree.setRootVisible(true); |
1226 |
|
tree.expandPath(new TreePath(((DefaultMutableTreeNode) |
1227 |
|
(tree.getModel()).getRoot()).getPath())); |
1228 |
treeSelectionModel = tree.getSelectionModel(); |
treeSelectionModel = tree.getSelectionModel(); |
1229 |
installListeners(); |
installListeners(); |
1230 |
installKeyboardActions(); |
installKeyboardActions(); |
1276 |
TreeModel mod = tree.getModel(); |
TreeModel mod = tree.getModel(); |
1277 |
g.translate(10, 10); |
g.translate(10, 10); |
1278 |
paintRecursive(g, 0, 0, 0, 0, tree, mod, mod.getRoot()); |
paintRecursive(g, 0, 0, 0, 0, tree, mod, mod.getRoot()); |
1279 |
|
paintControlIcons(g, 0, 0, 0, 0, tree, mod, mod.getRoot()); |
1280 |
g.translate(-10, -10); |
g.translate(-10, -10); |
1281 |
} |
} |
1282 |
|
|
2535 |
if (hasIcons) |
if (hasIcons) |
2536 |
{ |
{ |
2537 |
li.paintIcon(c, g, x, y + 2); |
li.paintIcon(c, g, x, y + 2); |
2538 |
x += (li.getIconWidth() + 4); |
x += li.getIconWidth() + 4; |
2539 |
} |
} |
2540 |
rendererPane.paintComponent(g, c, tree, |
rendererPane.paintComponent(g, c, tree, |
2541 |
getCellBounds(x, y, leaf)); |
getCellBounds(x, y, leaf)); |
2660 |
int halfWidth = rightChildIndent / 2; |
int halfWidth = rightChildIndent / 2; |
2661 |
int y0 = descent + halfHeight; |
int y0 = descent + halfHeight; |
2662 |
int heightOfLine = descent + halfHeight; |
int heightOfLine = descent + halfHeight; |
2663 |
|
|
2664 |
if (mod.isLeaf(curr)) |
if (mod.isLeaf(curr)) |
2665 |
{ |
{ |
2666 |
paintLeaf(g, indentation, descent, tree, curr); |
paintLeaf(g, indentation + 4, descent, tree, curr); |
2667 |
descent += getRowHeight(); |
descent += getRowHeight(); |
2668 |
} |
} |
2669 |
else |
else |
2670 |
{ |
{ |
2671 |
if (depth > 0 || tree.isRootVisible()) |
if (depth > 0 || tree.isRootVisible()) |
2672 |
{ |
{ |
2673 |
paintNonLeaf(g, indentation, descent, tree, curr); |
paintNonLeaf(g, indentation + 4, descent, tree, curr); |
2674 |
descent += getRowHeight(); |
descent += getRowHeight(); |
2675 |
y0 += halfHeight; |
y0 += halfHeight; |
2676 |
} |
} |
2678 |
int max = mod.getChildCount(curr); |
int max = mod.getChildCount(curr); |
2679 |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
2680 |
.getPath()))) |
.getPath()))) |
2681 |
|
{ |
2682 |
for (int i = 0; i < max; ++i) |
for (int i = 0; i < max; ++i) |
2683 |
{ |
{ |
2684 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
2685 |
heightOfLine = descent + halfHeight; |
heightOfLine = descent + halfHeight; |
2686 |
g.drawLine(indentation + halfWidth, heightOfLine, |
g.drawLine(indentation + halfWidth, heightOfLine, |
2687 |
indentation + rightChildIndent, heightOfLine); |
indentation + rightChildIndent, heightOfLine); |
2688 |
|
|
2689 |
descent = paintRecursive(g, indentation + rightChildIndent, |
descent = paintRecursive(g, indentation + rightChildIndent, |
2690 |
descent, i, depth + 1, tree, mod, mod.getChild(curr, i)); |
descent, i, depth + 1, tree, mod, mod.getChild(curr, i)); |
2691 |
} |
} |
2692 |
|
} |
2693 |
} |
} |
2694 |
|
|
2695 |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
2700 |
g.drawLine(indentation + halfWidth, y0, indentation + halfWidth, |
g.drawLine(indentation + halfWidth, y0, indentation + halfWidth, |
2701 |
heightOfLine); |
heightOfLine); |
2702 |
} |
} |
2703 |
|
|
2704 |
|
return descent; |
2705 |
|
} |
2706 |
|
|
2707 |
|
/** |
2708 |
|
* Recursively paints all the control icons on the tree. |
2709 |
|
* |
2710 |
|
* @param g the Graphics context in which to paint |
2711 |
|
* @param indentation of the current object |
2712 |
|
* @param descent is the number of elements drawn |
2713 |
|
* @param childNumber is the index of the current child in the tree |
2714 |
|
* @param depth is the depth of the current object in the tree |
2715 |
|
* @param tree is the tree to draw to |
2716 |
|
* @param mod is the TreeModel we are using to draw |
2717 |
|
* @param curr is the current object to draw |
2718 |
|
* |
2719 |
|
* @return int - current descent of the tree |
2720 |
|
*/ |
2721 |
|
private int paintControlIcons(Graphics g, int indentation, int descent, |
2722 |
|
int childNumber, int depth, JTree tree, TreeModel mod, Object node) |
2723 |
|
{ |
2724 |
|
int h = descent; |
2725 |
|
int rowHeight = getRowHeight(); |
2726 |
|
Icon ei = UIManager.getLookAndFeelDefaults(). |
2727 |
|
getIcon("Tree.expandedIcon"); |
2728 |
|
Icon ci = UIManager.getLookAndFeelDefaults(). |
2729 |
|
getIcon("Tree.collapsedIcon"); |
2730 |
|
Rectangle clip = g.getClipBounds(); |
2731 |
|
if (ci == null || ei == null || indentation > clip.x + clip.width + |
2732 |
|
rightChildIndent || descent > clip.y + clip.height + |
2733 |
|
getRowHeight()) |
2734 |
|
return descent; |
2735 |
|
|
2736 |
|
if (mod.isLeaf(node)) |
2737 |
|
{ |
2738 |
|
descent += rowHeight; |
2739 |
|
} |
2740 |
|
else |
2741 |
|
{ |
2742 |
|
if (depth > 0 || tree.isRootVisible()) |
2743 |
|
{ |
2744 |
|
descent += rowHeight; |
2745 |
|
} |
2746 |
|
|
2747 |
|
int max = mod.getChildCount(node); |
2748 |
|
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node) |
2749 |
|
.getPath()))) |
2750 |
|
{ |
2751 |
|
ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h); |
2752 |
|
for (int i = 0; i < max; ++i) |
2753 |
|
{ |
2754 |
|
descent = paintControlIcons(g, indentation + rightChildIndent, |
2755 |
|
descent, i, depth + 1, tree, mod, mod.getChild(node, i)); |
2756 |
|
} |
2757 |
|
} |
2758 |
|
else |
2759 |
|
ci.paintIcon(tree, g, indentation - rightChildIndent - 3, |
2760 |
|
descent - getRowHeight()); |
2761 |
|
} |
2762 |
|
|
2763 |
return descent; |
return descent; |
2764 |
} |
} |
2765 |
} // BasicTreeUI |
} // BasicTreeUI |