< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java

Print this page



 413         if(this.largeModel != largeModel) {
 414             completeEditing();
 415             this.largeModel = largeModel;
 416             treeState = createLayoutCache();
 417             configureLayoutCache();
 418             updateLayoutCacheExpandedNodesIfNecessary();
 419             updateSize();
 420         }
 421     }
 422 
 423     /**
 424      * Returns {@code true} if large model is set.
 425      *
 426      * @return {@code true} if large model is set
 427      */
 428     protected boolean isLargeModel() {
 429         return largeModel;
 430     }
 431 
 432     /**
 433      * Sets the row height, this is forwarded to the treeState.

 434      *
 435      * @param rowHeight the row height
 436      */
 437     protected void setRowHeight(int rowHeight) {
 438         completeEditing();
 439         if(treeState != null) {
 440             setLargeModel(tree.isLargeModel());
 441             treeState.setRowHeight(rowHeight);
 442             updateSize();
 443         }
 444     }
 445 
 446     /**
 447      * Returns the row height.


 448      *
 449      * @return the row height
 450      */
 451     protected int getRowHeight() {
 452         return (tree == null) ? -1 : tree.getRowHeight();
 453     }
 454 
 455     /**
 456      * Sets the {@code TreeCellRenderer} to {@code tcr}. This invokes
 457      * {@code updateRenderer}.
 458      *
 459      * @param tcr the new value
 460      */
 461     protected void setCellRenderer(TreeCellRenderer tcr) {
 462         completeEditing();
 463         updateRenderer();
 464         if(treeState != null) {
 465             treeState.invalidateSizes();
 466             updateSize();
 467         }
 468     }
 469 
 470     /**
 471      * Return {@code currentCellRenderer}, which will either be the trees
 472      * renderer, or {@code defaultCellRenderer}, which ever wasn't null.
 473      *
 474      * @return an instance of {@code TreeCellRenderer}
 475      */
 476     protected TreeCellRenderer getCellRenderer() {
 477         return currentCellRenderer;
 478     }
 479 
 480     /**
 481      * Sets the {@code TreeModel}.
 482      *
 483      * @param model the new value
 484      */
 485     protected void setModel(TreeModel model) {
 486         completeEditing();
 487         if(treeModel != null && treeModelListener != null)
 488             treeModel.removeTreeModelListener(treeModelListener);
 489         treeModel = model;
 490         if(treeModel != null) {
 491             if(treeModelListener != null)
 492                 treeModel.addTreeModelListener(treeModelListener);
 493         }
 494         if(treeState != null) {
 495             treeState.setModel(model);
 496             updateLayoutCacheExpandedNodesIfNecessary();
 497             updateSize();
 498         }
 499     }
 500 
 501     /**
 502      * Returns the tree model.
 503      *
 504      * @return the tree model
 505      */
 506     protected TreeModel getModel() {
 507         return treeModel;
 508     }
 509 
 510     /**
 511      * Sets the root to being visible.

 512      *
 513      * @param newValue the new value
 514      */
 515     protected void setRootVisible(boolean newValue) {
 516         completeEditing();
 517         updateDepthOffset();
 518         if(treeState != null) {
 519             treeState.setRootVisible(newValue);
 520             treeState.invalidateSizes();
 521             updateSize();
 522         }
 523     }
 524 
 525     /**
 526      * Returns {@code true} if the tree root is visible.
 527      *
 528      * @return {@code true} if the tree root is visible
 529      */
 530     protected boolean isRootVisible() {
 531         return (tree != null) ? tree.isRootVisible() : false;
 532     }
 533 
 534     /**
 535      * Determines whether the node handles are to be displayed.

 536      *
 537      * @param newValue the new value
 538      */
 539     protected void setShowsRootHandles(boolean newValue) {
 540         completeEditing();
 541         updateDepthOffset();
 542         if(treeState != null) {
 543             treeState.invalidateSizes();
 544             updateSize();
 545         }
 546     }
 547 
 548     /**
 549      * Returns {@code true} if the root handles are to be displayed.
 550      *
 551      * @return {@code true} if the root handles are to be displayed
 552      */
 553     protected boolean getShowsRootHandles() {
 554         return (tree != null) ? tree.getShowsRootHandles() : false;
 555     }
 556 
 557     /**
 558      * Sets the cell editor.

 559      *
 560      * @param editor the new cell editor
 561      */
 562     protected void setCellEditor(TreeCellEditor editor) {
 563         updateCellEditor();
 564     }
 565 
 566     /**
 567      * Returns an instance of {@code TreeCellEditor}.

 568      *
 569      * @return an instance of {@code TreeCellEditor}
 570      */
 571     protected TreeCellEditor getCellEditor() {
 572         return (tree != null) ? tree.getCellEditor() : null;
 573     }
 574 
 575     /**
 576      * Configures the receiver to allow, or not allow, editing.

 577      *
 578      * @param newValue the new value
 579      */
 580     protected void setEditable(boolean newValue) {
 581         updateCellEditor();
 582     }
 583 
 584     /**
 585      * Returns {@code true} if the tree is editable.
 586      *
 587      * @return {@code true} if the tree is editable
 588      */
 589     protected boolean isEditable() {
 590         return (tree != null) ? tree.isEditable() : false;
 591     }
 592 
 593     /**
 594      * Resets the selection model. The appropriate listener are installed
 595      * on the model.
 596      *
 597      * @param newLSM new selection model
 598      */
 599     protected void setSelectionModel(TreeSelectionModel newLSM) {
 600         completeEditing();
 601         if(selectionModelPropertyChangeListener != null &&
 602            treeSelectionModel != null)
 603             treeSelectionModel.removePropertyChangeListener
 604                               (selectionModelPropertyChangeListener);
 605         if(treeSelectionListener != null && treeSelectionModel != null)



 413         if(this.largeModel != largeModel) {
 414             completeEditing();
 415             this.largeModel = largeModel;
 416             treeState = createLayoutCache();
 417             configureLayoutCache();
 418             updateLayoutCacheExpandedNodesIfNecessary();
 419             updateSize();
 420         }
 421     }
 422 
 423     /**
 424      * Returns {@code true} if large model is set.
 425      *
 426      * @return {@code true} if large model is set
 427      */
 428     protected boolean isLargeModel() {
 429         return largeModel;
 430     }
 431 
 432     /**
 433      * Called when the {@code rowHeight} property is changed in
 434      * the drawn tree component.
 435      *
 436      * @param rowHeight the new value of the {@code rowHeight} property
 437      */
 438     protected void setRowHeight(int rowHeight) {
 439         completeEditing();
 440         if(treeState != null) {
 441             setLargeModel(tree.isLargeModel());
 442             treeState.setRowHeight(rowHeight);
 443             updateSize();
 444         }
 445     }
 446 
 447     /**
 448      * Returns the height of each row in the drawn tree component. If the
 449      * returned value is less than or equal to 0 the height for each row is
 450      * determined by the renderer.
 451      *
 452      * @return the height of each row, in pixels
 453      */
 454     protected int getRowHeight() {
 455         return (tree == null) ? -1 : tree.getRowHeight();
 456     }
 457 
 458     /**
 459      * Called when the {@code cellRenderer} property is changed in
 460      * the drawn tree component.
 461      *
 462      * @param tcr the new value of the {@code cellRenderer} property
 463      */
 464     protected void setCellRenderer(TreeCellRenderer tcr) {
 465         completeEditing();
 466         updateRenderer();
 467         if(treeState != null) {
 468             treeState.invalidateSizes();
 469             updateSize();
 470         }
 471     }
 472 
 473     /**
 474      * Returns the current instance of the {@link TreeCellRenderer} that is
 475      * rendering each cell.
 476      *
 477      * @return the {@link TreeCellRenderer} instance
 478      */
 479     protected TreeCellRenderer getCellRenderer() {
 480         return currentCellRenderer;
 481     }
 482 
 483     /**
 484      * Sets the {@code TreeModel}.
 485      *
 486      * @param model the new value
 487      */
 488     protected void setModel(TreeModel model) {
 489         completeEditing();
 490         if(treeModel != null && treeModelListener != null)
 491             treeModel.removeTreeModelListener(treeModelListener);
 492         treeModel = model;
 493         if(treeModel != null) {
 494             if(treeModelListener != null)
 495                 treeModel.addTreeModelListener(treeModelListener);
 496         }
 497         if(treeState != null) {
 498             treeState.setModel(model);
 499             updateLayoutCacheExpandedNodesIfNecessary();
 500             updateSize();
 501         }
 502     }
 503 
 504     /**
 505      * Returns the tree model.
 506      *
 507      * @return the tree model
 508      */
 509     protected TreeModel getModel() {
 510         return treeModel;
 511     }
 512 
 513     /**
 514      * Called when the {@code rootVisible} property is changed in the drawn tree
 515      * component.
 516      *
 517      * @param newValue the new value of the {@code rootVisible} property
 518      */
 519     protected void setRootVisible(boolean newValue) {
 520         completeEditing();
 521         updateDepthOffset();
 522         if(treeState != null) {
 523             treeState.setRootVisible(newValue);
 524             treeState.invalidateSizes();
 525             updateSize();
 526         }
 527     }
 528 
 529     /**
 530      * Returns whether the root node of the drawn tree component is displayable.
 531      *
 532      * @return {@code true} if the root node of the tree is displayed
 533      */
 534     protected boolean isRootVisible() {
 535         return (tree != null) ? tree.isRootVisible() : false;
 536     }
 537 
 538     /**
 539      * Called when the {@code showsRootHandles} property is changed in the drawn
 540      * tree component.
 541      *
 542      * @param newValue the new value of the {@code showsRootHandles} property
 543      */
 544     protected void setShowsRootHandles(boolean newValue) {
 545         completeEditing();
 546         updateDepthOffset();
 547         if(treeState != null) {
 548             treeState.invalidateSizes();
 549             updateSize();
 550         }
 551     }
 552 
 553     /**
 554      * Returns {@code true} if the root handles are to be displayed.
 555      *
 556      * @return {@code true} if the root handles are to be displayed
 557      */
 558     protected boolean getShowsRootHandles() {
 559         return (tree != null) ? tree.getShowsRootHandles() : false;
 560     }
 561 
 562     /**
 563      * Called when the {@code cellEditor} property is changed in the drawn tree
 564      * component.
 565      *
 566      * @param editor the new value of the {@code cellEditor} property
 567      */
 568     protected void setCellEditor(TreeCellEditor editor) {
 569         updateCellEditor();
 570     }
 571 
 572     /**
 573      * Returns the editor used to edit entries in the drawn tree component, or
 574      * {@code null} if the tree cannot be edited.
 575      *
 576      * @return the {@link TreeCellEditor} instance, or {@code null}
 577      */
 578     protected TreeCellEditor getCellEditor() {
 579         return (tree != null) ? tree.getCellEditor() : null;
 580     }
 581 
 582     /**
 583      * Called when the {@code editable} property is changed in the drawn tree
 584      * component.
 585      *
 586      * @param newValue the new value of the {@code editable}> property
 587      */
 588     protected void setEditable(boolean newValue) {
 589         updateCellEditor();
 590     }
 591 
 592     /**
 593      * Returns whether the drawn tree component should be enabled for editing.
 594      *
 595      * @return {@code true} if the tree is editable
 596      */
 597     protected boolean isEditable() {
 598         return (tree != null) ? tree.isEditable() : false;
 599     }
 600 
 601     /**
 602      * Resets the selection model. The appropriate listener are installed
 603      * on the model.
 604      *
 605      * @param newLSM new selection model
 606      */
 607     protected void setSelectionModel(TreeSelectionModel newLSM) {
 608         completeEditing();
 609         if(selectionModelPropertyChangeListener != null &&
 610            treeSelectionModel != null)
 611             treeSelectionModel.removePropertyChangeListener
 612                               (selectionModelPropertyChangeListener);
 613         if(treeSelectionListener != null && treeSelectionModel != null)


< prev index next >