Ignore:
Timestamp:
2003-05-27T15:40:47+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/TreeSynchronizer.java

    r4293 r4364  
    4040 */
    4141final public class TreeSynchronizer
    42     extends Vector
    43     implements TreeExpansionListener, TreeSelectionListener {
    44     /** <i>true</i> if we should temporarily ignore further events, most likely because we know our actions are causing them. */
    45     private boolean ignore;
    46     /** A list of tree selection listeners. */
    47     private Vector selection_listeners = new Vector();
    48     /** Add a new tree to the synchronization list of trees to be synchronized.
    49       * @param tree The lastest victim, a <strong>JTree</strong>.
     42    extends Vector
     43    implements TreeExpansionListener, TreeSelectionListener {
     44    /** <i>true</i> if we should temporarily ignore further events, most likely because we know our actions are causing them. */
     45    private boolean ignore;
     46    /** A list of tree selection listeners. */
     47    private Vector selection_listeners = new Vector();
     48    /** Add a new tree to the synchronization list of trees to be synchronized.
     49     * @param tree The lastest victim, a <strong>JTree</strong>.
    5050      */
    51     public void add(JTree tree) {
    52           super.add(tree);
    53           tree.addTreeExpansionListener(this);
    54           //tree.addTreeSelectionListener(this);
    55     }
     51    public void add(JTree tree) {
     52    super.add(tree);
     53    tree.addTreeExpansionListener(this);
     54    //tree.addTreeSelectionListener(this);
     55    }
    5656
    57     /** We allow the Gatherer to add tree listeners to this class, as it persists between collection changes transparently. Thus there is no need to reattach listeners everytime the collection changes. */
    58     public void addTreeSelectionListener(TreeSelectionListener listener) {
    59           if(!selection_listeners.contains(listener)) {
    60                 selection_listeners.add(listener);
    61           }
    62     }
     57    /** We allow the Gatherer to add tree listeners to this class, as it persists between collection changes transparently. Thus there is no need to reattach listeners everytime the collection changes. */
     58    public void addTreeSelectionListener(TreeSelectionListener listener) {
     59    if(!selection_listeners.contains(listener)) {
     60        selection_listeners.add(listener);
     61    }
     62    }
    6363
    64     /** Called whenever an item in the tree has been collapsed.
     64    /** Called whenever an item in the tree has been collapsed.
    6565      * @param event A <strong>TreeExpansionEvent</strong> containing information about the event.
    6666      */
    67     public void treeCollapsed(TreeExpansionEvent event) {
    68           if(!ignore) {
    69                 ignore = true;
     67    public void treeCollapsed(TreeExpansionEvent event) {
     68    if(!ignore) {
     69        ignore = true;
    7070                // Collapse that path in all registered trees.
    71                 JTree tree = (JTree)event.getSource();
    72                 TreePath path = event.getPath();
    73                 for(int i = size(); i != 0; i--) {
    74                      JTree sibling = (JTree) get(i - 1);
    75                      if(!sibling.equals(tree)) {
    76                           sibling.collapsePath(path);
    77                      }
    78                 }
    79                 ignore = false;
    80           }
    81     }
    82     /** Called whenever an item in the tree has been expanded.
     71        JTree tree = (JTree)event.getSource();
     72        TreePath path = event.getPath();
     73        for(int i = size(); i != 0; i--) {
     74        JTree sibling = (JTree) get(i - 1);
     75        if(!sibling.equals(tree)) {
     76            sibling.collapsePath(path);
     77        }
     78        }
     79        ignore = false;
     80    }
     81    }
     82    /** Called whenever an item in the tree has been expanded.
    8383      * @param event A <strong>TreeExpansionEvent</strong> containing information about the event.
    8484      */
    85     public void treeExpanded(TreeExpansionEvent event) {
    86           if(!ignore) {
    87                 ignore = true;
     85    public void treeExpanded(TreeExpansionEvent event) {
     86    if(!ignore) {
     87        ignore = true;
    8888                // Expand that path in all registered trees.
    89                 JTree tree = (JTree)event.getSource();
    90                 TreePath path = event.getPath();
    91                 for(int i = size(); i != 0; i--) {
    92                      JTree sibling = (JTree) get(i - 1);
    93                      if(!sibling.equals(tree)) {
    94                           sibling.expandPath(path);
    95                      }
    96                 }
    97                 ignore = false;
    98           }
    99     }
    100     /** Called whenever the one of the trees selection changes.
     89        JTree tree = (JTree)event.getSource();
     90        TreePath path = event.getPath();
     91        for(int i = size(); i != 0; i--) {
     92        JTree sibling = (JTree) get(i - 1);
     93        if(!sibling.equals(tree)) {
     94            sibling.expandPath(path);
     95        }
     96        }
     97        ignore = false;
     98    }
     99    }
     100    /** Called whenever the one of the trees selection changes.
    101101      * @param event A <strong>TreeSelectionEvent</strong> containing information about the event.
    102102      */
    103     public void valueChanged(TreeSelectionEvent event) {
    104           if(!ignore) {
    105                 ignore = true;
     103    public void valueChanged(TreeSelectionEvent event) {
     104    if(!ignore) {
     105        ignore = true;
    106106                // Recover the tree that is the source.
    107                 JTree tree = (JTree) event.getSource();
     107        JTree tree = (JTree) event.getSource();
    108108                // Brute Force approach.
    109109                // Extract the currently selected paths.
    110                 TreePath paths[] = tree.getSelectionPaths();
     110        TreePath paths[] = tree.getSelectionPaths();
    111111                // Then for every registered tree, that isn't this one, ensure those paths are selected.
    112                 for(int i = size(); paths != null && i != 0; i--) {
    113                      JTree sibling = (JTree) get(i - 1);
    114                      if(!sibling.equals(tree)) {
    115                           // One last thing to do. If this is actually a DragTree we are dealing with we have to tell it to set the selection values immediately, not wait for the clear until it is sure it is no the pre-cursor to a drag.
    116                           if(sibling instanceof DragTree) {
    117                                 DragTree gtree = (DragTree)sibling;
    118                                 gtree.setImmediate(true);
    119                                 gtree.setSelectionPaths(paths);
    120                                 // I'm going to ensure that the last selected path is visible.
    121                                 gtree.scrollPathToVisible(paths[paths.length - 1]);
    122                                 gtree.setImmediate(false);
    123                           }
    124                           else {
    125                                 sibling.setSelectionPaths(paths);
    126                                 sibling.scrollPathToVisible(paths[paths.length - 1]);
    127                           }
    128                      }
    129                 }
     112        for(int i = size(); paths != null && i != 0; i--) {
     113        JTree sibling = (JTree) get(i - 1);
     114        if(!sibling.equals(tree)) {
     115            // One last thing to do. If this is actually a DragTree we are dealing with we have to tell it to set the selection values immediately, not wait for the clear until it is sure it is no the pre-cursor to a drag.
     116            if(sibling instanceof DragTree) {
     117            DragTree gtree = (DragTree)sibling;
     118            gtree.setImmediate(true);
     119            gtree.setSelectionPaths(paths);
     120            // I'm going to ensure that the last selected path is visible.
     121            gtree.scrollPathToVisible(paths[paths.length - 1]);
     122            gtree.setImmediate(false);
     123            }
     124            else {
     125            sibling.setSelectionPaths(paths);
     126            sibling.scrollPathToVisible(paths[paths.length - 1]);
     127            }
     128        }
     129        }
    130130                // Pass on message to all listeners.
    131                 for(int i = 0; i < selection_listeners.size(); i++) {
    132                      ((TreeSelectionListener) selection_listeners.get(i)).valueChanged(event);
    133                 }
    134                 ignore = false;
    135           }
    136     }
     131        for(int i = 0; i < selection_listeners.size(); i++) {
     132        ((TreeSelectionListener) selection_listeners.get(i)).valueChanged(event);
     133        }
     134        ignore = false;
     135    }
     136    }
    137137}
Note: See TracChangeset for help on using the changeset viewer.