678 |
*/ |
*/ |
679 |
public int getRowCount(JTree tree) |
public int getRowCount(JTree tree) |
680 |
{ |
{ |
681 |
// FIXME: check visibility |
DefaultMutableTreeNode node = ((DefaultMutableTreeNode) (tree.getModel()) |
682 |
return treeState.getRowCount(); |
.getRoot()); |
683 |
|
int count = 0; |
684 |
|
|
685 |
|
while (node != null) |
686 |
|
{ |
687 |
|
count++; |
688 |
|
node = getNextVisibleNode(node); |
689 |
|
} |
690 |
|
|
691 |
|
return count; |
692 |
} |
} |
693 |
|
|
694 |
/** |
/** |
1295 |
*/ |
*/ |
1296 |
public Dimension getPreferredSize(JComponent c, boolean checkConsistancy) |
public Dimension getPreferredSize(JComponent c, boolean checkConsistancy) |
1297 |
{ |
{ |
1298 |
// FIXME: not implemented |
// FIXME: checkConsistancy not implemented, c not used |
1299 |
return new Dimension(200, 900); |
DefaultMutableTreeNode node = ((DefaultMutableTreeNode) (tree.getModel()) |
1300 |
|
.getRoot()); |
1301 |
|
int maxWidth = 0; |
1302 |
|
int count = 0; |
1303 |
|
if (node != null) |
1304 |
|
{ |
1305 |
|
maxWidth = (int) (getCellBounds(0, 0, node).getWidth()); |
1306 |
|
while (node != null) |
1307 |
|
{ |
1308 |
|
count++; |
1309 |
|
DefaultMutableTreeNode nextNode = node.getNextNode(); |
1310 |
|
if (nextNode != null) |
1311 |
|
maxWidth = Math.max(maxWidth, (int) (getCellBounds(0, 0, nextNode) |
1312 |
|
.getWidth())); |
1313 |
|
node = nextNode; |
1314 |
|
} |
1315 |
|
} |
1316 |
|
|
1317 |
|
return new Dimension(maxWidth, (getRowHeight() * count)); |
1318 |
} |
} |
1319 |
|
|
1320 |
/** |
/** |
1327 |
public Dimension getMinimumSize(JComponent c) |
public Dimension getMinimumSize(JComponent c) |
1328 |
{ |
{ |
1329 |
// FIXME: not implemented |
// FIXME: not implemented |
1330 |
return new Dimension(200, 900); |
return getPreferredSize(c); |
1331 |
} |
} |
1332 |
|
|
1333 |
/** |
/** |
1340 |
public Dimension getMaximumSize(JComponent c) |
public Dimension getMaximumSize(JComponent c) |
1341 |
{ |
{ |
1342 |
// FIXME: not implemented |
// FIXME: not implemented |
1343 |
return new Dimension(200, 900); |
return getPreferredSize(c); |
1344 |
} |
} |
1345 |
|
|
1346 |
/** |
/** |
2378 |
*/ |
*/ |
2379 |
private Rectangle getCellBounds(int x, int y, Object cell) |
private Rectangle getCellBounds(int x, int y, Object cell) |
2380 |
{ |
{ |
2381 |
String s = cell.toString(); |
if (cell != null) |
2382 |
Font f = tree.getFont(); |
{ |
2383 |
FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont()); |
String s = cell.toString(); |
2384 |
|
Font f = tree.getFont(); |
2385 |
|
FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont()); |
2386 |
|
|
2387 |
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), fm |
return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), |
2388 |
.getHeight()); |
fm.getHeight()); |
2389 |
|
} |
2390 |
|
return null; |
2391 |
} |
} |
2392 |
|
|
2393 |
/** |
/** |
2485 |
int halfHeight = getRowHeight() / 2; |
int halfHeight = getRowHeight() / 2; |
2486 |
int halfWidth = rightChildIndent / 2; |
int halfWidth = rightChildIndent / 2; |
2487 |
int y0 = descent + halfHeight; |
int y0 = descent + halfHeight; |
2488 |
|
int heightOfLine = descent + halfHeight; |
2489 |
|
|
2490 |
if (mod.isLeaf(curr)) |
if (mod.isLeaf(curr)) |
2491 |
{ |
{ |
2506 |
for (int i = 0; i < max; ++i) |
for (int i = 0; i < max; ++i) |
2507 |
{ |
{ |
2508 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
2509 |
g.drawLine(indentation + halfWidth, descent + halfHeight, |
heightOfLine = descent + halfHeight; |
2510 |
indentation + rightChildIndent, descent + halfHeight); |
g.drawLine(indentation + halfWidth, heightOfLine, |
2511 |
|
indentation + rightChildIndent, heightOfLine); |
2512 |
descent = paintRecursive(g, indentation + rightChildIndent, |
descent = paintRecursive(g, indentation + rightChildIndent, |
2513 |
descent, i, depth + 1, tree, mod, mod.getChild(curr, i)); |
descent, i, depth + 1, tree, mod, mod.getChild(curr, i)); |
2514 |
} |
} |
2515 |
} |
} |
2516 |
|
|
|
int y1 = descent - halfHeight; |
|
|
|
|
2517 |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) |
2518 |
.getPath()))) |
.getPath()))) |
2519 |
if (y0 != y1) |
if (y0 != heightOfLine) |
2520 |
{ |
{ |
2521 |
g.setColor(getHashColor()); |
g.setColor(getHashColor()); |
2522 |
g |
g.drawLine(indentation + halfWidth, y0, indentation + halfWidth, |
2523 |
.drawLine(indentation + halfWidth, y0, indentation |
heightOfLine); |
|
+ halfWidth, y1); |
|
2524 |
} |
} |
2525 |
return descent; |
return descent; |
2526 |
} |
} |