< prev index next >

src/java.desktop/share/classes/javax/swing/tree/FixedHeightLayoutCache.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 330     }
 331 
 332     //
 333     // TreeModelListener methods
 334     //
 335 
 336     /**
 337      * <p>Invoked after a node (or a set of siblings) has changed in some
 338      * way. The node(s) have not changed locations in the tree or
 339      * altered their children arrays, but other attributes have
 340      * changed and may affect presentation. Example: the name of a
 341      * file has changed, but it is in the same location in the file
 342      * system.</p>
 343      *
 344      * <p>e.path() returns the path the parent of the changed node(s).</p>
 345      *
 346      * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 347      */
 348     public void treeNodesChanged(TreeModelEvent e) {
 349         if(e != null) {
 350             int                 changedIndexs[];
 351             FHTreeStateNode     changedParent = getNodeForPath
 352                                   (SwingUtilities2.getTreePath(e, getModel()), false, false);
 353             int                 maxCounter;
 354 
 355             changedIndexs = e.getChildIndices();
 356             /* Only need to update the children if the node has been
 357                expanded once. */
 358             // PENDING(scott): make sure childIndexs is sorted!
 359             if (changedParent != null) {
 360                 if (changedIndexs != null &&
 361                     (maxCounter = changedIndexs.length) > 0) {
 362                     Object       parentValue = changedParent.getUserObject();
 363 
 364                     for(int counter = 0; counter < maxCounter; counter++) {
 365                         FHTreeStateNode    child = changedParent.
 366                                  getChildAtModelIndex(changedIndexs[counter]);
 367 
 368                         if(child != null) {
 369                             child.setUserObject(treeModel.getChild(parentValue,
 370                                                      changedIndexs[counter]));


 374                         visibleNodesChanged();
 375                 }
 376                 // Null for root indicates it changed.
 377                 else if (changedParent == root && changedParent.isVisible() &&
 378                          changedParent.isExpanded()) {
 379                     visibleNodesChanged();
 380                 }
 381             }
 382         }
 383     }
 384 
 385     /**
 386      * <p>Invoked after nodes have been inserted into the tree.</p>
 387      *
 388      * <p>e.path() returns the parent of the new nodes
 389      * <p>e.childIndices() returns the indices of the new nodes in
 390      * ascending order.
 391      */
 392     public void treeNodesInserted(TreeModelEvent e) {
 393         if(e != null) {
 394             int                 changedIndexs[];
 395             FHTreeStateNode     changedParent = getNodeForPath
 396                                   (SwingUtilities2.getTreePath(e, getModel()), false, false);
 397             int                 maxCounter;
 398 
 399             changedIndexs = e.getChildIndices();
 400             /* Only need to update the children if the node has been
 401                expanded once. */
 402             // PENDING(scott): make sure childIndexs is sorted!
 403             if(changedParent != null && changedIndexs != null &&
 404                (maxCounter = changedIndexs.length) > 0) {
 405                 boolean          isVisible =
 406                     (changedParent.isVisible() &&
 407                      changedParent.isExpanded());
 408 
 409                 for(int counter = 0; counter < maxCounter; counter++) {
 410                     changedParent.childInsertedAtModelIndex
 411                         (changedIndexs[counter], isVisible);
 412                 }
 413                 if(isVisible && treeSelectionModel != null)
 414                     treeSelectionModel.resetRowSelection();
 415                 if(changedParent.isVisible())
 416                     this.visibleNodesChanged();
 417             }
 418         }
 419     }
 420 
 421     /**
 422      * <p>Invoked after nodes have been removed from the tree.  Note that
 423      * if a subtree is removed from the tree, this method may only be
 424      * invoked once for the root of the removed subtree, not once for
 425      * each individual set of siblings removed.</p>
 426      *
 427      * <p>e.path() returns the former parent of the deleted nodes.</p>
 428      *
 429      * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 430      */
 431     public void treeNodesRemoved(TreeModelEvent e) {
 432         if(e != null) {
 433             int                  changedIndexs[];
 434             int                  maxCounter;
 435             TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
 436             FHTreeStateNode      changedParentNode = getNodeForPath
 437                                        (parentPath, false, false);
 438 
 439             changedIndexs = e.getChildIndices();
 440             // PENDING(scott): make sure that changedIndexs are sorted in
 441             // ascending order.
 442             if(changedParentNode != null && changedIndexs != null &&
 443                (maxCounter = changedIndexs.length) > 0) {
 444                 Object[]           children = e.getChildren();
 445                 boolean            isVisible =
 446                     (changedParentNode.isVisible() &&
 447                      changedParentNode.isExpanded());
 448 
 449                 for(int counter = maxCounter - 1; counter >= 0; counter--) {
 450                     changedParentNode.removeChildAtModelIndex
 451                                      (changedIndexs[counter], isVisible);
 452                 }
 453                 if(isVisible) {


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 330     }
 331 
 332     //
 333     // TreeModelListener methods
 334     //
 335 
 336     /**
 337      * <p>Invoked after a node (or a set of siblings) has changed in some
 338      * way. The node(s) have not changed locations in the tree or
 339      * altered their children arrays, but other attributes have
 340      * changed and may affect presentation. Example: the name of a
 341      * file has changed, but it is in the same location in the file
 342      * system.</p>
 343      *
 344      * <p>e.path() returns the path the parent of the changed node(s).</p>
 345      *
 346      * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 347      */
 348     public void treeNodesChanged(TreeModelEvent e) {
 349         if(e != null) {
 350             int[]                 changedIndexs;
 351             FHTreeStateNode     changedParent = getNodeForPath
 352                                   (SwingUtilities2.getTreePath(e, getModel()), false, false);
 353             int                 maxCounter;
 354 
 355             changedIndexs = e.getChildIndices();
 356             /* Only need to update the children if the node has been
 357                expanded once. */
 358             // PENDING(scott): make sure childIndexs is sorted!
 359             if (changedParent != null) {
 360                 if (changedIndexs != null &&
 361                     (maxCounter = changedIndexs.length) > 0) {
 362                     Object       parentValue = changedParent.getUserObject();
 363 
 364                     for(int counter = 0; counter < maxCounter; counter++) {
 365                         FHTreeStateNode    child = changedParent.
 366                                  getChildAtModelIndex(changedIndexs[counter]);
 367 
 368                         if(child != null) {
 369                             child.setUserObject(treeModel.getChild(parentValue,
 370                                                      changedIndexs[counter]));


 374                         visibleNodesChanged();
 375                 }
 376                 // Null for root indicates it changed.
 377                 else if (changedParent == root && changedParent.isVisible() &&
 378                          changedParent.isExpanded()) {
 379                     visibleNodesChanged();
 380                 }
 381             }
 382         }
 383     }
 384 
 385     /**
 386      * <p>Invoked after nodes have been inserted into the tree.</p>
 387      *
 388      * <p>e.path() returns the parent of the new nodes
 389      * <p>e.childIndices() returns the indices of the new nodes in
 390      * ascending order.
 391      */
 392     public void treeNodesInserted(TreeModelEvent e) {
 393         if(e != null) {
 394             int[]                 changedIndexs;
 395             FHTreeStateNode     changedParent = getNodeForPath
 396                                   (SwingUtilities2.getTreePath(e, getModel()), false, false);
 397             int                 maxCounter;
 398 
 399             changedIndexs = e.getChildIndices();
 400             /* Only need to update the children if the node has been
 401                expanded once. */
 402             // PENDING(scott): make sure childIndexs is sorted!
 403             if(changedParent != null && changedIndexs != null &&
 404                (maxCounter = changedIndexs.length) > 0) {
 405                 boolean          isVisible =
 406                     (changedParent.isVisible() &&
 407                      changedParent.isExpanded());
 408 
 409                 for(int counter = 0; counter < maxCounter; counter++) {
 410                     changedParent.childInsertedAtModelIndex
 411                         (changedIndexs[counter], isVisible);
 412                 }
 413                 if(isVisible && treeSelectionModel != null)
 414                     treeSelectionModel.resetRowSelection();
 415                 if(changedParent.isVisible())
 416                     this.visibleNodesChanged();
 417             }
 418         }
 419     }
 420 
 421     /**
 422      * <p>Invoked after nodes have been removed from the tree.  Note that
 423      * if a subtree is removed from the tree, this method may only be
 424      * invoked once for the root of the removed subtree, not once for
 425      * each individual set of siblings removed.</p>
 426      *
 427      * <p>e.path() returns the former parent of the deleted nodes.</p>
 428      *
 429      * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 430      */
 431     public void treeNodesRemoved(TreeModelEvent e) {
 432         if(e != null) {
 433             int[]                  changedIndexs;
 434             int                  maxCounter;
 435             TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
 436             FHTreeStateNode      changedParentNode = getNodeForPath
 437                                        (parentPath, false, false);
 438 
 439             changedIndexs = e.getChildIndices();
 440             // PENDING(scott): make sure that changedIndexs are sorted in
 441             // ascending order.
 442             if(changedParentNode != null && changedIndexs != null &&
 443                (maxCounter = changedIndexs.length) > 0) {
 444                 Object[]           children = e.getChildren();
 445                 boolean            isVisible =
 446                     (changedParentNode.isVisible() &&
 447                      changedParentNode.isExpanded());
 448 
 449                 for(int counter = maxCounter - 1; counter >= 0; counter--) {
 450                     changedParentNode.removeChildAtModelIndex
 451                                      (changedIndexs[counter], isVisible);
 452                 }
 453                 if(isVisible) {


< prev index next >