339 |
{ |
{ |
340 |
setModel(model); |
setModel(model); |
341 |
setSelectionModel(EmptySelectionModel.sharedInstance()); |
setSelectionModel(EmptySelectionModel.sharedInstance()); |
|
selectionModel.addTreeSelectionListener(selectionRedirector); |
|
342 |
setCellRenderer(new DefaultTreeCellRenderer()); |
setCellRenderer(new DefaultTreeCellRenderer()); |
343 |
updateUI(); |
updateUI(); |
344 |
} |
} |
563 |
} |
} |
564 |
|
|
565 |
/** |
/** |
566 |
* Returns the preferred viewport size.. |
* Returns the preferred viewport size. |
567 |
* |
* |
568 |
* @return the preferred size |
* @return the preferred size |
569 |
*/ |
*/ |
570 |
public Dimension getPreferredScrollableViewportSize() |
public Dimension getPreferredScrollableViewportSize() |
571 |
{ |
{ |
572 |
return null; |
return new Dimension (getPreferredSize().width, getVisibleRowCount()*getRowHeight()); |
573 |
} |
} |
574 |
|
|
575 |
public int getScrollableUnitIncrement(Rectangle visibleRect, |
public int getScrollableUnitIncrement(Rectangle visibleRect, |
584 |
return 1; |
return 1; |
585 |
} |
} |
586 |
|
|
587 |
public boolean getScrollableTracksViewportWidth() |
public boolean getScrollableTracksViewportWidth() |
588 |
{ |
{ |
589 |
return false; |
if (getParent() instanceof JViewport) |
590 |
} |
return ((JViewport) getParent()).getHeight() > getPreferredSize().height; |
591 |
|
return false; |
592 |
public boolean getScrollableTracksViewportHeight() |
} |
593 |
{ |
|
594 |
return false; |
public boolean getScrollableTracksViewportHeight() |
595 |
} |
{ |
596 |
|
if (getParent() instanceof JViewport) |
597 |
|
return ((JViewport) getParent()).getWidth() > getPreferredSize().width; |
598 |
|
return false; |
599 |
|
} |
600 |
|
|
601 |
/** |
/** |
602 |
* Adds a <code>TreeExpansionListener</code> object to the tree. |
* Adds a <code>TreeExpansionListener</code> object to the tree. |
663 |
*/ |
*/ |
664 |
public void addTreeSelectionListener(TreeSelectionListener listener) |
public void addTreeSelectionListener(TreeSelectionListener listener) |
665 |
{ |
{ |
666 |
listenerList.add(TreeSelectionListener.class, listener); |
listenerList.add(TreeSelectionListener.class, listener); |
667 |
} |
} |
668 |
|
|
669 |
/** |
/** |
695 |
protected void fireValueChanged(TreeSelectionEvent event) |
protected void fireValueChanged(TreeSelectionEvent event) |
696 |
{ |
{ |
697 |
TreeSelectionListener[] listeners = getTreeSelectionListeners(); |
TreeSelectionListener[] listeners = getTreeSelectionListeners(); |
698 |
|
|
699 |
for (int index = 0; index < listeners.length; ++index) |
for (int index = 0; index < listeners.length; ++index) |
700 |
listeners[index].valueChanged(event); |
listeners[index].valueChanged(event); |
701 |
} |
} |
1280 |
} |
} |
1281 |
|
|
1282 |
public void collapsePath(TreePath path) |
public void collapsePath(TreePath path) |
1283 |
{ |
{ |
1284 |
setExpandedState(path, false); |
try |
1285 |
} |
{ |
1286 |
|
fireTreeWillCollapse(path); |
1287 |
|
} |
1288 |
|
catch (ExpandVetoException ev) |
1289 |
|
{ |
1290 |
|
} |
1291 |
|
setExpandedState(path, false); |
1292 |
|
fireTreeCollapsed(path); |
1293 |
|
} |
1294 |
|
|
1295 |
public void collapseRow(int row) |
public void collapseRow(int row) |
1296 |
{ |
{ |
1304 |
} |
} |
1305 |
|
|
1306 |
public void expandPath(TreePath path) |
public void expandPath(TreePath path) |
1307 |
{ |
{ |
1308 |
// Don't expand if last path component is a leaf node. |
// Don't expand if last path component is a leaf node. |
1309 |
if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent()))) |
if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent()))) |
1310 |
return; |
return; |
1311 |
|
|
1312 |
setExpandedState(path, true); |
try |
1313 |
} |
{ |
1314 |
|
fireTreeWillExpand(path); |
1315 |
|
} |
1316 |
|
catch (ExpandVetoException ev) |
1317 |
|
{ |
1318 |
|
} |
1319 |
|
|
1320 |
|
setExpandedState(path, true); |
1321 |
|
fireTreeExpanded(path); |
1322 |
|
} |
1323 |
|
|
1324 |
public void expandRow(int row) |
public void expandRow(int row) |
1325 |
{ |
{ |
1526 |
private void doExpandParents(TreePath path, boolean state) |
private void doExpandParents(TreePath path, boolean state) |
1527 |
{ |
{ |
1528 |
TreePath parent = path.getParentPath(); |
TreePath parent = path.getParentPath(); |
1529 |
if (isExpanded(parent)) |
|
1530 |
{ |
if (!isExpanded(parent) && parent != null) |
|
nodeStates.put(path, state ? EXPANDED : COLLAPSED); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (parent != null) |
|
1531 |
doExpandParents(parent, false); |
doExpandParents(parent, false); |
1532 |
|
|
1533 |
nodeStates.put(path, state ? EXPANDED : COLLAPSED); |
nodeStates.put(path, state ? EXPANDED : COLLAPSED); |
1537 |
{ |
{ |
1538 |
if (path == null) |
if (path == null) |
1539 |
return; |
return; |
|
|
|
1540 |
TreePath parent = path.getParentPath(); |
TreePath parent = path.getParentPath(); |
1541 |
|
|
1542 |
doExpandParents(path, state); |
doExpandParents(path, state); |