| 1 |
0 |
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package net.wotonomy.ui.swing.components; |
| 20 |
|
|
| 21 |
|
import java.awt.BorderLayout; |
| 22 |
|
import java.awt.Component; |
| 23 |
|
import java.awt.Cursor; |
| 24 |
|
import java.awt.Dimension; |
| 25 |
|
import java.awt.GridBagConstraints; |
| 26 |
|
import java.awt.GridBagLayout; |
| 27 |
|
import java.awt.event.ActionEvent; |
| 28 |
|
import java.awt.event.ActionListener; |
| 29 |
|
import java.awt.event.MouseAdapter; |
| 30 |
|
import java.awt.event.MouseEvent; |
| 31 |
|
import java.util.Enumeration; |
| 32 |
|
import java.util.LinkedList; |
| 33 |
|
import java.util.List; |
| 34 |
|
import java.util.Stack; |
| 35 |
|
import java.util.Vector; |
| 36 |
|
|
| 37 |
|
import javax.swing.ComboBoxModel; |
| 38 |
|
import javax.swing.JButton; |
| 39 |
|
import javax.swing.JComboBox; |
| 40 |
|
import javax.swing.JComponent; |
| 41 |
|
import javax.swing.JList; |
| 42 |
|
import javax.swing.JPanel; |
| 43 |
|
import javax.swing.JScrollPane; |
| 44 |
|
import javax.swing.JToolBar; |
| 45 |
|
import javax.swing.JTree; |
| 46 |
|
import javax.swing.ListCellRenderer; |
| 47 |
|
import javax.swing.ListSelectionModel; |
| 48 |
|
import javax.swing.UIManager; |
| 49 |
|
import javax.swing.event.ListDataEvent; |
| 50 |
|
import javax.swing.event.ListDataListener; |
| 51 |
|
import javax.swing.event.ListSelectionEvent; |
| 52 |
|
import javax.swing.event.ListSelectionListener; |
| 53 |
|
import javax.swing.event.TreeModelEvent; |
| 54 |
|
import javax.swing.event.TreeModelListener; |
| 55 |
|
import javax.swing.event.TreeSelectionEvent; |
| 56 |
|
import javax.swing.event.TreeSelectionListener; |
| 57 |
|
import javax.swing.tree.DefaultMutableTreeNode; |
| 58 |
|
import javax.swing.tree.DefaultTreeCellRenderer; |
| 59 |
|
import javax.swing.tree.DefaultTreeModel; |
| 60 |
|
import javax.swing.tree.DefaultTreeSelectionModel; |
| 61 |
|
import javax.swing.tree.TreeCellRenderer; |
| 62 |
|
import javax.swing.tree.TreeModel; |
| 63 |
|
import javax.swing.tree.TreePath; |
| 64 |
|
import javax.swing.tree.TreeSelectionModel; |
| 65 |
|
|
| 66 |
|
import net.wotonomy.foundation.internal.WotonomyException; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
public class TreeChooser extends JPanel |
| 79 |
|
implements ActionListener, ListSelectionListener, |
| 80 |
|
TreeSelectionListener, TreeModelListener, ListCellRenderer |
| 81 |
|
{ |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
public static final String BACK = "Back"; |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
public static final String HOME = "Home"; |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
public static final String UP = "Up"; |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
public static final String SELECT = "Select"; |
| 106 |
|
|
| 107 |
|
protected JList contents; |
| 108 |
|
protected JComboBox pathCombo; |
| 109 |
|
protected JToolBar toolBar; |
| 110 |
|
|
| 111 |
|
protected TreeModel model; |
| 112 |
|
protected TreeSelectionModel selectionModel; |
| 113 |
|
protected TreeCellRenderer renderer; |
| 114 |
|
protected TreePath displayPath; |
| 115 |
|
protected Stack pathStack; |
| 116 |
|
protected int pathIndent; |
| 117 |
|
|
| 118 |
|
private ChooserComboBoxModel comboBoxModel; |
| 119 |
|
private JTree bogusJTree; |
| 120 |
|
private Dimension preferredSize; |
| 121 |
|
|
| 122 |
0 |
public TreeChooser() |
| 123 |
0 |
{ |
| 124 |
0 |
preferredSize = new Dimension( 300, 200 ); |
| 125 |
0 |
model = new DefaultTreeModel( new DefaultMutableTreeNode( "Root" ) ); |
| 126 |
0 |
displayPath = new TreePath( model.getRoot() ); |
| 127 |
0 |
selectionModel = new DefaultTreeSelectionModel(); |
| 128 |
0 |
renderer = new DefaultTreeCellRenderer(); |
| 129 |
0 |
pathStack = new Stack(); |
| 130 |
0 |
pathIndent = 0; |
| 131 |
0 |
comboBoxModel = new ChooserComboBoxModel( this ); |
| 132 |
|
|
| 133 |
0 |
bogusJTree = new JTree(); |
| 134 |
0 |
bogusJTree.setModel( model ); |
| 135 |
|
|
| 136 |
0 |
init(); |
| 137 |
0 |
displayHome(); |
| 138 |
|
|
| 139 |
0 |
stopListening(); |
| 140 |
0 |
startListening(); |
| 141 |
0 |
} |
| 142 |
|
|
| 143 |
|
public Dimension getPreferredSize() |
| 144 |
|
{ |
| 145 |
0 |
return preferredSize; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
protected void init() |
| 149 |
|
{ |
| 150 |
0 |
this.setLayout( new BorderLayout( 10, 10 ) ); |
| 151 |
|
|
| 152 |
0 |
contents = initList(); |
| 153 |
0 |
contents.getSelectionModel().setSelectionMode( |
| 154 |
0 |
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); |
| 155 |
|
|
| 156 |
|
|
| 157 |
0 |
JScrollPane scrollPane = new JScrollPane( contents ); |
| 158 |
0 |
scrollPane.setPreferredSize( new Dimension( 200, 150 ) ); |
| 159 |
0 |
this.add( scrollPane, BorderLayout.CENTER ); |
| 160 |
|
|
| 161 |
0 |
Component previewPane = initPreviewPane(); |
| 162 |
0 |
if ( previewPane != null ) |
| 163 |
|
{ |
| 164 |
0 |
this.add( previewPane, BorderLayout.EAST ); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
0 |
JPanel navigationPanel = new JPanel(); |
| 168 |
0 |
navigationPanel.setLayout( new BorderLayout( 10, 10 ) ); |
| 169 |
0 |
this.add( navigationPanel, BorderLayout.NORTH ); |
| 170 |
|
|
| 171 |
0 |
pathCombo = initComboBox(); |
| 172 |
0 |
if ( pathCombo != null ) |
| 173 |
|
{ |
| 174 |
0 |
pathCombo.setModel( comboBoxModel ); |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
0 |
JPanel panel = new JPanel(); |
| 179 |
0 |
panel.setLayout( new GridBagLayout() ); |
| 180 |
0 |
GridBagConstraints gbc = new GridBagConstraints(); |
| 181 |
0 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
| 182 |
0 |
gbc.weightx = 1.0; |
| 183 |
0 |
panel.add( pathCombo, gbc ); |
| 184 |
0 |
navigationPanel.add( panel, BorderLayout.CENTER ); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
0 |
Component toolBar = initToolBar(); |
| 188 |
0 |
if ( toolBar != null ) |
| 189 |
|
{ |
| 190 |
0 |
navigationPanel.add( toolBar, BorderLayout.EAST ); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
0 |
} |
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
protected Component initToolBar() |
| 201 |
|
{ |
| 202 |
0 |
JToolBar toolBar = new JToolBar(); |
| 203 |
0 |
toolBar.setFloatable( false ); |
| 204 |
|
JButton button; |
| 205 |
0 |
button = new JButton( UIManager.getIcon("FileChooser.upFolderIcon") ); |
| 206 |
0 |
button.setActionCommand( UP ); |
| 207 |
0 |
button.addActionListener( this ); |
| 208 |
0 |
toolBar.add( button ); |
| 209 |
0 |
button = new JButton( UIManager.getIcon("FileChooser.homeFolderIcon") ); |
| 210 |
0 |
button.setActionCommand( HOME ); |
| 211 |
0 |
button.addActionListener( this ); |
| 212 |
0 |
toolBar.add( button ); |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
0 |
return toolBar; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
protected Component initPreviewPane() |
| 230 |
|
{ |
| 231 |
0 |
return null; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
|
protected JComboBox initComboBox() |
| 241 |
|
{ |
| 242 |
0 |
JComboBox comboBox = new JComboBox(); |
| 243 |
0 |
comboBox.setRenderer( this ); |
| 244 |
0 |
return comboBox; |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| 251 |
|
|
| 252 |
|
|
| 253 |
|
|
| 254 |
|
protected JList initList() |
| 255 |
|
{ |
| 256 |
0 |
JList list = new JList(); |
| 257 |
0 |
list.setCellRenderer( this ); |
| 258 |
0 |
list.addMouseListener( new MouseAdapter() |
| 259 |
|
{ |
| 260 |
0 |
public void mouseClicked( MouseEvent evt ) |
| 261 |
|
{ |
| 262 |
0 |
if ( evt.getClickCount() > 1 ) |
| 263 |
|
{ |
| 264 |
0 |
actionPerformed( new ActionEvent( this, 0, SELECT ) ); |
| 265 |
|
} |
| 266 |
0 |
} |
| 267 |
|
}); |
| 268 |
0 |
return list; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
|
|
| 274 |
|
|
| 275 |
|
protected void startListening() |
| 276 |
|
{ |
| 277 |
0 |
model.addTreeModelListener( this ); |
| 278 |
0 |
selectionModel.addTreeSelectionListener( this ); |
| 279 |
0 |
contents.addListSelectionListener( this ); |
| 280 |
0 |
} |
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| 285 |
|
|
| 286 |
|
protected void stopListening() |
| 287 |
|
{ |
| 288 |
0 |
model.removeTreeModelListener( this ); |
| 289 |
0 |
selectionModel.removeTreeSelectionListener( this ); |
| 290 |
0 |
contents.removeListSelectionListener( this ); |
| 291 |
0 |
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
public TreeModel getModel() |
| 297 |
|
{ |
| 298 |
0 |
return model; |
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
|
| 302 |
|
|
| 303 |
|
|
| 304 |
|
public void setModel( TreeModel aTreeModel ) |
| 305 |
|
{ |
| 306 |
0 |
stopListening(); |
| 307 |
0 |
model = aTreeModel; |
| 308 |
0 |
bogusJTree.setModel( aTreeModel ); |
| 309 |
0 |
pathStack.removeAllElements(); |
| 310 |
0 |
startListening(); |
| 311 |
0 |
displayHome(); |
| 312 |
0 |
} |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
public TreeSelectionModel getSelectionModel() |
| 318 |
|
{ |
| 319 |
0 |
return selectionModel; |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
|
| 323 |
|
|
| 324 |
|
|
| 325 |
|
public void setSelectionModel( TreeSelectionModel aSelectionModel ) |
| 326 |
|
{ |
| 327 |
0 |
selectionModel = aSelectionModel; |
| 328 |
0 |
if ( aSelectionModel.getSelectionMode() == |
| 329 |
0 |
TreeSelectionModel.SINGLE_TREE_SELECTION ) |
| 330 |
|
{ |
| 331 |
0 |
contents.getSelectionModel().setSelectionMode( |
| 332 |
0 |
ListSelectionModel.SINGLE_SELECTION ); |
| 333 |
0 |
} |
| 334 |
|
else |
| 335 |
|
{ |
| 336 |
0 |
contents.getSelectionModel().setSelectionMode( |
| 337 |
0 |
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); |
| 338 |
|
} |
| 339 |
0 |
updateSelection(); |
| 340 |
0 |
} |
| 341 |
|
|
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
|
public TreeCellRenderer getRenderer() |
| 346 |
|
{ |
| 347 |
0 |
return renderer; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
| 353 |
|
public void setRenderer( TreeCellRenderer aRenderer ) |
| 354 |
|
{ |
| 355 |
0 |
renderer = aRenderer; |
| 356 |
0 |
updateContents(); |
| 357 |
0 |
} |
| 358 |
|
|
| 359 |
|
|
| 360 |
|
|
| 361 |
|
|
| 362 |
|
|
| 363 |
|
public void displayHome() |
| 364 |
|
{ |
| 365 |
0 |
setDisplayPath( null ); |
| 366 |
0 |
} |
| 367 |
|
|
| 368 |
|
|
| 369 |
|
|
| 370 |
|
|
| 371 |
|
public void displayParent() |
| 372 |
|
{ |
| 373 |
0 |
setDisplayPath( displayPath.getParentPath() ); |
| 374 |
0 |
} |
| 375 |
|
|
| 376 |
|
|
| 377 |
|
|
| 378 |
|
|
| 379 |
|
|
| 380 |
|
public void displayPrevious() |
| 381 |
|
{ |
| 382 |
0 |
if ( pathStack.empty() ) |
| 383 |
|
{ |
| 384 |
0 |
displayHome(); |
| 385 |
0 |
} |
| 386 |
|
else |
| 387 |
|
{ |
| 388 |
0 |
setDisplayPathDirect( (TreePath) pathStack.pop() ); |
| 389 |
0 |
updateContents(); |
| 390 |
|
} |
| 391 |
0 |
} |
| 392 |
|
|
| 393 |
|
|
| 394 |
|
|
| 395 |
|
|
| 396 |
|
|
| 397 |
|
|
| 398 |
|
public void setDisplayPath( TreePath aPath ) |
| 399 |
|
{ |
| 400 |
0 |
if ( aPath == null ) |
| 401 |
|
{ |
| 402 |
0 |
aPath = new TreePath( getModel().getRoot() ); |
| 403 |
|
} |
| 404 |
0 |
if ( ! displayPath.equals ( aPath ) ) |
| 405 |
|
{ |
| 406 |
0 |
pathStack.push( displayPath ); |
| 407 |
0 |
setDisplayPathDirect( aPath ); |
| 408 |
|
} |
| 409 |
0 |
updateContents(); |
| 410 |
0 |
} |
| 411 |
|
|
| 412 |
|
|
| 413 |
|
|
| 414 |
|
|
| 415 |
|
|
| 416 |
|
protected void setDisplayPathDirect( TreePath aPath ) |
| 417 |
|
{ |
| 418 |
0 |
displayPath = aPath; |
| 419 |
0 |
} |
| 420 |
|
|
| 421 |
|
|
| 422 |
|
|
| 423 |
|
|
| 424 |
|
public TreePath getDisplayPath() |
| 425 |
|
{ |
| 426 |
0 |
return displayPath; |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 430 |
|
|
| 431 |
|
|
| 432 |
|
|
| 433 |
|
protected void updateContents() |
| 434 |
|
{ |
| 435 |
0 |
stopListening(); |
| 436 |
|
|
| 437 |
|
|
| 438 |
0 |
comboBoxModel.fireContentsChanged(); |
| 439 |
|
|
| 440 |
|
|
| 441 |
0 |
Object displayedObject = displayPath.getLastPathComponent(); |
| 442 |
|
|
| 443 |
|
|
| 444 |
|
|
| 445 |
|
|
| 446 |
|
|
| 447 |
0 |
int count = model.getChildCount( displayedObject ); |
| 448 |
0 |
Object[] children = new Object[ count ]; |
| 449 |
0 |
for ( int i = 0; i < count; i++ ) |
| 450 |
|
{ |
| 451 |
0 |
children[i] = model.getChild( displayedObject, i ); |
| 452 |
|
} |
| 453 |
0 |
contents.setListData( children ); |
| 454 |
|
|
| 455 |
0 |
startListening(); |
| 456 |
|
|
| 457 |
|
|
| 458 |
0 |
updateSelection(); |
| 459 |
0 |
} |
| 460 |
|
|
| 461 |
|
|
| 462 |
|
|
| 463 |
|
|
| 464 |
|
|
| 465 |
|
public void updateSelection() |
| 466 |
|
{ |
| 467 |
|
int index; |
| 468 |
0 |
Object last = displayPath.getLastPathComponent(); |
| 469 |
0 |
TreePath[] selectionPaths = selectionModel.getSelectionPaths(); |
| 470 |
0 |
if ( selectionPaths != null ) |
| 471 |
|
{ |
| 472 |
0 |
List selectedIndices = new LinkedList(); |
| 473 |
0 |
for ( int i = 0; i < selectionPaths.length; i++ ) |
| 474 |
|
{ |
| 475 |
0 |
if ( displayPath.equals( selectionPaths[i].getParentPath() ) ) |
| 476 |
|
{ |
| 477 |
0 |
index = getModel().getIndexOfChild( |
| 478 |
0 |
last, selectionPaths[i].getLastPathComponent() ); |
| 479 |
0 |
if ( index != -1 ) |
| 480 |
|
{ |
| 481 |
0 |
selectedIndices.add( new Integer( index ) ); |
| 482 |
0 |
} |
| 483 |
|
else |
| 484 |
|
{ |
| 485 |
0 |
throw new WotonomyException( |
| 486 |
0 |
"Could not find child of displayed node." ); |
| 487 |
|
} |
| 488 |
|
} |
| 489 |
|
} |
| 490 |
0 |
int[] selected = new int[ selectedIndices.size() ]; |
| 491 |
0 |
for ( int i = 0; i < selected.length; i++ ) |
| 492 |
|
{ |
| 493 |
0 |
selected[i] = ((Integer)selectedIndices.get(i)).intValue(); |
| 494 |
|
} |
| 495 |
0 |
stopListening(); |
| 496 |
0 |
contents.setSelectedIndices( selected ); |
| 497 |
0 |
startListening(); |
| 498 |
|
} |
| 499 |
0 |
} |
| 500 |
|
|
| 501 |
|
|
| 502 |
|
|
| 503 |
|
public void treeNodesChanged( TreeModelEvent evt ) |
| 504 |
|
{ |
| 505 |
|
|
| 506 |
|
|
| 507 |
|
|
| 508 |
|
|
| 509 |
|
|
| 510 |
|
|
| 511 |
0 |
updateContents(); |
| 512 |
|
|
| 513 |
|
|
| 514 |
|
|
| 515 |
|
|
| 516 |
|
|
| 517 |
|
|
| 518 |
|
|
| 519 |
0 |
} |
| 520 |
|
|
| 521 |
|
public void treeNodesInserted( TreeModelEvent evt ) |
| 522 |
|
{ |
| 523 |
|
|
| 524 |
0 |
} |
| 525 |
|
|
| 526 |
|
public void treeNodesRemoved( TreeModelEvent evt ) |
| 527 |
|
{ |
| 528 |
|
|
| 529 |
0 |
} |
| 530 |
|
|
| 531 |
|
public void treeStructureChanged( TreeModelEvent evt ) |
| 532 |
|
{ |
| 533 |
0 |
if ( ( evt.getTreePath().equals( displayPath ) ) |
| 534 |
0 |
|| ( evt.getTreePath().isDescendant( displayPath ) ) ) |
| 535 |
|
{ |
| 536 |
|
|
| 537 |
|
} |
| 538 |
|
|
| 539 |
0 |
displayHome(); |
| 540 |
0 |
} |
| 541 |
|
|
| 542 |
|
|
| 543 |
|
|
| 544 |
|
|
| 545 |
|
|
| 546 |
|
|
| 547 |
|
|
| 548 |
|
|
| 549 |
|
public void valueChanged( TreeSelectionEvent evt ) |
| 550 |
|
{ |
| 551 |
0 |
updateSelection(); |
| 552 |
0 |
} |
| 553 |
|
|
| 554 |
|
|
| 555 |
|
|
| 556 |
|
|
| 557 |
|
|
| 558 |
|
|
| 559 |
|
|
| 560 |
|
|
| 561 |
|
public void valueChanged( ListSelectionEvent evt ) |
| 562 |
|
{ |
| 563 |
0 |
if ( ! evt.getValueIsAdjusting() ) |
| 564 |
|
{ |
| 565 |
0 |
Object last = displayPath.getLastPathComponent(); |
| 566 |
0 |
int[] selection = contents.getSelectedIndices(); |
| 567 |
0 |
TreePath[] selectionPaths = new TreePath[ selection.length ]; |
| 568 |
0 |
for ( int i = 0; i < selection.length; i++ ) |
| 569 |
|
{ |
| 570 |
0 |
selectionPaths[i] = displayPath.pathByAddingChild( |
| 571 |
0 |
getModel().getChild( last, selection[i] ) ); |
| 572 |
|
} |
| 573 |
0 |
selectionModel.setSelectionPaths( selectionPaths ); |
| 574 |
|
} |
| 575 |
|
|
| 576 |
0 |
} |
| 577 |
|
|
| 578 |
|
|
| 579 |
|
|
| 580 |
|
|
| 581 |
|
|
| 582 |
|
|
| 583 |
|
public Component getListCellRendererComponent( |
| 584 |
|
JList list, |
| 585 |
|
Object value, |
| 586 |
|
int index, |
| 587 |
|
boolean isSelected, |
| 588 |
|
boolean cellHasFocus ) |
| 589 |
|
{ |
| 590 |
0 |
boolean isLeaf = ( model.isLeaf( value ) ); |
| 591 |
|
|
| 592 |
0 |
bogusJTree.setForeground( list.getForeground() ); |
| 593 |
0 |
bogusJTree.setBackground( list.getBackground() ); |
| 594 |
|
|
| 595 |
0 |
JComponent result = (JComponent) renderer.getTreeCellRendererComponent( |
| 596 |
0 |
bogusJTree, value, isSelected, (list != contents), |
| 597 |
0 |
isLeaf, index, cellHasFocus ); |
| 598 |
|
|
| 599 |
|
|
| 600 |
|
|
| 601 |
|
|
| 602 |
|
|
| 603 |
|
|
| 604 |
|
|
| 605 |
|
|
| 606 |
|
|
| 607 |
|
|
| 608 |
|
|
| 609 |
|
|
| 610 |
0 |
return result; |
| 611 |
|
} |
| 612 |
|
|
| 613 |
|
|
| 614 |
|
|
| 615 |
|
public void actionPerformed( ActionEvent evt ) |
| 616 |
|
{ |
| 617 |
0 |
String command = evt.getActionCommand(); |
| 618 |
|
|
| 619 |
0 |
if ( HOME.equals( command ) ) |
| 620 |
|
{ |
| 621 |
0 |
displayHome(); |
| 622 |
0 |
} |
| 623 |
|
else |
| 624 |
0 |
if ( UP.equals( command ) ) |
| 625 |
|
{ |
| 626 |
0 |
displayParent(); |
| 627 |
0 |
} |
| 628 |
|
else |
| 629 |
0 |
if ( BACK.equals( command ) ) |
| 630 |
|
{ |
| 631 |
0 |
displayPrevious(); |
| 632 |
0 |
} |
| 633 |
|
else |
| 634 |
0 |
if ( SELECT.equals( command ) ) |
| 635 |
|
{ |
| 636 |
0 |
Cursor oldCursor = getCursor(); |
| 637 |
0 |
setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); |
| 638 |
|
|
| 639 |
0 |
int index = contents.getSelectedIndex(); |
| 640 |
|
|
| 641 |
0 |
if ( index != -1 ) |
| 642 |
|
{ |
| 643 |
0 |
Object parent = displayPath.getLastPathComponent(); |
| 644 |
0 |
Object child = getModel().getChild( parent, index ); |
| 645 |
|
|
| 646 |
0 |
if ( getModel().getChildCount( child ) > 0 ) |
| 647 |
|
{ |
| 648 |
|
|
| 649 |
0 |
setDisplayPath( displayPath.pathByAddingChild( child ) ); |
| 650 |
|
} |
| 651 |
|
} |
| 652 |
|
|
| 653 |
0 |
setCursor( oldCursor ); |
| 654 |
|
} |
| 655 |
|
|
| 656 |
0 |
} |
| 657 |
|
|
| 658 |
|
private class ChooserComboBoxModel implements ComboBoxModel |
| 659 |
|
{ |
| 660 |
|
TreeChooser treeChooser; |
| 661 |
|
Vector listeners; |
| 662 |
|
|
| 663 |
0 |
ChooserComboBoxModel( TreeChooser aTreeChooser ) |
| 664 |
0 |
{ |
| 665 |
0 |
treeChooser = aTreeChooser; |
| 666 |
0 |
listeners = new Vector(); |
| 667 |
0 |
} |
| 668 |
|
|
| 669 |
|
public int getSize() |
| 670 |
|
{ |
| 671 |
0 |
return treeChooser.displayPath.getPathCount(); |
| 672 |
|
} |
| 673 |
|
|
| 674 |
|
public Object getElementAt(int index) |
| 675 |
|
{ |
| 676 |
0 |
return treeChooser.displayPath.getPathComponent( index ); |
| 677 |
|
} |
| 678 |
|
|
| 679 |
|
public Object getSelectedItem() |
| 680 |
|
{ |
| 681 |
0 |
return treeChooser.displayPath.getLastPathComponent(); |
| 682 |
|
} |
| 683 |
|
|
| 684 |
|
public void setSelectedItem(Object anItem) |
| 685 |
|
{ |
| 686 |
0 |
if ( ! ( |
| 687 |
0 |
treeChooser.displayPath.getLastPathComponent().equals( anItem ) ) ) |
| 688 |
|
{ |
| 689 |
0 |
Object[] items = treeChooser.displayPath.getPath(); |
| 690 |
0 |
TreePath path = new TreePath( getModel().getRoot() ); |
| 691 |
0 |
for ( int i = 1; i < items.length; i++ ) |
| 692 |
|
{ |
| 693 |
0 |
if ( path.getLastPathComponent() == anItem ) |
| 694 |
|
{ |
| 695 |
0 |
treeChooser.setDisplayPath( path ); |
| 696 |
0 |
return; |
| 697 |
|
} |
| 698 |
0 |
path = path.pathByAddingChild( items[i] ); |
| 699 |
|
} |
| 700 |
|
} |
| 701 |
0 |
} |
| 702 |
|
|
| 703 |
|
public void addListDataListener(ListDataListener l) |
| 704 |
|
{ |
| 705 |
0 |
listeners.add( l ); |
| 706 |
0 |
} |
| 707 |
|
|
| 708 |
|
public void removeListDataListener(ListDataListener l) |
| 709 |
|
{ |
| 710 |
0 |
listeners.remove( l ); |
| 711 |
0 |
} |
| 712 |
|
|
| 713 |
|
public void fireContentsChanged() |
| 714 |
|
{ |
| 715 |
0 |
Enumeration e = listeners.elements(); |
| 716 |
0 |
while ( e.hasMoreElements() ) |
| 717 |
|
{ |
| 718 |
0 |
((ListDataListener)e.nextElement()).contentsChanged( |
| 719 |
0 |
new ListDataEvent( |
| 720 |
0 |
this, ListDataEvent.CONTENTS_CHANGED, 0, getSize() ) ); |
| 721 |
0 |
} |
| 722 |
0 |
} |
| 723 |
|
} |
| 724 |
|
|
| 725 |
|
} |
| 726 |
|
|
| 727 |
|
|