/[classpath]/classpath/javax/swing/plaf/basic/BasicTreeUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicTreeUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.58 by langel, Wed Aug 10 15:03:13 2005 UTC revision 1.59 by langel, Wed Aug 10 15:04:15 2005 UTC
# Line 1  Line 1 
1  /* BasicTreeUI.java --  /* BasicTreeUI.java --
2     Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.   This file is part of GNU Classpath.
5    
6  GNU Classpath is free software; you can redistribute it and/or modify   GNU Classpath is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by   it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)   the Free Software Foundation; either version 2, or (at your option)
9  any later version.   any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but   GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of   WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  General Public License for more details.   General Public License for more details.
15    
16  You should have received a copy of the GNU General Public License   You should have received a copy of the GNU General Public License
17  along with GNU Classpath; see the file COPYING.  If not, write to the   along with GNU Classpath; see the file COPYING.  If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.   02110-1301 USA.
20    
21  Linking this library statically or dynamically with other modules is   Linking this library statically or dynamically with other modules is
22  making a combined work based on this library.  Thus, the terms and   making a combined work based on this library.  Thus, the terms and
23  conditions of the GNU General Public License cover the whole   conditions of the GNU General Public License cover the whole
24  combination.   combination.
25    
26  As a special exception, the copyright holders of this library give you   As a special exception, the copyright holders of this library give you
27  permission to link this library with independent modules to produce an   permission to link this library with independent modules to produce an
28  executable, regardless of the license terms of these independent   executable, regardless of the license terms of these independent
29  modules, and to copy and distribute the resulting executable under   modules, and to copy and distribute the resulting executable under
30  terms of your choice, provided that you also meet, for each linked   terms of your choice, provided that you also meet, for each linked
31  independent module, the terms and conditions of the license of that   independent module, the terms and conditions of the license of that
32  module.  An independent module is a module which is not derived from   module.  An independent module is a module which is not derived from
33  or based on this library.  If you modify this library, you may extend   or based on this library.  If you modify this library, you may extend
34  this exception to your version of the library, but you are not   this exception to your version of the library, but you are not
35  obligated to do so.  If you do not wish to do so, delete this   obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */   exception statement from your version. */
37    
38    
39  package javax.swing.plaf.basic;  package javax.swing.plaf.basic;
# Line 107  import javax.swing.tree.TreeSelectionMod Line 107  import javax.swing.tree.TreeSelectionMod
107   * @author Sascha Brawer (brawer@dandelis.ch)   * @author Sascha Brawer (brawer@dandelis.ch)
108   * @author Lillian Angel (langel@redhat.com)   * @author Lillian Angel (langel@redhat.com)
109   */   */
110  public class BasicTreeUI extends TreeUI  public class BasicTreeUI
111      extends TreeUI
112  {  {
113    /** Collapse Icon for the tree. */    /** Collapse Icon for the tree. */
114    protected transient Icon collapsedIcon;    protected transient Icon collapsedIcon;
115      
116    /** Expanded Icon for the tree. */    /** Expanded Icon for the tree. */
117    protected transient Icon expandedIcon;    protected transient Icon expandedIcon;
118      
119    /** Distance between left margin and where vertical dashes will be drawn. */    /** Distance between left margin and where vertical dashes will be drawn. */
120    protected int leftChildIndent;    protected int leftChildIndent;
121      
122    /**    /**
123     * Distance between leftChildIndent and where cell contents will be drawn.     * Distance between leftChildIndent and where cell contents will be drawn.
124     */     */
125    protected int rightChildIndent;    protected int rightChildIndent;
126      
127    /**    /**
128     * Total fistance that will be indented. The sum of leftChildIndent and     * Total fistance that will be indented. The sum of leftChildIndent and
129     * rightChildIndent .     * rightChildIndent .
130     */     */
131    protected int totalChildIndent;    protected int totalChildIndent;
132      
133    /** Minimum preferred size. */    /** Minimum preferred size. */
134    protected Dimension preferredMinsize;    protected Dimension preferredMinsize;
135      
136    /** Index of the row that was last selected. */    /** Index of the row that was last selected. */
137    protected int lastSelectedRow;    protected int lastSelectedRow;
138      
139    /** Component that we're going to be drawing onto. */    /** Component that we're going to be drawing onto. */
140    protected JTree tree;    protected JTree tree;
141      
142    /** Renderer that is being used to do the actual cell drawing. */    /** Renderer that is being used to do the actual cell drawing. */
143    protected transient TreeCellRenderer currentCellRenderer;    protected transient TreeCellRenderer currentCellRenderer;
144      
145    /**    /**
146     * Set to true if the renderer that is currently in the tree was created by     * Set to true if the renderer that is currently in the tree was created by
147     * this instance.     * this instance.
148     */     */
149    protected boolean createdRenderer;    protected boolean createdRenderer;
150      
151    /** Editor for the tree. */    /** Editor for the tree. */
152    protected transient TreeCellEditor cellEditor;    protected transient TreeCellEditor cellEditor;
153      
154    /**    /**
155     * Set to true if editor that is currently in the tree was created by this     * Set to true if editor that is currently in the tree was created by this
156     * instance.     * instance.
157     */     */
158    protected boolean createdCellEditor;    protected boolean createdCellEditor;
159      
160    /**    /**
161     * Set to false when editing and shouldSelectCall() returns true meaning the     * Set to false when editing and shouldSelectCall() returns true meaning the
162     * node should be selected before editing, used in completeEditing.     * node should be selected before editing, used in completeEditing.
163     */     */
164    protected boolean stopEditingInCompleteEditing;    protected boolean stopEditingInCompleteEditing;
165      
166    /** Used to paint the TreeCellRenderer. */    /** Used to paint the TreeCellRenderer. */
167    protected CellRendererPane rendererPane;    protected CellRendererPane rendererPane;
168      
169    /** Size needed to completely display all the nodes. */    /** Size needed to completely display all the nodes. */
170    protected Dimension preferredSize;    protected Dimension preferredSize;
171      
172    /** Is the preferredSize valid? */    /** Is the preferredSize valid? */
173    protected boolean validCachedPreferredSize;    protected boolean validCachedPreferredSize;
174      
175    /** Object responsible for handling sizing and expanded issues. */    /** Object responsible for handling sizing and expanded issues. */
176    protected AbstractLayoutCache treeState;    protected AbstractLayoutCache treeState;
177      
178    /** Used for minimizing the drawing of vertical lines. */    /** Used for minimizing the drawing of vertical lines. */
179    protected Hashtable drawingCache;    protected Hashtable drawingCache;
180      
181    /**    /**
182     * True if doing optimizations for a largeModel. Subclasses that don't     * True if doing optimizations for a largeModel. Subclasses that don't
183     * support this may wish to override createLayoutCache to not return a     * support this may wish to override createLayoutCache to not return a
184     * FixedHeightLayoutCache instance.     * FixedHeightLayoutCache instance.
185     */     */
186    protected boolean largeModel;    protected boolean largeModel;
187      
188    /** Responsible for telling the TreeState the size needed for a node. */    /** Responsible for telling the TreeState the size needed for a node. */
189    protected AbstractLayoutCache.NodeDimensions nodeDimensions;    protected AbstractLayoutCache.NodeDimensions nodeDimensions;
190      
191    /** Used to determine what to display. */    /** Used to determine what to display. */
192    protected TreeModel treeModel;    protected TreeModel treeModel;
193      
194    /** Model maintaining the selection. */    /** Model maintaining the selection. */
195    protected TreeSelectionModel treeSelectionModel;    protected TreeSelectionModel treeSelectionModel;
196      
197    /**    /**
198     * How much the depth should be offset to properly calculate x locations.     * How much the depth should be offset to properly calculate x locations.
199     * This is based on whether or not the root is visible, and if the root     * This is based on whether or not the root is visible, and if the root
200     * handles are visible.     * handles are visible.
201     */     */
202    protected int depthOffset;    protected int depthOffset;
203      
204    /**    /**
205     * When editing, this will be the Component that is doing the actual editing.     * When editing, this will be the Component that is doing the actual editing.
206     */     */
207    protected Component editingComponent;    protected Component editingComponent;
208      
209    /** Path that is being edited. */    /** Path that is being edited. */
210    protected TreePath editingPath;    protected TreePath editingPath;
211      
212    /**    /**
213     * Row that is being edited. Should only be referenced if editingComponent is     * Row that is being edited. Should only be referenced if editingComponent is
214     * null.     * null.
215     */     */
216    protected int editingRow;    protected int editingRow;
217      
218    /** Set to true if the editor has a different size than the renderer. */    /** Set to true if the editor has a different size than the renderer. */
219    protected boolean editorHasDifferentSize;    protected boolean editorHasDifferentSize;
220      
221    /** Listeners */    /** Listeners */
222    private PropertyChangeListener propertyChangeListener;    private PropertyChangeListener propertyChangeListener;
223    
224    private FocusListener focusListener;    private FocusListener focusListener;
225    
226    private TreeSelectionListener treeSelectionListener;    private TreeSelectionListener treeSelectionListener;
227    
228    private MouseInputListener mouseInputListener;    private MouseInputListener mouseInputListener;
229    
230    private KeyListener keyListener;    private KeyListener keyListener;
231    
232    private PropertyChangeListener selectionModelPropertyChangeListener;    private PropertyChangeListener selectionModelPropertyChangeListener;
233    
234    private ComponentListener componentListener;    private ComponentListener componentListener;
235    
236    private CellEditorListener cellEditorListener;    private CellEditorListener cellEditorListener;
237    
238    private TreeExpansionListener treeExpansionListener;    private TreeExpansionListener treeExpansionListener;
239    
240    private TreeModelListener treeModelListener;    private TreeModelListener treeModelListener;
241      
242    /**    /**
243     * Creates a new BasicTreeUI object.     * Creates a new BasicTreeUI object.
244     */     */
# Line 240  public class BasicTreeUI extends TreeUI Line 250  public class BasicTreeUI extends TreeUI
250      nodeDimensions = createNodeDimensions();      nodeDimensions = createNodeDimensions();
251      rendererPane = createCellRendererPane();      rendererPane = createCellRendererPane();
252      configureLayoutCache();      configureLayoutCache();
253        
254      propertyChangeListener = createPropertyChangeListener();      propertyChangeListener = createPropertyChangeListener();
255      focusListener = createFocusListener();      focusListener = createFocusListener();
256      treeSelectionListener = createTreeSelectionListener();      treeSelectionListener = createTreeSelectionListener();
# Line 251  public class BasicTreeUI extends TreeUI Line 261  public class BasicTreeUI extends TreeUI
261      cellEditorListener = createCellEditorListener();      cellEditorListener = createCellEditorListener();
262      treeExpansionListener = createTreeExpansionListener();      treeExpansionListener = createTreeExpansionListener();
263      treeModelListener = createTreeModelListener();      treeModelListener = createTreeModelListener();
264        
265      createdRenderer = true;      createdRenderer = true;
266      createdCellEditor = true;      createdCellEditor = true;
267      editingRow = -1;      editingRow = -1;
268      lastSelectedRow = -1;      lastSelectedRow = -1;
269    }    }
270      
271    /**    /**
272     * Returns an instance of the UI delegate for the specified component.     * Returns an instance of the UI delegate for the specified component.
273     *     *
# Line 269  public class BasicTreeUI extends TreeUI Line 279  public class BasicTreeUI extends TreeUI
279    {    {
280      return new BasicTreeUI();      return new BasicTreeUI();
281    }    }
282      
283    /**    /**
284     * Returns the Hash color.     * Returns the Hash color.
285     *     *
# Line 279  public class BasicTreeUI extends TreeUI Line 289  public class BasicTreeUI extends TreeUI
289    {    {
290      return UIManager.getLookAndFeelDefaults().getColor("Tree.hash");      return UIManager.getLookAndFeelDefaults().getColor("Tree.hash");
291    }    }
292      
293    /**    /**
294     * Sets the Hash color.     * Sets the Hash color.
295     *     *
# Line 288  public class BasicTreeUI extends TreeUI Line 298  public class BasicTreeUI extends TreeUI
298    protected void setHashColor(Color color)    protected void setHashColor(Color color)
299    {    {
300      // FIXME: not implemented      // FIXME: not implemented
301        
302    }    }
303      
304    /**    /**
305     * Sets the left child's indent value.     * Sets the left child's indent value.
306     *     *
# Line 300  public class BasicTreeUI extends TreeUI Line 310  public class BasicTreeUI extends TreeUI
310    {    {
311      leftChildIndent = newAmount;      leftChildIndent = newAmount;
312    }    }
313      
314    /**    /**
315     * Returns the indent value for the left child.     * Returns the indent value for the left child.
316     *     *
# Line 310  public class BasicTreeUI extends TreeUI Line 320  public class BasicTreeUI extends TreeUI
320    {    {
321      return leftChildIndent;      return leftChildIndent;
322    }    }
323      
324    /**    /**
325     * Sets the right child's indent value.     * Sets the right child's indent value.
326     *     *
# Line 320  public class BasicTreeUI extends TreeUI Line 330  public class BasicTreeUI extends TreeUI
330    {    {
331      rightChildIndent = newAmount;      rightChildIndent = newAmount;
332    }    }
333      
334    /**    /**
335     * Returns the indent value for the right child.     * Returns the indent value for the right child.
336     *     *
# Line 330  public class BasicTreeUI extends TreeUI Line 340  public class BasicTreeUI extends TreeUI
340    {    {
341      return rightChildIndent;      return rightChildIndent;
342    }    }
343      
344    /**    /**
345     * Sets the expanded icon.     * Sets the expanded icon.
346     *     *
# Line 340  public class BasicTreeUI extends TreeUI Line 350  public class BasicTreeUI extends TreeUI
350    {    {
351      expandedIcon = newG;      expandedIcon = newG;
352    }    }
353      
354    /**    /**
355     * Returns the current expanded icon.     * Returns the current expanded icon.
356     *     *
# Line 350  public class BasicTreeUI extends TreeUI Line 360  public class BasicTreeUI extends TreeUI
360    {    {
361      return expandedIcon;      return expandedIcon;
362    }    }
363      
364    /**    /**
365     * Sets the collapsed icon.     * Sets the collapsed icon.
366     *     *
# Line 360  public class BasicTreeUI extends TreeUI Line 370  public class BasicTreeUI extends TreeUI
370    {    {
371      collapsedIcon = newG;      collapsedIcon = newG;
372    }    }
373      
374    /**    /**
375     * Returns the current collapsed icon.     * Returns the current collapsed icon.
376     *     *
# Line 370  public class BasicTreeUI extends TreeUI Line 380  public class BasicTreeUI extends TreeUI
380    {    {
381      return collapsedIcon;      return collapsedIcon;
382    }    }
383      
384    /**    /**
385     * Updates the componentListener, if necessary.     * Updates the componentListener, if necessary.
386     *     *
# Line 385  public class BasicTreeUI extends TreeUI Line 395  public class BasicTreeUI extends TreeUI
395          tree.addComponentListener(componentListener);          tree.addComponentListener(componentListener);
396        }        }
397    }    }
398      
399    /**    /**
400     * Returns true if largeModel is set     * Returns true if largeModel is set
401     *     *
# Line 395  public class BasicTreeUI extends TreeUI Line 405  public class BasicTreeUI extends TreeUI
405    {    {
406      return largeModel;      return largeModel;
407    }    }
408      
409    /**    /**
410     * Sets the row height.     * Sets the row height.
411     *     *
# Line 405  public class BasicTreeUI extends TreeUI Line 415  public class BasicTreeUI extends TreeUI
415    {    {
416      treeState.setRowHeight(rowHeight);      treeState.setRowHeight(rowHeight);
417    }    }
418      
419    /**    /**
420     * Returns the current row height.     * Returns the current row height.
421     *     *
# Line 415  public class BasicTreeUI extends TreeUI Line 425  public class BasicTreeUI extends TreeUI
425    {    {
426      return treeState.getRowHeight();      return treeState.getRowHeight();
427    }    }
428      
429    /**    /**
430     * Sets the TreeCellRenderer to <code>tcr</code>. This invokes     * Sets the TreeCellRenderer to <code>tcr</code>. This invokes
431     * <code>updateRenderer</code>.     * <code>updateRenderer</code>.
# Line 428  public class BasicTreeUI extends TreeUI Line 438  public class BasicTreeUI extends TreeUI
438      tree.setCellRenderer(tcr);      tree.setCellRenderer(tcr);
439      updateRenderer();      updateRenderer();
440    }    }
441      
442    /**    /**
443     * Return currentCellRenderer, which will either be the trees renderer, or     * Return currentCellRenderer, which will either be the trees renderer, or
444     * defaultCellRenderer, which ever was not null.     * defaultCellRenderer, which ever was not null.
# Line 439  public class BasicTreeUI extends TreeUI Line 449  public class BasicTreeUI extends TreeUI
449    {    {
450      if (currentCellRenderer != null)      if (currentCellRenderer != null)
451        return currentCellRenderer;        return currentCellRenderer;
452        
453      return createDefaultCellRenderer();      return createDefaultCellRenderer();
454    }    }
455      
456    /**    /**
457     * Sets the tree's model.     * Sets the tree's model.
458     *     *
# Line 453  public class BasicTreeUI extends TreeUI Line 463  public class BasicTreeUI extends TreeUI
463      tree.setModel(model);      tree.setModel(model);
464      treeModel = tree.getModel();      treeModel = tree.getModel();
465    }    }
466      
467    /**    /**
468     * Returns the tree's model     * Returns the tree's model
469     *     *
# Line 463  public class BasicTreeUI extends TreeUI Line 473  public class BasicTreeUI extends TreeUI
473    {    {
474      return treeModel;      return treeModel;
475    }    }
476      
477    /**    /**
478     * Sets the root to being visible.     * Sets the root to being visible.
479     *     *
# Line 473  public class BasicTreeUI extends TreeUI Line 483  public class BasicTreeUI extends TreeUI
483    {    {
484      tree.setRootVisible(newValue);      tree.setRootVisible(newValue);
485    }    }
486      
487    /**    /**
488     * Returns true if the root is visible.     * Returns true if the root is visible.
489     *     *
# Line 483  public class BasicTreeUI extends TreeUI Line 493  public class BasicTreeUI extends TreeUI
493    {    {
494      return tree.isRootVisible();      return tree.isRootVisible();
495    }    }
496      
497    /**    /**
498     * Determines whether the node handles are to be displayed.     * Determines whether the node handles are to be displayed.
499     *     *
# Line 493  public class BasicTreeUI extends TreeUI Line 503  public class BasicTreeUI extends TreeUI
503    {    {
504      tree.setShowsRootHandles(newValue);      tree.setShowsRootHandles(newValue);
505    }    }
506      
507    /**    /**
508     * Returns true if the node handles are to be displayed.     * Returns true if the node handles are to be displayed.
509     *     *
# Line 503  public class BasicTreeUI extends TreeUI Line 513  public class BasicTreeUI extends TreeUI
513    {    {
514      return tree.getShowsRootHandles();      return tree.getShowsRootHandles();
515    }    }
516      
517    /**    /**
518     * Sets the cell editor.     * Sets the cell editor.
519     *     *
# Line 513  public class BasicTreeUI extends TreeUI Line 523  public class BasicTreeUI extends TreeUI
523    {    {
524      cellEditor = editor;      cellEditor = editor;
525    }    }
526      
527    /**    /**
528     * Returns the <code>TreeCellEditor</code> for this tree.     * Returns the <code>TreeCellEditor</code> for this tree.
529     *     *
# Line 523  public class BasicTreeUI extends TreeUI Line 533  public class BasicTreeUI extends TreeUI
533    {    {
534      return cellEditor;      return cellEditor;
535    }    }
536      
537    /**    /**
538     * Configures the receiver to allow, or not allow, editing.     * Configures the receiver to allow, or not allow, editing.
539     *     *
# Line 533  public class BasicTreeUI extends TreeUI Line 543  public class BasicTreeUI extends TreeUI
543    {    {
544      tree.setEditable(newValue);      tree.setEditable(newValue);
545    }    }
546      
547    /**    /**
548     * Returns true if the receiver allows editing.     * Returns true if the receiver allows editing.
549     *     *
# Line 543  public class BasicTreeUI extends TreeUI Line 553  public class BasicTreeUI extends TreeUI
553    {    {
554      return tree.isEditable();      return tree.isEditable();
555    }    }
556      
557    /**    /**
558     * Resets the selection model. The appropriate listeners are installed on the     * Resets the selection model. The appropriate listeners are installed on the
559     * model.     * model.
# Line 558  public class BasicTreeUI extends TreeUI Line 568  public class BasicTreeUI extends TreeUI
568          tree.setSelectionModel(treeSelectionModel);          tree.setSelectionModel(treeSelectionModel);
569        }        }
570    }    }
571      
572    /**    /**
573     * Returns the current selection model.     * Returns the current selection model.
574     *     *
# Line 568  public class BasicTreeUI extends TreeUI Line 578  public class BasicTreeUI extends TreeUI
578    {    {
579      return treeSelectionModel;      return treeSelectionModel;
580    }    }
581      
582    /**    /**
583     * Returns the Rectangle enclosing the label portion that the last item in     * Returns the Rectangle enclosing the label portion that the last item in
584     * path will be drawn to. Will return null if any component in path is     * path will be drawn to. Will return null if any component in path is
# Line 586  public class BasicTreeUI extends TreeUI Line 596  public class BasicTreeUI extends TreeUI
596          Object cell = path.getLastPathComponent();          Object cell = path.getLastPathComponent();
597          TreeModel mod = tree.getModel();          TreeModel mod = tree.getModel();
598          if (mod != null)          if (mod != null)
599          {            {
600            Object root = mod.getRoot();              Object root = mod.getRoot();
601            if (!tree.isRootVisible()              if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
602                && tree.isExpanded(new TreePath(root)))                root = getNextNode(root);
603              root = getNextNode(root);  
604                          Point loc = getCellLocation(0, 0, tree, mod, cell, root);
605            Point loc = getCellLocation(0, 0, tree, mod, cell, root);              return getCellBounds(loc.x, loc.y, cell);
606            return getCellBounds(loc.x, loc.y, cell);            }
         }  
607        }        }
608      return null;      return null;
609    }    }
610      
611    /**    /**
612     * Returns the path for passed in row. If row is not visible null is     * Returns the path for passed in row. If row is not visible null is
613     * returned.     * returned.
# Line 612  public class BasicTreeUI extends TreeUI Line 621  public class BasicTreeUI extends TreeUI
621    {    {
622      TreeModel mod = tree.getModel();      TreeModel mod = tree.getModel();
623      if (mod != null)      if (mod != null)
624      {        {
625        Object node = mod.getRoot();          Object node = mod.getRoot();
626        if (!tree.isRootVisible()          if (!tree.isRootVisible()
627            && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))              && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
628          node = getNextNode(node);            node = getNextNode(node);
629          
630        for (int i = 0; i < row; i++)          for (int i = 0; i < row; i++)
631          node = getNextVisibleNode(node);            node = getNextVisibleNode(node);
632          
633        if (node == null)          if (node == null)
634          return null;            return null;
635          
636        return new TreePath(getPathToRoot(node, 0));          return new TreePath(getPathToRoot(node, 0));
637      }        }
638      return null;      return null;
639    }    }
640      
641    /**    /**
642     * Returns the row that the last item identified in path is visible at. Will     * Returns the row that the last item identified in path is visible at. Will
643     * return -1 if any of the elments in the path are not currently visible.     * return -1 if any of the elments in the path are not currently visible.
# Line 646  public class BasicTreeUI extends TreeUI Line 655  public class BasicTreeUI extends TreeUI
655      // expand/collapse is not implemented      // expand/collapse is not implemented
656      return path.getPathCount() - 1;      return path.getPathCount() - 1;
657    }    }
658      
659    /**    /**
660     * Returns the number of rows that are being displayed.     * Returns the number of rows that are being displayed.
661     *     *
# Line 658  public class BasicTreeUI extends TreeUI Line 667  public class BasicTreeUI extends TreeUI
667      TreeModel mod = tree.getModel();      TreeModel mod = tree.getModel();
668      int count = 0;      int count = 0;
669      if (mod != null)      if (mod != null)
     {  
       Object node = mod.getRoot();  
       if (!tree.isRootVisible()  
           && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))  
         node = getNextNode(node);  
   
       while (node != null)  
670        {        {
671          count++;          Object node = mod.getRoot();
672          node = getNextVisibleNode(node);          if (!tree.isRootVisible()
673                && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))
674              node = getNextNode(node);
675    
676            while (node != null)
677              {
678                count++;
679                node = getNextVisibleNode(node);
680              }
681        }        }
     }  
682      return count;      return count;
683    }    }
684      
685    /**    /**
686     * Returns the path to the node that is closest to x,y. If there is nothing     * Returns the path to the node that is closest to x,y. If there is nothing
687     * currently visible this will return null, otherwise it'll always return a     * currently visible this will return null, otherwise it'll always return a
# Line 688  public class BasicTreeUI extends TreeUI Line 697  public class BasicTreeUI extends TreeUI
697    {    {
698      //FIXME: what if root is hidden? should not depend on (0,0)      //FIXME: what if root is hidden? should not depend on (0,0)
699      // should start counting rows from where root is.      // should start counting rows from where root is.
700        
701      int row = Math.round(y / getRowHeight());      int row = Math.round(y / getRowHeight());
702      TreePath path = getPathForRow(tree, row);      TreePath path = getPathForRow(tree, row);
703        
704      // no row is visible at this node      // no row is visible at this node
705      while (row > 0 && path == null)      while (row > 0 && path == null)
706        {        {
707          --row;          --row;
708          path = getPathForRow(tree, row);          path = getPathForRow(tree, row);
709        }        }
710        
711      return path;      return path;
712    }    }
713      
714    /**    /**
715     * Returns true if the tree is being edited. The item that is being edited     * Returns true if the tree is being edited. The item that is being edited
716     * can be returned by getEditingPath().     * can be returned by getEditingPath().
# Line 714  public class BasicTreeUI extends TreeUI Line 723  public class BasicTreeUI extends TreeUI
723      // FIXME: not implemented      // FIXME: not implemented
724      return false;      return false;
725    }    }
726      
727    /**    /**
728     * Stops the current editing session. This has no effect if the tree is not     * Stops the current editing session. This has no effect if the tree is not
729     * being edited. Returns true if the editor allows the editing session to     * being edited. Returns true if the editor allows the editing session to
# Line 728  public class BasicTreeUI extends TreeUI Line 737  public class BasicTreeUI extends TreeUI
737      // FIXME: not implemented      // FIXME: not implemented
738      return false;      return false;
739    }    }
740      
741    /**    /**
742     * Cancels the current editing session.     * Cancels the current editing session.
743     *     *
# Line 738  public class BasicTreeUI extends TreeUI Line 747  public class BasicTreeUI extends TreeUI
747    {    {
748      // FIXME: not implemented      // FIXME: not implemented
749    }    }
750      
751    /**    /**
752     * Selects the last item in path and tries to edit it. Editing will fail if     * Selects the last item in path and tries to edit it. Editing will fail if
753     * the CellEditor won't allow it for the selected item.     * the CellEditor won't allow it for the selected item.
# Line 750  public class BasicTreeUI extends TreeUI Line 759  public class BasicTreeUI extends TreeUI
759    {    {
760      // FIXME: not implemented      // FIXME: not implemented
761    }    }
762      
763    /**    /**
764     * Returns the path to the element that is being editted.     * Returns the path to the element that is being editted.
765     *     *
# Line 762  public class BasicTreeUI extends TreeUI Line 771  public class BasicTreeUI extends TreeUI
771      // FIXME: not implemented      // FIXME: not implemented
772      return null;      return null;
773    }    }
774      
775    /**    /**
776     * Invoked after the tree instance variable has been set, but before any     * Invoked after the tree instance variable has been set, but before any
777     * default/listeners have been installed.     * default/listeners have been installed.
# Line 771  public class BasicTreeUI extends TreeUI Line 780  public class BasicTreeUI extends TreeUI
780    {    {
781      // FIXME: not implemented      // FIXME: not implemented
782    }    }
783      
784    /**    /**
785     * Invoked from installUI after all the defaults/listeners have been     * Invoked from installUI after all the defaults/listeners have been
786     * installed.     * installed.
# Line 780  public class BasicTreeUI extends TreeUI Line 789  public class BasicTreeUI extends TreeUI
789    {    {
790      // FIXME: not implemented      // FIXME: not implemented
791    }    }
792      
793    /**    /**
794     * Invoked from uninstallUI after all the defaults/listeners have been     * Invoked from uninstallUI after all the defaults/listeners have been
795     * uninstalled.     * uninstalled.
# Line 789  public class BasicTreeUI extends TreeUI Line 798  public class BasicTreeUI extends TreeUI
798    {    {
799      // FIXME: not implemented      // FIXME: not implemented
800    }    }
801      
802    /**    /**
803     * Installs the subcomponents of the tree, which is the renderer pane.     * Installs the subcomponents of the tree, which is the renderer pane.
804     */     */
# Line 797  public class BasicTreeUI extends TreeUI Line 806  public class BasicTreeUI extends TreeUI
806    {    {
807      // FIXME: not implemented      // FIXME: not implemented
808    }    }
809      
810    /**    /**
811     * Creates an instance of NodeDimensions that is able to determine the size     * Creates an instance of NodeDimensions that is able to determine the size
812     * of a given node in the tree.     * of a given node in the tree.
# Line 809  public class BasicTreeUI extends TreeUI Line 818  public class BasicTreeUI extends TreeUI
818      // FIXME: not implemented      // FIXME: not implemented
819      return null;      return null;
820    }    }
821      
822    /**    /**
823     * Creates a listener that is reponsible for the updates the UI based on how     * Creates a listener that is reponsible for the updates the UI based on how
824     * the tree changes.     * the tree changes.
# Line 820  public class BasicTreeUI extends TreeUI Line 829  public class BasicTreeUI extends TreeUI
829    {    {
830      return new PropertyChangeHandler();      return new PropertyChangeHandler();
831    }    }
832      
833    /**    /**
834     * Creates the listener responsible for updating the selection based on mouse     * Creates the listener responsible for updating the selection based on mouse
835     * events.     * events.
# Line 831  public class BasicTreeUI extends TreeUI Line 840  public class BasicTreeUI extends TreeUI
840    {    {
841      return new MouseHandler();      return new MouseHandler();
842    }    }
843      
844    /**    /**
845     * Creates the listener that is responsible for updating the display when     * Creates the listener that is responsible for updating the display when
846     * focus is lost/grained.     * focus is lost/grained.
# Line 842  public class BasicTreeUI extends TreeUI Line 851  public class BasicTreeUI extends TreeUI
851    {    {
852      return new FocusHandler();      return new FocusHandler();
853    }    }
854      
855    /**    /**
856     * Creates the listener reponsible for getting key events from the tree.     * Creates the listener reponsible for getting key events from the tree.
857     *     *
# Line 852  public class BasicTreeUI extends TreeUI Line 861  public class BasicTreeUI extends TreeUI
861    {    {
862      return new KeyHandler();      return new KeyHandler();
863    }    }
864      
865    /**    /**
866     * Creates the listener responsible for getting property change events from     * Creates the listener responsible for getting property change events from
867     * the selection model.     * the selection model.
# Line 864  public class BasicTreeUI extends TreeUI Line 873  public class BasicTreeUI extends TreeUI
873    {    {
874      return new SelectionModelPropertyChangeHandler();      return new SelectionModelPropertyChangeHandler();
875    }    }
876      
877    /**    /**
878     * Creates the listener that updates the display based on selection change     * Creates the listener that updates the display based on selection change
879     * methods.     * methods.
# Line 875  public class BasicTreeUI extends TreeUI Line 884  public class BasicTreeUI extends TreeUI
884    {    {
885      return new TreeSelectionHandler();      return new TreeSelectionHandler();
886    }    }
887      
888    /**    /**
889     * Creates a listener to handle events from the current editor     * Creates a listener to handle events from the current editor
890     *     *
# Line 885  public class BasicTreeUI extends TreeUI Line 894  public class BasicTreeUI extends TreeUI
894    {    {
895      return new CellEditorHandler();      return new CellEditorHandler();
896    }    }
897      
898    /**    /**
899     * Creates and returns a new ComponentHandler. This is used for the large     * Creates and returns a new ComponentHandler. This is used for the large
900     * model to mark the validCachedPreferredSize as invalid when the component     * model to mark the validCachedPreferredSize as invalid when the component
# Line 897  public class BasicTreeUI extends TreeUI Line 906  public class BasicTreeUI extends TreeUI
906    {    {
907      return new ComponentHandler();      return new ComponentHandler();
908    }    }
909      
910    /**    /**
911     * Creates and returns the object responsible for updating the treestate when     * Creates and returns the object responsible for updating the treestate when
912     * a nodes expanded state changes.     * a nodes expanded state changes.
# Line 908  public class BasicTreeUI extends TreeUI Line 917  public class BasicTreeUI extends TreeUI
917    {    {
918      return new TreeExpansionHandler();      return new TreeExpansionHandler();
919    }    }
920      
921    /**    /**
922     * Creates the object responsible for managing what is expanded, as well as     * Creates the object responsible for managing what is expanded, as well as
923     * the size of nodes.     * the size of nodes.
# Line 919  public class BasicTreeUI extends TreeUI Line 928  public class BasicTreeUI extends TreeUI
928    {    {
929      return new FixedHeightLayoutCache();      return new FixedHeightLayoutCache();
930    }    }
931      
932    /**    /**
933     * Returns the renderer pane that renderer components are placed in.     * Returns the renderer pane that renderer components are placed in.
934     *     *
# Line 929  public class BasicTreeUI extends TreeUI Line 938  public class BasicTreeUI extends TreeUI
938    {    {
939      return new CellRendererPane();      return new CellRendererPane();
940    }    }
941      
942    /**    /**
943     * Creates a default cell editor.     * Creates a default cell editor.
944     *     *
# Line 937  public class BasicTreeUI extends TreeUI Line 946  public class BasicTreeUI extends TreeUI
946     */     */
947    protected TreeCellEditor createDefaultCellEditor()    protected TreeCellEditor createDefaultCellEditor()
948    {    {
949      return new DefaultTreeCellEditor(tree,      return new DefaultTreeCellEditor(
950                                       (DefaultTreeCellRenderer) createDefaultCellRenderer(), cellEditor);                                       tree,
951                                         (DefaultTreeCellRenderer) createDefaultCellRenderer(),
952                                         cellEditor);
953    }    }
954      
955    /**    /**
956     * Returns the default cell renderer that is used to do the stamping of each     * Returns the default cell renderer that is used to do the stamping of each
957     * node.     * node.
# Line 952  public class BasicTreeUI extends TreeUI Line 963  public class BasicTreeUI extends TreeUI
963    {    {
964      return new DefaultTreeCellRenderer();      return new DefaultTreeCellRenderer();
965    }    }
966      
967    /**    /**
968     * Returns a listener that can update the tree when the model changes.     * Returns a listener that can update the tree when the model changes.
969     *     *
# Line 962  public class BasicTreeUI extends TreeUI Line 973  public class BasicTreeUI extends TreeUI
973    {    {
974      return new TreeModelHandler();      return new TreeModelHandler();
975    }    }
976      
977    /**    /**
978     * Uninstall all registered listeners     * Uninstall all registered listeners
979     */     */
# Line 976  public class BasicTreeUI extends TreeUI Line 987  public class BasicTreeUI extends TreeUI
987      tree.removePropertyChangeListener(selectionModelPropertyChangeListener);      tree.removePropertyChangeListener(selectionModelPropertyChangeListener);
988      tree.removeComponentListener(componentListener);      tree.removeComponentListener(componentListener);
989      tree.removeTreeExpansionListener(treeExpansionListener);      tree.removeTreeExpansionListener(treeExpansionListener);
990        
991      TreeCellEditor tce = tree.getCellEditor();      TreeCellEditor tce = tree.getCellEditor();
992      if (tce != null)      if (tce != null)
993        tce.removeCellEditorListener(cellEditorListener);        tce.removeCellEditorListener(cellEditorListener);
# Line 984  public class BasicTreeUI extends TreeUI Line 995  public class BasicTreeUI extends TreeUI
995      if (tm != null)      if (tm != null)
996        tm.removeTreeModelListener(treeModelListener);        tm.removeTreeModelListener(treeModelListener);
997    }    }
998      
999    /**    /**
1000     * Uninstall all keyboard actions.     * Uninstall all keyboard actions.
1001     */     */
1002    protected void uninstallKeyboardActions()    protected void uninstallKeyboardActions()
1003    {    {
1004    }    }
1005      
1006    /**    /**
1007     * Uninstall the rendererPane.     * Uninstall the rendererPane.
1008     */     */
# Line 999  public class BasicTreeUI extends TreeUI Line 1010  public class BasicTreeUI extends TreeUI
1010    {    {
1011      // FIXME: not implemented      // FIXME: not implemented
1012    }    }
1013      
1014    /**    /**
1015     * The vertical element of legs between nodes starts at the bottom of the     * The vertical element of legs between nodes starts at the bottom of the
1016     * parent node by default. This method makes the leg start below that.     * parent node by default. This method makes the leg start below that.
# Line 1011  public class BasicTreeUI extends TreeUI Line 1022  public class BasicTreeUI extends TreeUI
1022      // FIXME: not implemented      // FIXME: not implemented
1023      return 0;      return 0;
1024    }    }
1025      
1026    /**    /**
1027     * The horizontal element of legs between nodes starts at the right of the     * The horizontal element of legs between nodes starts at the right of the
1028     * left-hand side of the child node by default. This method makes the leg end     * left-hand side of the child node by default. This method makes the leg end
# Line 1024  public class BasicTreeUI extends TreeUI Line 1035  public class BasicTreeUI extends TreeUI
1035      // FIXME: not implemented      // FIXME: not implemented
1036      return 0;      return 0;
1037    }    }
1038      
1039    /**    /**
1040     * Make all the nodes that are expanded in JTree expanded in LayoutCache.     * Make all the nodes that are expanded in JTree expanded in LayoutCache.
1041     * This invokes update ExpandedDescendants with the root path.     * This invokes update ExpandedDescendants with the root path.
# Line 1033  public class BasicTreeUI extends TreeUI Line 1044  public class BasicTreeUI extends TreeUI
1044    {    {
1045      // FIXME: not implemented      // FIXME: not implemented
1046    }    }
1047      
1048    /**    /**
1049     * Updates the expanded state of all the descendants of the <code>path</code>     * Updates the expanded state of all the descendants of the <code>path</code>
1050     * by getting the expanded descendants from the tree and forwarding to the     * by getting the expanded descendants from the tree and forwarding to the
# Line 1045  public class BasicTreeUI extends TreeUI Line 1056  public class BasicTreeUI extends TreeUI
1056    {    {
1057      // FIXME: not implemented      // FIXME: not implemented
1058    }    }
1059      
1060    /**    /**
1061     * Returns a path to the last child of <code>parent</code>     * Returns a path to the last child of <code>parent</code>
1062     *     *
# Line 1056  public class BasicTreeUI extends TreeUI Line 1067  public class BasicTreeUI extends TreeUI
1067    {    {
1068      return ((TreePath) parent.getLastPathComponent());      return ((TreePath) parent.getLastPathComponent());
1069    }    }
1070      
1071    /**    /**
1072     * Updates how much each depth should be offset by.     * Updates how much each depth should be offset by.
1073     */     */
# Line 1064  public class BasicTreeUI extends TreeUI Line 1075  public class BasicTreeUI extends TreeUI
1075    {    {
1076      // FIXME: not implemented      // FIXME: not implemented
1077    }    }
1078      
1079    /**    /**
1080     * Updates the cellEditor based on editability of the JTree that we're     * Updates the cellEditor based on editability of the JTree that we're
1081     * contained in. Ig the tree is editable but doesn't have a cellEditor, a     * contained in. Ig the tree is editable but doesn't have a cellEditor, a
# Line 1074  public class BasicTreeUI extends TreeUI Line 1085  public class BasicTreeUI extends TreeUI
1085    {    {
1086      // FIXME: not implemented      // FIXME: not implemented
1087    }    }
1088      
1089    /**    /**
1090     * Messaged from the tree we're in when the renderer has changed.     * Messaged from the tree we're in when the renderer has changed.
1091     */     */
# Line 1082  public class BasicTreeUI extends TreeUI Line 1093  public class BasicTreeUI extends TreeUI
1093    {    {
1094      // FIXME: not implemented      // FIXME: not implemented
1095    }    }
1096      
1097    /**    /**
1098     * Resets the treeState instance based on the tree we're providing the look     * Resets the treeState instance based on the tree we're providing the look
1099     * and feel for.     * and feel for.
# Line 1091  public class BasicTreeUI extends TreeUI Line 1102  public class BasicTreeUI extends TreeUI
1102    {    {
1103      treeState = createLayoutCache();      treeState = createLayoutCache();
1104    }    }
1105      
1106    /**    /**
1107     * Marks the cached size as being invalid, and messages the tree with     * Marks the cached size as being invalid, and messages the tree with
1108     * <code>treeDidChange</code>.     * <code>treeDidChange</code>.
# Line 1100  public class BasicTreeUI extends TreeUI Line 1111  public class BasicTreeUI extends TreeUI
1111    {    {
1112      // FIXME: not implemented      // FIXME: not implemented
1113    }    }
1114      
1115    /**    /**
1116     * Updates the <code>preferredSize</code> instance variable, which is     * Updates the <code>preferredSize</code> instance variable, which is
1117     * returned from <code>getPreferredSize()</code>. For left to right     * returned from <code>getPreferredSize()</code>. For left to right
# Line 1112  public class BasicTreeUI extends TreeUI Line 1123  public class BasicTreeUI extends TreeUI
1123    {    {
1124      // FIXME: not implemented      // FIXME: not implemented
1125    }    }
1126      
1127    /**    /**
1128     * Messaged from the VisibleTreeNode after it has been expanded.     * Messaged from the VisibleTreeNode after it has been expanded.
1129     *     *
# Line 1122  public class BasicTreeUI extends TreeUI Line 1133  public class BasicTreeUI extends TreeUI
1133    {    {
1134      // FIXME: not implemented      // FIXME: not implemented
1135    }    }
1136      
1137    /**    /**
1138     * Messaged from the VisibleTreeNode after it has collapsed     * Messaged from the VisibleTreeNode after it has collapsed
1139     */     */
# Line 1130  public class BasicTreeUI extends TreeUI Line 1141  public class BasicTreeUI extends TreeUI
1141    {    {
1142      // FIXME: not implemented      // FIXME: not implemented
1143    }    }
1144      
1145    /**    /**
1146     * Install all defaults for the tree.     * Install all defaults for the tree.
1147     *     *
# Line 1139  public class BasicTreeUI extends TreeUI Line 1150  public class BasicTreeUI extends TreeUI
1150    protected void installDefaults(JTree tree)    protected void installDefaults(JTree tree)
1151    {    {
1152      UIDefaults defaults = UIManager.getLookAndFeelDefaults();      UIDefaults defaults = UIManager.getLookAndFeelDefaults();
1153        
1154      tree.setFont(defaults.getFont("Tree.font"));      tree.setFont(defaults.getFont("Tree.font"));
1155      tree.setForeground(defaults.getColor("Tree.foreground"));      tree.setForeground(defaults.getColor("Tree.foreground"));
1156      tree.setBackground(defaults.getColor("Tree.background"));      tree.setBackground(defaults.getColor("Tree.background"));
1157      tree.setOpaque(true);      tree.setOpaque(true);
1158        
1159      rightChildIndent = defaults.getInt("Tree.rightChildIndent");      rightChildIndent = defaults.getInt("Tree.rightChildIndent");
1160      leftChildIndent = defaults.getInt("Tree.leftChildIndent");      leftChildIndent = defaults.getInt("Tree.leftChildIndent");
1161      setRowHeight(defaults.getInt("Tree.rowHeight"));      setRowHeight(defaults.getInt("Tree.rowHeight"));
1162    }    }
1163      
1164    /**    /**
1165     * Install all keyboard actions for this     * Install all keyboard actions for this
1166     */     */
1167    protected void installKeyboardActions()    protected void installKeyboardActions()
1168    {    {
1169    }    }
1170      
1171    /**    /**
1172     * Install all listeners for this     * Install all listeners for this
1173     */     */
# Line 1174  public class BasicTreeUI extends TreeUI Line 1185  public class BasicTreeUI extends TreeUI
1185      if (treeModel != null)      if (treeModel != null)
1186        treeModel.addTreeModelListener(treeModelListener);        treeModel.addTreeModelListener(treeModelListener);
1187    }    }
1188      
1189    /**    /**
1190     * Install the UI for the component     * Install the UI for the component
1191     *     *
# Line 1195  public class BasicTreeUI extends TreeUI Line 1206  public class BasicTreeUI extends TreeUI
1206      installKeyboardActions();      installKeyboardActions();
1207      completeUIInstall();      completeUIInstall();
1208    }    }
1209      
1210    /**    /**
1211     * Uninstall the defaults for the tree     * Uninstall the defaults for the tree
1212     *     *
# Line 1207  public class BasicTreeUI extends TreeUI Line 1218  public class BasicTreeUI extends TreeUI
1218      tree.setForeground(null);      tree.setForeground(null);
1219      tree.setBackground(null);      tree.setBackground(null);
1220    }    }
1221      
1222    /**    /**
1223     * Uninstall the UI for the component     * Uninstall the UI for the component
1224     *     *
# Line 1221  public class BasicTreeUI extends TreeUI Line 1232  public class BasicTreeUI extends TreeUI
1232      tree = null;      tree = null;
1233      completeUIUninstall();      completeUIUninstall();
1234    }    }
1235      
1236    /**    /**
1237     * Paints the specified component appropriate for the look and feel. This     * Paints the specified component appropriate for the look and feel. This
1238     * method is invoked from the ComponentUI.update method when the specified     * method is invoked from the ComponentUI.update method when the specified
# Line 1238  public class BasicTreeUI extends TreeUI Line 1249  public class BasicTreeUI extends TreeUI
1249      JTree tree = (JTree) c;      JTree tree = (JTree) c;
1250      TreeModel mod = tree.getModel();      TreeModel mod = tree.getModel();
1251      if (mod != null)      if (mod != null)
1252      {        {
1253        Object root = mod.getRoot();          Object root = mod.getRoot();
1254          
1255        if (!tree.isRootVisible())          if (!tree.isRootVisible())
1256          tree.expandPath(new TreePath(root));            tree.expandPath(new TreePath(root));
1257          
1258        paintRecursive(g, 0, 0, 0, 0, tree, mod, root);          paintRecursive(g, 0, 0, 0, 0, tree, mod, root);
1259          
1260        if (hasControlIcons())          if (hasControlIcons())
1261          paintControlIcons(g, 0, 0, 0, 0, tree, mod, root);            paintControlIcons(g, 0, 0, 0, 0, tree, mod, root);
1262      }        }
1263    }    }
1264      
1265    /**    /**
1266     * Ensures that the rows identified by beginRow through endRow are visible.     * Ensures that the rows identified by beginRow through endRow are visible.
1267     *     *
# Line 1261  public class BasicTreeUI extends TreeUI Line 1272  public class BasicTreeUI extends TreeUI
1272    {    {
1273      // FIXME: not implemented      // FIXME: not implemented
1274    }    }
1275      
1276    /**    /**
1277     * Sets the preferred minimum size.     * Sets the preferred minimum size.
1278     *     *
# Line 1271  public class BasicTreeUI extends TreeUI Line 1282  public class BasicTreeUI extends TreeUI
1282    {    {
1283      // FIXME: not implemented      // FIXME: not implemented
1284    }    }
1285      
1286    /**    /**
1287     * Gets the preferred minimum size.     * Gets the preferred minimum size.
1288     *     *
# Line 1282  public class BasicTreeUI extends TreeUI Line 1293  public class BasicTreeUI extends TreeUI
1293      // FIXME: not implemented      // FIXME: not implemented
1294      return null;      return null;
1295    }    }
1296      
1297    /**    /**
1298     * Returns the preferred size to properly display the tree, this is a cover     * Returns the preferred size to properly display the tree, this is a cover
1299     * method for getPreferredSize(c, false).     * method for getPreferredSize(c, false).
# Line 1296  public class BasicTreeUI extends TreeUI Line 1307  public class BasicTreeUI extends TreeUI
1307    {    {
1308      return getPreferredSize(c, false);      return getPreferredSize(c, false);
1309    }    }
1310      
1311    /**    /**
1312     * Returns the preferred size to represent the tree in c. If checkConsistancy     * Returns the preferred size to represent the tree in c. If checkConsistancy
1313     * is true, checkConsistancy is messaged first.     * is true, checkConsistancy is messaged first.
# Line 1312  public class BasicTreeUI extends TreeUI Line 1323  public class BasicTreeUI extends TreeUI
1323      int maxWidth = 0;      int maxWidth = 0;
1324      int count = 0;      int count = 0;
1325      if (model != null)      if (model != null)
     {  
       Object node = model.getRoot();  
       if (node != null)  
1326        {        {
1327          maxWidth = (int) (getCellBounds(0, 0, node).getWidth());          Object node = model.getRoot();
1328          while (node != null)          if (node != null)
1329          {            {
1330            count++;              maxWidth = (int) (getCellBounds(0, 0, node).getWidth());
1331            Object nextNode = getNextVisibleNode(node);              while (node != null)
1332            if (nextNode != null)                {
1333              maxWidth = Math.max(maxWidth, (int) (getCellBounds(0, 0, nextNode)                  count++;
1334                  .getWidth()));                  Object nextNode = getNextVisibleNode(node);
1335            node = nextNode;                  if (nextNode != null)
1336          }                    maxWidth = Math.max(
1337                                          maxWidth,
1338                                          (int) (getCellBounds(0, 0, nextNode).getWidth()));
1339                    node = nextNode;
1340                  }
1341              }
1342        }        }
     }  
1343      return new Dimension(maxWidth, (getRowHeight() * count));      return new Dimension(maxWidth, (getRowHeight() * count));
1344    }    }
1345      
1346    /**    /**
1347     * Returns the minimum size for this component. Which will be the min     * Returns the minimum size for this component. Which will be the min
1348     * preferred size or (0,0).     * preferred size or (0,0).
# Line 1343  public class BasicTreeUI extends TreeUI Line 1355  public class BasicTreeUI extends TreeUI
1355      // FIXME: not implemented      // FIXME: not implemented
1356      return getPreferredSize(c);      return getPreferredSize(c);
1357    }    }
1358      
1359    /**    /**
1360     * Returns the maximum size for the component, which will be the preferred     * Returns the maximum size for the component, which will be the preferred
1361     * size if the instance is currently in JTree or (0,0).     * size if the instance is currently in JTree or (0,0).
# Line 1356  public class BasicTreeUI extends TreeUI Line 1368  public class BasicTreeUI extends TreeUI
1368      // FIXME: not implemented      // FIXME: not implemented
1369      return getPreferredSize(c);      return getPreferredSize(c);
1370    }    }
1371      
1372    /**    /**
1373     * Messages to stop the editing session. If the UI the receiver is providing     * Messages to stop the editing session. If the UI the receiver is providing
1374     * the look and feel for returns true from     * the look and feel for returns true from
# Line 1368  public class BasicTreeUI extends TreeUI Line 1380  public class BasicTreeUI extends TreeUI
1380    {    {
1381      // FIXME: not implemented      // FIXME: not implemented
1382    }    }
1383      
1384    /**    /**
1385     * Stops the editing session. If messageStop is true, the editor is messaged     * Stops the editing session. If messageStop is true, the editor is messaged
1386     * with stopEditing, if messageCancel is true the editor is messaged with     * with stopEditing, if messageCancel is true the editor is messaged with
# Line 1384  public class BasicTreeUI extends TreeUI Line 1396  public class BasicTreeUI extends TreeUI
1396    {    {
1397      // FIXME: not implemented      // FIXME: not implemented
1398    }    }
1399      
1400    /**    /**
1401     * Will start editing for node if there is a cellEditor and shouldSelectCall     * Will start editing for node if there is a cellEditor and shouldSelectCall
1402     * returns true. This assumes that path is valid and visible.     * returns true. This assumes that path is valid and visible.
# Line 1398  public class BasicTreeUI extends TreeUI Line 1410  public class BasicTreeUI extends TreeUI
1410      // FIXME: not implemented      // FIXME: not implemented
1411      return false;      return false;
1412    }    }
1413      
1414    /**    /**
1415     * If the <code>mouseX</code> and <code>mouseY</code> are in the expand     * If the <code>mouseX</code> and <code>mouseY</code> are in the expand
1416     * or collapse region of the row, this will toggle the row.     * or collapse region of the row, this will toggle the row.
# Line 1412  public class BasicTreeUI extends TreeUI Line 1424  public class BasicTreeUI extends TreeUI
1424    {    {
1425      // FIXME: not implemented      // FIXME: not implemented
1426    }    }
1427      
1428    /**    /**
1429     * Returns true if the <code>mouseX</code> and <code>mouseY</code> fall     * Returns true if the <code>mouseX</code> and <code>mouseY</code> fall
1430     * in the area of row that is used to expand/collpse the node and the node at     * in the area of row that is used to expand/collpse the node and the node at
# Line 1431  public class BasicTreeUI extends TreeUI Line 1443  public class BasicTreeUI extends TreeUI
1443      // FIXME: not implemented      // FIXME: not implemented
1444      return false;      return false;
1445    }    }
1446      
1447    /**    /**
1448     * Messaged when the user clicks the particular row, this invokes     * Messaged when the user clicks the particular row, this invokes
1449     * toggleExpandState.     * toggleExpandState.
# Line 1444  public class BasicTreeUI extends TreeUI Line 1456  public class BasicTreeUI extends TreeUI
1456    {    {
1457      // FIXME: not implemented      // FIXME: not implemented
1458    }    }
1459      
1460    /**    /**
1461     * Expands path if it is not expanded, or collapses row if it is expanded. If     * Expands path if it is not expanded, or collapses row if it is expanded. If
1462     * expanding a path and JTree scroll on expand, ensureRowsAreVisible is     * expanding a path and JTree scroll on expand, ensureRowsAreVisible is
# Line 1457  public class BasicTreeUI extends TreeUI Line 1469  public class BasicTreeUI extends TreeUI
1469    {    {
1470      // FIXME: not implemented      // FIXME: not implemented
1471    }    }
1472      
1473    /**    /**
1474     * Returning true signifies a mouse event on the node should toggle the     * Returning true signifies a mouse event on the node should toggle the
1475     * selection of only the row under the mouse.     * selection of only the row under the mouse.
# Line 1471  public class BasicTreeUI extends TreeUI Line 1483  public class BasicTreeUI extends TreeUI
1483      // FIXME: not implemented      // FIXME: not implemented
1484      return false;      return false;
1485    }    }
1486      
1487    /**    /**
1488     * Returning true signifies a mouse event on the node should select from the     * Returning true signifies a mouse event on the node should select from the
1489     * anchor point.     * anchor point.
# Line 1485  public class BasicTreeUI extends TreeUI Line 1497  public class BasicTreeUI extends TreeUI
1497      // FIXME: not implemented      // FIXME: not implemented
1498      return false;      return false;
1499    }    }
1500      
1501    /**    /**
1502     * Returning true indicates the row under the mouse should be toggled based     * Returning true indicates the row under the mouse should be toggled based
1503     * on the event. This is invoked after checkForClickInExpandControl, implying     * on the event. This is invoked after checkForClickInExpandControl, implying
# Line 1500  public class BasicTreeUI extends TreeUI Line 1512  public class BasicTreeUI extends TreeUI
1512      // FIXME: not implemented      // FIXME: not implemented
1513      return false;      return false;
1514    }    }
1515      
1516    /**    /**
1517     * Messaged to update the selection based on a MouseEvent over a particular     * Messaged to update the selection based on a MouseEvent over a particular
1518     * row. If the even is a toggle selection event, the row is either selected,     * row. If the even is a toggle selection event, the row is either selected,
# Line 1516  public class BasicTreeUI extends TreeUI Line 1528  public class BasicTreeUI extends TreeUI
1528    {    {
1529      // FIXME: not implemented      // FIXME: not implemented
1530    }    }
1531      
1532    /**    /**
1533     * Returns true if the node at <code>row</code> is a leaf.     * Returns true if the node at <code>row</code> is a leaf.
1534     *     *
# Line 1528  public class BasicTreeUI extends TreeUI Line 1540  public class BasicTreeUI extends TreeUI
1540      TreePath pathForRow = getPathForRow(tree, row);      TreePath pathForRow = getPathForRow(tree, row);
1541      if (pathForRow == null)      if (pathForRow == null)
1542        return true;        return true;
1543        
1544      Object node = pathForRow.getLastPathComponent();      Object node = pathForRow.getLastPathComponent();
1545      return tree.getModel().isLeaf(node);      return tree.getModel().isLeaf(node);
1546    }    }
1547      
1548    /**    /**
1549     * Updates the preferred size when scrolling, if necessary.     * Updates the preferred size when scrolling, if necessary.
1550     */     */
1551    public class ComponentHandler    public class ComponentHandler
1552    extends ComponentAdapter      extends ComponentAdapter
1553    implements ActionListener      implements ActionListener
1554    {    {
1555      /**      /**
1556       * Timer used when inside a scrollpane and the scrollbar is adjusting       * Timer used when inside a scrollpane and the scrollbar is adjusting
1557       */       */
1558      protected Timer timer;      protected Timer timer;
1559        
1560      /** ScrollBar that is being adjusted */      /** ScrollBar that is being adjusted */
1561      protected JScrollBar scrollBar;      protected JScrollBar scrollBar;
1562        
1563      /**      /**
1564       * Constructor       * Constructor
1565       */       */
1566      public ComponentHandler()      public ComponentHandler()
1567      {      {
1568      }      }
1569        
1570      /**      /**
1571       * Invoked when the component's position changes.       * Invoked when the component's position changes.
1572       *       *
# Line 1563  public class BasicTreeUI extends TreeUI Line 1575  public class BasicTreeUI extends TreeUI
1575      public void componentMoved(ComponentEvent e)      public void componentMoved(ComponentEvent e)
1576      {      {
1577      }      }
1578        
1579      /**      /**
1580       * Creats, if necessary, and starts a Timer to check if needed to resize       * Creats, if necessary, and starts a Timer to check if needed to resize
1581       * the bounds       * the bounds
# Line 1571  public class BasicTreeUI extends TreeUI Line 1583  public class BasicTreeUI extends TreeUI
1583      protected void startTimer()      protected void startTimer()
1584      {      {
1585      }      }
1586        
1587      /**      /**
1588       * Returns the JScrollPane housing the JTree, or null if one isn't found.       * Returns the JScrollPane housing the JTree, or null if one isn't found.
1589       *       *
# Line 1581  public class BasicTreeUI extends TreeUI Line 1593  public class BasicTreeUI extends TreeUI
1593      {      {
1594        return null;        return null;
1595      }      }
1596        
1597      /**      /**
1598       * Public as a result of Timer. If the scrollBar is null, or not       * Public as a result of Timer. If the scrollBar is null, or not
1599       * adjusting, this stops the timer and updates the sizing.       * adjusting, this stops the timer and updates the sizing.
# Line 1592  public class BasicTreeUI extends TreeUI Line 1604  public class BasicTreeUI extends TreeUI
1604      {      {
1605      }      }
1606    }// ComponentHandler    }// ComponentHandler
1607      
1608    /**    /**
1609     * Listener responsible for getting cell editing events and updating the tree     * Listener responsible for getting cell editing events and updating the tree
1610     * accordingly.     * accordingly.
1611     */     */
1612    public class CellEditorHandler    public class CellEditorHandler
1613    implements CellEditorListener      implements CellEditorListener
1614    {    {
1615      /**      /**
1616       * Constructor       * Constructor
# Line 1606  public class BasicTreeUI extends TreeUI Line 1618  public class BasicTreeUI extends TreeUI
1618      public CellEditorHandler()      public CellEditorHandler()
1619      {      {
1620      }      }
1621        
1622      /**      /**
1623       * Messaged when editing has stopped in the tree. Tells the listeners       * Messaged when editing has stopped in the tree. Tells the listeners
1624       * editing has stopped.       * editing has stopped.
# Line 1616  public class BasicTreeUI extends TreeUI Line 1628  public class BasicTreeUI extends TreeUI
1628      public void editingStopped(ChangeEvent e)      public void editingStopped(ChangeEvent e)
1629      {      {
1630      }      }
1631        
1632      /**      /**
1633       * Messaged when editing has been canceled in the tree. This tells the       * Messaged when editing has been canceled in the tree. This tells the
1634       * listeners the editor has canceled editing.       * listeners the editor has canceled editing.
# Line 1627  public class BasicTreeUI extends TreeUI Line 1639  public class BasicTreeUI extends TreeUI
1639      {      {
1640      }      }
1641    }// CellEditorHandler    }// CellEditorHandler
1642      
1643    /**    /**
1644     * Repaints the lead selection row when focus is lost/grained.     * Repaints the lead selection row when focus is lost/grained.
1645     */     */
1646    public class FocusHandler    public class FocusHandler
1647    implements FocusListener      implements FocusListener
1648    {    {
1649      /**      /**
1650       * Constructor       * Constructor
# Line 1640  public class BasicTreeUI extends TreeUI Line 1652  public class BasicTreeUI extends TreeUI
1652      public FocusHandler()      public FocusHandler()
1653      {      {
1654      }      }
1655        
1656      /**      /**
1657       * Invoked when focus is activated on the tree we're in, redraws the lead       * Invoked when focus is activated on the tree we're in, redraws the lead
1658       * row. Invoked when a component gains the keyboard focus.       * row. Invoked when a component gains the keyboard focus.
# Line 1650  public class BasicTreeUI extends TreeUI Line 1662  public class BasicTreeUI extends TreeUI
1662      public void focusGained(FocusEvent e)      public void focusGained(FocusEvent e)
1663      {      {
1664      }      }
1665        
1666      /**      /**
1667       * Invoked when focus is deactivated on the tree we're in, redraws the       * Invoked when focus is deactivated on the tree we're in, redraws the
1668       * lead row. Invoked when a component loses the keyboard focus.       * lead row. Invoked when a component loses the keyboard focus.
# Line 1661  public class BasicTreeUI extends TreeUI Line 1673  public class BasicTreeUI extends TreeUI
1673      {      {
1674      }      }
1675    }// FocusHandler    }// FocusHandler
1676      
1677    /**    /**
1678     * This is used to get multiple key down events to appropriately genereate     * This is used to get multiple key down events to appropriately genereate
1679     * events.     * events.
1680     */     */
1681    public class KeyHandler    public class KeyHandler
1682    extends KeyAdapter      extends KeyAdapter
1683    {    {
1684      /** Key code that is being generated for. */      /** Key code that is being generated for. */
1685      protected Action repeatKeyAction;      protected Action repeatKeyAction;
1686        
1687      /** Set to true while keyPressed is active */      /** Set to true while keyPressed is active */
1688      protected boolean isKeyDown;      protected boolean isKeyDown;
1689        
1690      /**      /**
1691       * Constructor       * Constructor
1692       */       */
1693      public KeyHandler()      public KeyHandler()
1694      {      {
1695      }      }
1696        
1697      /**      /**
1698       * Invoked when a key has been typed. Moves the keyboard focus to the       * Invoked when a key has been typed. Moves the keyboard focus to the
1699       * first element whose first letter matches the alphanumeric key pressed       * first element whose first letter matches the alphanumeric key pressed
# Line 1693  public class BasicTreeUI extends TreeUI Line 1705  public class BasicTreeUI extends TreeUI
1705      public void keyTyped(KeyEvent e)      public void keyTyped(KeyEvent e)
1706      {      {
1707      }      }
1708        
1709      /**      /**
1710       * Invoked when a key has been pressed.       * Invoked when a key has been pressed.
1711       *       *
# Line 1706  public class BasicTreeUI extends TreeUI Line 1718  public class BasicTreeUI extends TreeUI
1718        Object last = null;        Object last = null;
1719        if (start != null)        if (start != null)
1720          last = start.getLastPathComponent();          last = start.getLastPathComponent();
1721          
1722        if (last != null)        if (last != null)
1723          {          {
1724            // DOWN, KP_DOWN            // DOWN, KP_DOWN
1725            if (e.getKeyCode() == KeyEvent.VK_DOWN            if (e.getKeyCode() == KeyEvent.VK_DOWN
1726                || e.getKeyCode() == KeyEvent.VK_KP_DOWN)                || e.getKeyCode() == KeyEvent.VK_KP_DOWN)
1727              {              {
1728                Object next = BasicTreeUI.this.                Object next = BasicTreeUI.this.getNextVisibleNode(last);
                 getNextVisibleNode(last);  
1729                if (next != null)                if (next != null)
1730                  {                  {
1731                    TreePath newPath = new TreePath(getPathToRoot(next, 0));                    TreePath newPath = new TreePath(getPathToRoot(next, 0));
# Line 1725  public class BasicTreeUI extends TreeUI Line 1736  public class BasicTreeUI extends TreeUI
1736                      {                      {
1737                        BasicTreeUI.this.tree.expandPath(newPath);                        BasicTreeUI.this.tree.expandPath(newPath);
1738                        try                        try
1739                        {                          {
1740                          BasicTreeUI.this.tree.fireTreeWillExpand(newPath);                            BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
1741                        }                          }
1742                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
1743                        {                                                  {
1744                        }                          }
1745                        BasicTreeUI.this.tree.fireTreeExpanded(newPath);                        BasicTreeUI.this.tree.fireTreeExpanded(newPath);
1746                      }                      }
1747                  }                  }
1748              }              }
1749            // UP, KP_UP            // UP, KP_UP
1750            else if (e.getKeyCode() == KeyEvent.VK_UP            else if (e.getKeyCode() == KeyEvent.VK_UP
1751                || e.getKeyCode() == KeyEvent.VK_KP_UP)                     || e.getKeyCode() == KeyEvent.VK_KP_UP)
1752              {              {
1753                Object prev = BasicTreeUI.this.                Object prev = BasicTreeUI.this.getPreviousVisibleNode(last);
1754                getPreviousVisibleNode(last);  
                 
1755                if (prev != null)                if (prev != null)
1756                  {                  {
1757                    TreePath newPath = new TreePath(getPathToRoot(prev, 0));                    TreePath newPath = new TreePath(getPathToRoot(prev, 0));
1758                    BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,                    BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,
1759                                                new TreePath(getPathToRoot(prev, 0)));                                                new TreePath(getPathToRoot(prev,
1760                                                                             0)));
1761                    if (e.isControlDown())                    if (e.isControlDown())
1762                      tree.setLeadSelectionPath(newPath);                      tree.setLeadSelectionPath(newPath);
1763                    else if (!mod.isLeaf(prev) && e.isShiftDown())                    else if (!mod.isLeaf(prev) && e.isShiftDown())
1764                      {                      {
1765                        BasicTreeUI.this.tree.expandPath(newPath);                        BasicTreeUI.this.tree.expandPath(newPath);
1766                        try                        try
1767                        {                          {
1768                          BasicTreeUI.this.tree.fireTreeWillExpand(newPath);                            BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
1769                        }                          }
1770                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
1771                        {                                                  {
1772                        }                          }
1773                        BasicTreeUI.this.tree.fireTreeExpanded(newPath);                        BasicTreeUI.this.tree.fireTreeExpanded(newPath);
1774                      }                      }
1775                  }                  }
1776              }              }
1777            // LEFT, KP_LEFT            // LEFT, KP_LEFT
1778            else if (e.getKeyCode() == KeyEvent.VK_LEFT            else if (e.getKeyCode() == KeyEvent.VK_LEFT
1779                || e.getKeyCode() == KeyEvent.VK_KP_LEFT)                     || e.getKeyCode() == KeyEvent.VK_KP_LEFT)
1780              {              {
1781                TreePath path = new TreePath(getPathToRoot(last, 0));                TreePath path = new TreePath(getPathToRoot(last, 0));
1782                Object p = getParent(mod.getRoot(), last);                Object p = getParent(mod.getRoot(), last);
1783                  
1784                if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isExpanded(path))                if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isExpanded(path))
1785                  {                  {
1786                    BasicTreeUI.this.tree.collapsePath(path);                    BasicTreeUI.this.tree.collapsePath(path);
1787                    try                    try
1788                    {                      {
1789                      BasicTreeUI.this.tree.fireTreeWillCollapse(path);                        BasicTreeUI.this.tree.fireTreeWillCollapse(path);
1790                    }                      }
1791                    catch (ExpandVetoException ev)                    catch (ExpandVetoException ev)
1792                    {                                              {
1793                    }                      }
1794                    BasicTreeUI.this.tree.fireTreeCollapsed(path);                    BasicTreeUI.this.tree.fireTreeCollapsed(path);
1795                  }                  }
1796                else if (p != null)                else if (p != null)
# Line 1788  public class BasicTreeUI extends TreeUI Line 1799  public class BasicTreeUI extends TreeUI
1799              }              }
1800            // RIGHT, KP_RIGHT            // RIGHT, KP_RIGHT
1801            else if (e.getKeyCode() == KeyEvent.VK_RIGHT            else if (e.getKeyCode() == KeyEvent.VK_RIGHT
1802                || e.getKeyCode() == KeyEvent.VK_KP_RIGHT)                     || e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
1803              {              {
1804                TreePath path = new TreePath(getPathToRoot(last, 0));                TreePath path = new TreePath(getPathToRoot(last, 0));
1805                  
1806                if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isCollapsed(path))                if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isCollapsed(path))
1807                  {                  {
1808                    BasicTreeUI.this.tree.expandPath(path);                    BasicTreeUI.this.tree.expandPath(path);
1809                    try                    try
1810                    {                      {
1811                      BasicTreeUI.this.tree.fireTreeWillExpand(path);                        BasicTreeUI.this.tree.fireTreeWillExpand(path);
1812                    }                      }
1813                    catch (ExpandVetoException ev)                    catch (ExpandVetoException ev)
1814                    {                                              {
1815                    }                      }
1816                    BasicTreeUI.this.tree.fireTreeExpanded(path);                    BasicTreeUI.this.tree.fireTreeExpanded(path);
1817                  }                  }
1818                else                else
1819                  {                  {
1820                    Object next = BasicTreeUI.this.                    Object next = BasicTreeUI.this.getNextVisibleNode(last);
1821                    getNextVisibleNode(last);  
                     
1822                    if (next != null)                    if (next != null)
1823                      BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,                      BasicTreeUI.this.selectPath(
1824                                                  new TreePath(getPathToRoot(next, 0)));                                                  BasicTreeUI.this.tree,
1825                                                    new TreePath(
1826                                                                 getPathToRoot(
1827                                                                               next,
1828                                                                               0)));
1829                  }                  }
1830              }              }
1831            // Enter            // Enter
# Line 1824  public class BasicTreeUI extends TreeUI Line 1838  public class BasicTreeUI extends TreeUI
1838                      {                      {
1839                        BasicTreeUI.this.tree.collapsePath(path);                        BasicTreeUI.this.tree.collapsePath(path);
1840                        try                        try
1841                        {                          {
1842                          BasicTreeUI.this.tree.fireTreeWillCollapse(path);                            BasicTreeUI.this.tree.fireTreeWillCollapse(path);
1843                        }                          }
1844                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
1845                        {                                                  {
1846                        }                          }
1847                        BasicTreeUI.this.tree.fireTreeCollapsed(path);                        BasicTreeUI.this.tree.fireTreeCollapsed(path);
1848                      }                      }
1849                    else                    else
1850                      {                      {
1851                        BasicTreeUI.this.tree.expandPath(path);                        BasicTreeUI.this.tree.expandPath(path);
1852                        try                        try
1853                        {                          {
1854                          BasicTreeUI.this.tree.fireTreeWillExpand(path);                            BasicTreeUI.this.tree.fireTreeWillExpand(path);
1855                        }                          }
1856                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
1857                        {                                                  {
1858                        }                          }
1859                        BasicTreeUI.this.tree.fireTreeExpanded(path);                        BasicTreeUI.this.tree.fireTreeExpanded(path);
1860                      }                      }
1861                  }                  }
1862              }              }
1863          }          }
1864      }      }
1865        
1866      /**      /**
1867       * Invoked when a key has been released       * Invoked when a key has been released
1868       *       *
# Line 1858  public class BasicTreeUI extends TreeUI Line 1872  public class BasicTreeUI extends TreeUI
1872      {      {
1873      }      }
1874    }// KeyHandler    }// KeyHandler
1875      
1876    /**    /**
1877     * MouseListener is responsible for updating the selevtion based on mouse     * MouseListener is responsible for updating the selevtion based on mouse
1878     * events.     * events.
1879     */     */
1880    public class MouseHandler    public class MouseHandler
1881    extends MouseAdapter      extends MouseAdapter
1882    implements MouseMotionListener      implements MouseMotionListener
1883    {    {
1884      /**      /**
1885       * Constructor       * Constructor
# Line 1873  public class BasicTreeUI extends TreeUI Line 1887  public class BasicTreeUI extends TreeUI
1887      public MouseHandler()      public MouseHandler()
1888      {      {
1889      }      }
1890        
1891      /**      /**
1892       * Invoked when a mouse button has been pressed on a component.       * Invoked when a mouse button has been pressed on a component.
1893       *       *
# Line 1882  public class BasicTreeUI extends TreeUI Line 1896  public class BasicTreeUI extends TreeUI
1896      public void mousePressed(MouseEvent e)      public void mousePressed(MouseEvent e)
1897      {      {
1898      }      }
1899        
1900      /**      /**
1901       * Invoked when a mouse button is pressed on a component and then dragged.       * Invoked when a mouse button is pressed on a component and then dragged.
1902       * MOUSE_DRAGGED events will continue to be delivered to the component       * MOUSE_DRAGGED events will continue to be delivered to the component
# Line 1895  public class BasicTreeUI extends TreeUI Line 1909  public class BasicTreeUI extends TreeUI
1909      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
1910      {      {
1911      }      }
1912        
1913      /**      /**
1914       * Invoked when the mouse button has been moved on a component (with no       * Invoked when the mouse button has been moved on a component (with no
1915       * buttons no down).       * buttons no down).
# Line 1905  public class BasicTreeUI extends TreeUI Line 1919  public class BasicTreeUI extends TreeUI
1919      public void mouseMoved(MouseEvent e)      public void mouseMoved(MouseEvent e)
1920      {      {
1921      }      }
1922        
1923      /**      /**
1924       * Invoked when a mouse button has been released on a component.       * Invoked when a mouse button has been released on a component.
1925       *       *
# Line 1915  public class BasicTreeUI extends TreeUI Line 1929  public class BasicTreeUI extends TreeUI
1929      {      {
1930      }      }
1931    }// MouseHandler    }// MouseHandler
1932      
1933    /**    /**
1934     * MouseInputHandler handles passing all mouse events, including mouse motion     * MouseInputHandler handles passing all mouse events, including mouse motion
1935     * events, until the mouse is released to the destination it is constructed     * events, until the mouse is released to the destination it is constructed
1936     * with.     * with.
1937     */     */
1938    public class MouseInputHandler    public class MouseInputHandler
1939    implements MouseInputListener      implements MouseInputListener
1940    {    {
1941      /** Source that events are coming from */      /** Source that events are coming from */
1942      protected Component source;      protected Component source;
1943        
1944      /** Destination that receives all events. */      /** Destination that receives all events. */
1945      protected Component destination;      protected Component destination;
1946        
1947      /** Number of mouse clicks on a non-leaf */      /** Number of mouse clicks on a non-leaf */
1948      private int clickCount = 0;      private int clickCount = 0;
1949        
1950      /** The last non-leaf cell that was clicked */      /** The last non-leaf cell that was clicked */
1951      private Object lastClicked = null;      private Object lastClicked = null;
1952        
1953      /**      /**
1954       * Constructor       * Constructor
1955       *       *
# Line 1947  public class BasicTreeUI extends TreeUI Line 1961  public class BasicTreeUI extends TreeUI
1961                               MouseEvent e)                               MouseEvent e)
1962      {      {
1963      }      }
1964        
1965      /**      /**
1966       * Invoked when the mouse button has been clicked (pressed and released)       * Invoked when the mouse button has been clicked (pressed and released)
1967       * on a component.       * on a component.
# Line 1958  public class BasicTreeUI extends TreeUI Line 1972  public class BasicTreeUI extends TreeUI
1972      {      {
1973        Point click = e.getPoint();        Point click = e.getPoint();
1974        int row = Math.round(click.y / BasicTreeUI.this.getRowHeight());        int row = Math.round(click.y / BasicTreeUI.this.getRowHeight());
1975        TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree,        TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree, click.x,
1976                                                                   click.x, click.y);                                                                   click.y);
1977          
1978        if (path != null)        if (path != null)
1979          {          {
1980            boolean inBounds = false;            boolean inBounds = false;
1981            boolean cntlClick = false;            boolean cntlClick = false;
1982            Rectangle bounds = BasicTreeUI.this.getPathBounds(            Rectangle bounds = BasicTreeUI.this.getPathBounds(
1983                                                              BasicTreeUI.this.tree, path);                                                              BasicTreeUI.this.tree,
1984                                                                          path);
1985    
1986            bounds.x -= rightChildIndent - 4;            bounds.x -= rightChildIndent - 4;
1987            bounds.width += rightChildIndent + 4;            bounds.width += rightChildIndent + 4;
1988              
1989            if (bounds.contains(click.x, click.y))            if (bounds.contains(click.x, click.y))
1990              inBounds = true;              inBounds = true;
1991            else if (BasicTreeUI.this.hasControlIcons()            else if (BasicTreeUI.this.hasControlIcons()
1992                && (click.x < (bounds.x - rightChildIndent + 5) &&                     && (click.x < (bounds.x - rightChildIndent + 5) && click.x > (bounds.x
1993                    click.x > (bounds.x - rightChildIndent - 5)))                                                                                   - rightChildIndent - 5)))
1994              cntlClick = true;              cntlClick = true;
1995              
1996            if ((inBounds || cntlClick)            if ((inBounds || cntlClick) && BasicTreeUI.this.tree.isVisible(path))
               && BasicTreeUI.this.tree.isVisible(path))  
1997              {              {
1998                if (!cntlClick && !BasicTreeUI.this.isLeaf(row))                if (!cntlClick && !BasicTreeUI.this.isLeaf(row))
1999                  {                  {
# Line 1992  public class BasicTreeUI extends TreeUI Line 2006  public class BasicTreeUI extends TreeUI
2006                        clickCount = 1;                        clickCount = 1;
2007                      }                      }
2008                  }                  }
2009                  
2010                if (clickCount == 2 || cntlClick == true)                if (clickCount == 2 || cntlClick == true)
2011                  {                  {
2012                    clickCount = 0;                    clickCount = 0;
# Line 2002  public class BasicTreeUI extends TreeUI Line 2016  public class BasicTreeUI extends TreeUI
2016                      {                      {
2017                        BasicTreeUI.this.tree.collapsePath(path);                        BasicTreeUI.this.tree.collapsePath(path);
2018                        try                        try
2019                        {                          {
2020                          BasicTreeUI.this.tree.fireTreeWillCollapse(path);                            BasicTreeUI.this.tree.fireTreeWillCollapse(path);
2021                        }                          }
2022                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
2023                        {                                                  {
2024                        }                          }
2025                        BasicTreeUI.this.tree.fireTreeCollapsed(path);                        BasicTreeUI.this.tree.fireTreeCollapsed(path);
2026                      }                      }
2027                    else                    else
2028                      {                      {
2029                        BasicTreeUI.this.tree.expandPath(path);                        BasicTreeUI.this.tree.expandPath(path);
2030                        try                        try
2031                        {                          {
2032                          BasicTreeUI.this.tree.fireTreeWillExpand(path);                            BasicTreeUI.this.tree.fireTreeWillExpand(path);
2033                        }                          }
2034                        catch (ExpandVetoException ev)                        catch (ExpandVetoException ev)
2035                        {                                                  {
2036                        }                          }
2037                        BasicTreeUI.this.tree.fireTreeExpanded(path);                        BasicTreeUI.this.tree.fireTreeExpanded(path);
2038                      }                      }
2039                  }                  }
2040                  
2041                BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path);                BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path);
2042              }              }
2043          }          }
2044      }      }
2045        
2046      /**      /**
2047       * Invoked when a mouse button has been pressed on a component.       * Invoked when a mouse button has been pressed on a component.
2048       *       *
# Line 2037  public class BasicTreeUI extends TreeUI Line 2051  public class BasicTreeUI extends TreeUI
2051      public void mousePressed(MouseEvent e)      public void mousePressed(MouseEvent e)
2052      {      {
2053      }      }
2054        
2055      /**      /**
2056       * Invoked when a mouse button has been released on a component.       * Invoked when a mouse button has been released on a component.
2057       *       *
# Line 2046  public class BasicTreeUI extends TreeUI Line 2060  public class BasicTreeUI extends TreeUI
2060      public void mouseReleased(MouseEvent e)      public void mouseReleased(MouseEvent e)
2061      {      {
2062      }      }
2063        
2064      /**      /**
2065       * Invoked when the mouse enters a component.       * Invoked when the mouse enters a component.
2066       *       *
# Line 2055  public class BasicTreeUI extends TreeUI Line 2069  public class BasicTreeUI extends TreeUI
2069      public void mouseEntered(MouseEvent e)      public void mouseEntered(MouseEvent e)
2070      {      {
2071      }      }
2072        
2073      /**      /**
2074       * Invoked when the mouse exits a component.       * Invoked when the mouse exits a component.
2075       *       *
# Line 2064  public class BasicTreeUI extends TreeUI Line 2078  public class BasicTreeUI extends TreeUI
2078      public void mouseExited(MouseEvent e)      public void mouseExited(MouseEvent e)
2079      {      {
2080      }      }
2081        
2082      /**      /**
2083       * Invoked when a mouse button is pressed on a component and then dragged.       * Invoked when a mouse button is pressed on a component and then dragged.
2084       * MOUSE_DRAGGED events will continue to be delivered to the component       * MOUSE_DRAGGED events will continue to be delivered to the component
# Line 2077  public class BasicTreeUI extends TreeUI Line 2091  public class BasicTreeUI extends TreeUI
2091      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
2092      {      {
2093      }      }
2094        
2095      /**      /**
2096       * Invoked when the mouse cursor has been moved onto a component but no       * Invoked when the mouse cursor has been moved onto a component but no
2097       * buttons have been pushed.       * buttons have been pushed.
# Line 2087  public class BasicTreeUI extends TreeUI Line 2101  public class BasicTreeUI extends TreeUI
2101      public void mouseMoved(MouseEvent e)      public void mouseMoved(MouseEvent e)
2102      {      {
2103      }      }
2104        
2105      /**      /**
2106       * Removes event from the source       * Removes event from the source
2107       */       */
# Line 2095  public class BasicTreeUI extends TreeUI Line 2109  public class BasicTreeUI extends TreeUI
2109      {      {
2110      }      }
2111    }// MouseInputHandler    }// MouseInputHandler
2112      
2113    /**    /**
2114     * Class responsible for getting size of node, method is forwarded to     * Class responsible for getting size of node, method is forwarded to
2115     * BasicTreeUI method. X location does not include insets, that is handled in     * BasicTreeUI method. X location does not include insets, that is handled in
2116     * getPathBounds.     * getPathBounds.
2117     */     */
2118    public class NodeDimensionsHandler    public class NodeDimensionsHandler
2119    extends AbstractLayoutCache.NodeDimensions      extends AbstractLayoutCache.NodeDimensions
2120    {    {
2121      /**      /**
2122       * Constructor       * Constructor
# Line 2110  public class BasicTreeUI extends TreeUI Line 2124  public class BasicTreeUI extends TreeUI
2124      public NodeDimensionsHandler()      public NodeDimensionsHandler()
2125      {      {
2126      }      }
2127        
2128      /**      /**
2129       * Responsible for getting the size of a particular node.       * Responsible for getting the size of a particular node.
2130       *       *
# Line 2127  public class BasicTreeUI extends TreeUI Line 2141  public class BasicTreeUI extends TreeUI
2141      {      {
2142        return null;        return null;
2143      }      }
2144        
2145      /**      /**
2146       * Returns the amount to indent the given row       * Returns the amount to indent the given row
2147       *       *
# Line 2138  public class BasicTreeUI extends TreeUI Line 2152  public class BasicTreeUI extends TreeUI
2152        return 0;        return 0;
2153      }      }
2154    }// NodeDimensionsHandler    }// NodeDimensionsHandler
2155      
2156    /**    /**
2157     * PropertyChangeListener for the tree. Updates the appropriate varaible, or     * PropertyChangeListener for the tree. Updates the appropriate varaible, or
2158     * TreeState, based on what changes.     * TreeState, based on what changes.
2159     */     */
2160    public class PropertyChangeHandler    public class PropertyChangeHandler
2161    implements PropertyChangeListener      implements PropertyChangeListener
2162    {    {
2163        
2164      /**      /**
2165       * Constructor       * Constructor
2166       */       */
2167      public PropertyChangeHandler()      public PropertyChangeHandler()
2168      {      {
2169      }      }
2170        
2171      /**      /**
2172       * This method gets called when a bound property is changed.       * This method gets called when a bound property is changed.
2173       *       *
# Line 2164  public class BasicTreeUI extends TreeUI Line 2178  public class BasicTreeUI extends TreeUI
2178      {      {
2179      }      }
2180    }// PropertyChangeHandler    }// PropertyChangeHandler
2181      
2182    /**    /**
2183     * Listener on the TreeSelectionModel, resets the row selection if any of the     * Listener on the TreeSelectionModel, resets the row selection if any of the
2184     * properties of the model change.     * properties of the model change.
2185     */     */
2186    public class SelectionModelPropertyChangeHandler    public class SelectionModelPropertyChangeHandler
2187    implements PropertyChangeListener      implements PropertyChangeListener
2188    {    {
2189        
2190      /**      /**
2191       * Constructor       * Constructor
2192       */       */
2193      public SelectionModelPropertyChangeHandler()      public SelectionModelPropertyChangeHandler()
2194      {      {
2195      }      }
2196        
2197      /**      /**
2198       * This method gets called when a bound property is changed.       * This method gets called when a bound property is changed.
2199       *       *
# Line 2190  public class BasicTreeUI extends TreeUI Line 2204  public class BasicTreeUI extends TreeUI
2204      {      {
2205      }      }
2206    }// SelectionModelPropertyChangeHandler    }// SelectionModelPropertyChangeHandler
2207      
2208    /**    /**
2209     * ActionListener that invokes cancelEditing when action performed.     * ActionListener that invokes cancelEditing when action performed.
2210     */     */
2211    public class TreeCancelEditingAction    public class TreeCancelEditingAction
2212    extends AbstractAction      extends AbstractAction
2213    {    {
2214        
2215      /**      /**
2216       * Constructor       * Constructor
2217       */       */
2218      public TreeCancelEditingAction()      public TreeCancelEditingAction()
2219      {      {
2220      }      }
2221        
2222      /**      /**
2223       * Invoked when an action occurs.       * Invoked when an action occurs.
2224       *       *
# Line 2213  public class BasicTreeUI extends TreeUI Line 2227  public class BasicTreeUI extends TreeUI
2227      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2228      {      {
2229      }      }
2230        
2231      /**      /**
2232       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2233       *       *
# Line 2224  public class BasicTreeUI extends TreeUI Line 2238  public class BasicTreeUI extends TreeUI
2238        return false;        return false;
2239      }      }
2240    }// TreeCancelEditingAction    }// TreeCancelEditingAction
2241      
2242    /**    /**
2243     * Updates the TreeState in response to nodes expanding/collapsing.     * Updates the TreeState in response to nodes expanding/collapsing.
2244     */     */
2245    public class TreeExpansionHandler    public class TreeExpansionHandler
2246    implements TreeExpansionListener      implements TreeExpansionListener
2247    {    {
2248        
2249      /**      /**
2250       * Constructor       * Constructor
2251       */       */
2252      public TreeExpansionHandler()      public TreeExpansionHandler()
2253      {      {
2254      }      }
2255        
2256      /**      /**
2257       * Called whenever an item in the tree has been expanded.       * Called whenever an item in the tree has been expanded.
2258       *       *
# Line 2248  public class BasicTreeUI extends TreeUI Line 2262  public class BasicTreeUI extends TreeUI
2262      {      {
2263        BasicTreeUI.this.tree.repaint();        BasicTreeUI.this.tree.repaint();
2264      }      }
2265        
2266      /**      /**
2267       * Called whenever an item in the tree has been collapsed.       * Called whenever an item in the tree has been collapsed.
2268       *       *
# Line 2259  public class BasicTreeUI extends TreeUI Line 2273  public class BasicTreeUI extends TreeUI
2273        BasicTreeUI.this.tree.repaint();        BasicTreeUI.this.tree.repaint();
2274      }      }
2275    }// TreeExpansionHandler    }// TreeExpansionHandler
2276      
2277    /**    /**
2278     * TreeHomeAction is used to handle end/home actions. Scrolls either the     * TreeHomeAction is used to handle end/home actions. Scrolls either the
2279     * first or last cell to be visible based on direction.     * first or last cell to be visible based on direction.
2280     */     */
2281    public class TreeHomeAction    public class TreeHomeAction
2282    extends AbstractAction      extends AbstractAction
2283    {    {
2284        
2285      /** direction is either home or end */      /** direction is either home or end */
2286      protected int direction;      protected int direction;
2287        
2288      /**      /**
2289       * Constructor       * Constructor
2290       *       *
# Line 2280  public class BasicTreeUI extends TreeUI Line 2294  public class BasicTreeUI extends TreeUI
2294      public TreeHomeAction(int direction, String name)      public TreeHomeAction(int direction, String name)
2295      {      {
2296      }      }
2297        
2298      /**      /**
2299       * Invoked when an action occurs.       * Invoked when an action occurs.
2300       *       *
# Line 2289  public class BasicTreeUI extends TreeUI Line 2303  public class BasicTreeUI extends TreeUI
2303      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2304      {      {
2305      }      }
2306        
2307      /**      /**
2308       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2309       *       *
# Line 2300  public class BasicTreeUI extends TreeUI Line 2314  public class BasicTreeUI extends TreeUI
2314        return false;        return false;
2315      }      }
2316    }// TreeHomeAction    }// TreeHomeAction
2317      
2318    /**    /**
2319     * TreeIncrementAction is used to handle up/down actions. Selection is moved     * TreeIncrementAction is used to handle up/down actions. Selection is moved
2320     * up or down based on direction.     * up or down based on direction.
2321     */     */
2322    public class TreeIncrementAction    public class TreeIncrementAction
2323    extends AbstractAction      extends AbstractAction
2324    {    {
2325        
2326      /** Specifies the direction to adjust the selection by. */      /** Specifies the direction to adjust the selection by. */
2327      protected int direction;      protected int direction;
2328        
2329      /**      /**
2330       * Constructor       * Constructor
2331       *       *
# Line 2321  public class BasicTreeUI extends TreeUI Line 2335  public class BasicTreeUI extends TreeUI
2335      public TreeIncrementAction(int direction, String name)      public TreeIncrementAction(int direction, String name)
2336      {      {
2337      }      }
2338        
2339      /**      /**
2340       * Invoked when an action occurs.       * Invoked when an action occurs.
2341       *       *
# Line 2330  public class BasicTreeUI extends TreeUI Line 2344  public class BasicTreeUI extends TreeUI
2344      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2345      {      {
2346      }      }
2347        
2348      /**      /**
2349       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2350       *       *
# Line 2341  public class BasicTreeUI extends TreeUI Line 2355  public class BasicTreeUI extends TreeUI
2355        return false;        return false;
2356      }      }
2357    }// TreeIncrementAction    }// TreeIncrementAction
2358      
2359    /**    /**
2360     * Forwards all TreeModel events to the TreeState.     * Forwards all TreeModel events to the TreeState.
2361     */     */
2362    public class TreeModelHandler    public class TreeModelHandler
2363    implements TreeModelListener      implements TreeModelListener
2364    {    {
2365      /**      /**
2366       * Constructor       * Constructor
# Line 2354  public class BasicTreeUI extends TreeUI Line 2368  public class BasicTreeUI extends TreeUI
2368      public TreeModelHandler()      public TreeModelHandler()
2369      {      {
2370      }      }
2371        
2372      /**      /**
2373       * Invoked after a node (or a set of siblings) has changed in some way.       * Invoked after a node (or a set of siblings) has changed in some way.
2374       * The node(s) have not changed locations in the tree or altered their       * The node(s) have not changed locations in the tree or altered their
# Line 2370  public class BasicTreeUI extends TreeUI Line 2384  public class BasicTreeUI extends TreeUI
2384      public void treeNodesChanged(TreeModelEvent e)      public void treeNodesChanged(TreeModelEvent e)
2385      {      {
2386      }      }
2387        
2388      /**      /**
2389       * Invoked after nodes have been inserted into the tree. Use e.getPath()       * Invoked after nodes have been inserted into the tree. Use e.getPath()
2390       * to get the parent of the new node(s). e.getChildIndices() returns the       * to get the parent of the new node(s). e.getChildIndices() returns the
# Line 2381  public class BasicTreeUI extends TreeUI Line 2395  public class BasicTreeUI extends TreeUI
2395      public void treeNodesInserted(TreeModelEvent e)      public void treeNodesInserted(TreeModelEvent e)
2396      {      {
2397      }      }
2398        
2399      /**      /**
2400       * Invoked after nodes have been removed from the tree. Note that if a       * Invoked after nodes have been removed from the tree. Note that if a
2401       * subtree is removed from the tree, this method may only be invoked once       * subtree is removed from the tree, this method may only be invoked once
# Line 2395  public class BasicTreeUI extends TreeUI Line 2409  public class BasicTreeUI extends TreeUI
2409      public void treeNodesRemoved(TreeModelEvent e)      public void treeNodesRemoved(TreeModelEvent e)
2410      {      {
2411      }      }
2412        
2413      /**      /**
2414       * Invoked after the tree has drastically changed structure from a given       * Invoked after the tree has drastically changed structure from a given
2415       * node down. If the path returned by e.getPath() is of length one and the       * node down. If the path returned by e.getPath() is of length one and the
# Line 2409  public class BasicTreeUI extends TreeUI Line 2423  public class BasicTreeUI extends TreeUI
2423      {      {
2424      }      }
2425    }// TreeModelHandler    }// TreeModelHandler
2426      
2427    /**    /**
2428     * TreePageAction handles page up and page down events.     * TreePageAction handles page up and page down events.
2429     */     */
2430    public class TreePageAction    public class TreePageAction
2431    extends AbstractAction      extends AbstractAction
2432    {    {
2433      /** Specifies the direction to adjust the selection by. */      /** Specifies the direction to adjust the selection by. */
2434      protected int direction;      protected int direction;
2435        
2436      /**      /**
2437       * Constructor       * Constructor
2438       *       *
# Line 2428  public class BasicTreeUI extends TreeUI Line 2442  public class BasicTreeUI extends TreeUI
2442      public TreePageAction(int direction, String name)      public TreePageAction(int direction, String name)
2443      {      {
2444      }      }
2445        
2446      /**      /**
2447       * Invoked when an action occurs.       * Invoked when an action occurs.
2448       *       *
# Line 2437  public class BasicTreeUI extends TreeUI Line 2451  public class BasicTreeUI extends TreeUI
2451      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2452      {      {
2453      }      }
2454        
2455      /**      /**
2456       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2457       *       *
# Line 2448  public class BasicTreeUI extends TreeUI Line 2462  public class BasicTreeUI extends TreeUI
2462        return false;        return false;
2463      }      }
2464    }// TreePageAction    }// TreePageAction
2465      
2466    /**    /**
2467     * Listens for changes in the selection model and updates the display     * Listens for changes in the selection model and updates the display
2468     * accordingly.     * accordingly.
2469     */     */
2470    public class TreeSelectionHandler    public class TreeSelectionHandler
2471    implements TreeSelectionListener      implements TreeSelectionListener
2472    {    {
2473      /**      /**
2474       * Constructor       * Constructor
# Line 2462  public class BasicTreeUI extends TreeUI Line 2476  public class BasicTreeUI extends TreeUI
2476      public TreeSelectionHandler()      public TreeSelectionHandler()
2477      {      {
2478      }      }
2479        
2480      /**      /**
2481       * Messaged when the selection changes in the tree we're displaying for.       * Messaged when the selection changes in the tree we're displaying for.
2482       * Stops editing, messages super and displays the changed paths.       * Stops editing, messages super and displays the changed paths.
# Line 2473  public class BasicTreeUI extends TreeUI Line 2487  public class BasicTreeUI extends TreeUI
2487      {      {
2488      }      }
2489    }// TreeSelectionHandler    }// TreeSelectionHandler
2490      
2491    /**    /**
2492     * For the first selected row expandedness will be toggled.     * For the first selected row expandedness will be toggled.
2493     */     */
2494    public class TreeToggleAction    public class TreeToggleAction
2495    extends AbstractAction      extends AbstractAction
2496    {    {
2497      /**      /**
2498       * Constructor       * Constructor
# Line 2488  public class BasicTreeUI extends TreeUI Line 2502  public class BasicTreeUI extends TreeUI
2502      public TreeToggleAction(String name)      public TreeToggleAction(String name)
2503      {      {
2504      }      }
2505        
2506      /**      /**
2507       * Invoked when an action occurs.       * Invoked when an action occurs.
2508       *       *
# Line 2497  public class BasicTreeUI extends TreeUI Line 2511  public class BasicTreeUI extends TreeUI
2511      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2512      {      {
2513      }      }
2514        
2515      /**      /**
2516       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2517       *       *
# Line 2508  public class BasicTreeUI extends TreeUI Line 2522  public class BasicTreeUI extends TreeUI
2522        return false;        return false;
2523      }      }
2524    } // TreeToggleAction    } // TreeToggleAction
2525      
2526    /**    /**
2527     * TreeTraverseAction is the action used for left/right keys. Will toggle     * TreeTraverseAction is the action used for left/right keys. Will toggle
2528     * the expandedness of a node, as well as potentially incrementing the     * the expandedness of a node, as well as potentially incrementing the
2529     * selection.     * selection.
2530     */     */
2531    public class TreeTraverseAction    public class TreeTraverseAction
2532    extends AbstractAction      extends AbstractAction
2533    {    {
2534      /**      /**
2535       * Determines direction to traverse, 1 means expand, -1 means collapse.       * Determines direction to traverse, 1 means expand, -1 means collapse.
2536       */       */
2537      protected int direction;      protected int direction;
2538        
2539      /**      /**
2540       * Constructor       * Constructor
2541       *       *
# Line 2531  public class BasicTreeUI extends TreeUI Line 2545  public class BasicTreeUI extends TreeUI
2545      public TreeTraverseAction(int direction, String name)      public TreeTraverseAction(int direction, String name)
2546      {      {
2547      }      }
2548        
2549      /**      /**
2550       * Invoked when an action occurs.       * Invoked when an action occurs.
2551       *       *
# Line 2540  public class BasicTreeUI extends TreeUI Line 2554  public class BasicTreeUI extends TreeUI
2554      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2555      {      {
2556      }      }
2557        
2558      /**      /**
2559       * Returns true if the action is enabled.       * Returns true if the action is enabled.
2560       *       *
# Line 2551  public class BasicTreeUI extends TreeUI Line 2565  public class BasicTreeUI extends TreeUI
2565        return false;        return false;
2566      }      }
2567    } // TreeTraverseAction    } // TreeTraverseAction
2568      
2569    /**    /**
2570     * Returns the cell bounds for painting selected cells     * Returns the cell bounds for painting selected cells
2571     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2569  public class BasicTreeUI extends TreeUI Line 2583  public class BasicTreeUI extends TreeUI
2583          String s = cell.toString();          String s = cell.toString();
2584          Font f = tree.getFont();          Font f = tree.getFont();
2585          FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());          FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());
2586            
2587          if (s != null)          if (s != null)
2588            return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + 4,            return new Rectangle(x, y,
2589                                   SwingUtilities.computeStringWidth(fm, s) + 4,
2590                                 fm.getHeight());                                 fm.getHeight());
2591        }        }
2592      return new Rectangle(x, y, 0, 0);      return new Rectangle(x, y, 0, 0);
2593    }    }
2594      
2595    /**    /**
2596     * Retrieves the location of some node, recursively starting at from     * Retrieves the location of some node, recursively starting at from
2597     * some node.     * some node.
# Line 2591  public class BasicTreeUI extends TreeUI Line 2606  public class BasicTreeUI extends TreeUI
2606     *     *
2607     * @return Point - the location of node     * @return Point - the location of node
2608     */     */
2609    Point getCellLocation(int x, int y, JTree tree, TreeModel mod,    Point getCellLocation(int x, int y, JTree tree, TreeModel mod, Object node,
2610                          Object node, Object startNode)                          Object startNode)
2611    {    {
2612      int rowHeight = getRowHeight();      int rowHeight = getRowHeight();
2613      if (startNode == null || startNode.equals(node))      if (startNode == null || startNode.equals(node))
2614        {        {
2615          if (!tree.isRootVisible() && tree.isExpanded(new TreePath(mod.getRoot())))          if (!tree.isRootVisible()
2616                && tree.isExpanded(new TreePath(mod.getRoot())))
2617            return new Point(x + ((getLevel(node)) * rightChildIndent), y);            return new Point(x + ((getLevel(node)) * rightChildIndent), y);
2618            
2619          return new Point(x + ((getLevel(node) + 1)          return new Point(x + ((getLevel(node) + 1) * rightChildIndent), y);
             * rightChildIndent), y);  
2620        }        }
2621        
2622      if (!mod.isLeaf(startNode)      if (!mod.isLeaf(startNode)
2623          && tree.isExpanded(new TreePath(getPathToRoot(startNode, 0))))          && tree.isExpanded(new TreePath(getPathToRoot(startNode, 0))))
2624        {        {
2625          Object child = mod.getChild(startNode, 0);          Object child = mod.getChild(startNode, 0);
2626          if (child != null)          if (child != null)
2627            return getCellLocation(x, y + rowHeight, tree, mod,            return getCellLocation(x, y + rowHeight, tree, mod, node, child);
                                  node, child);  
2628        }        }
2629        
2630      return getCellLocation(x, y + rowHeight, tree, mod, node,      return getCellLocation(x, y + rowHeight, tree, mod, node,
2631                             getNextVisibleNode(startNode));                             getNextVisibleNode(startNode));
2632    }    }
2633      
2634    /**    /**
2635     * Paints a node in the tree Package private for use in inner classes.     * Paints a node in the tree Package private for use in inner classes.
2636     *     *
# Line 2627  public class BasicTreeUI extends TreeUI Line 2641  public class BasicTreeUI extends TreeUI
2641     * @param node the object to draw     * @param node the object to draw
2642     */     */
2643    void paintNode(Graphics g, int x, int y, JTree tree, Object node,    void paintNode(Graphics g, int x, int y, JTree tree, Object node,
2644        boolean isLeaf)                   boolean isLeaf)
2645    {    {
2646      TreePath curr = new TreePath(getPathToRoot(node, 0));      TreePath curr = new TreePath(getPathToRoot(node, 0));
2647      boolean selected = tree.isPathSelected(curr);      boolean selected = tree.isPathSelected(curr);
# Line 2635  public class BasicTreeUI extends TreeUI Line 2649  public class BasicTreeUI extends TreeUI
2649      boolean hasIcons = false;      boolean hasIcons = false;
2650    
2651      if (tree.isVisible(curr))      if (tree.isVisible(curr))
2652      {        {
2653        TreeCellRenderer dtcr = tree.getCellRenderer();          TreeCellRenderer dtcr = tree.getCellRenderer();
2654        if (dtcr == null)          if (dtcr == null)
2655          dtcr = createDefaultCellRenderer();            dtcr = createDefaultCellRenderer();
2656    
2657        if (!isLeaf)          if (!isLeaf)
2658          expanded = tree.isExpanded(curr);            expanded = tree.isExpanded(curr);
2659    
2660        Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,          Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
2661            expanded, isLeaf, 0, false);                                                          expanded, isLeaf, 0,
2662        rendererPane.paintComponent(g, c, c.getParent(),                                                          false);
2663            getCellBounds(x, y, node));          rendererPane.paintComponent(g, c, c.getParent(), getCellBounds(x, y,
2664      }                                                                         node));
2665          }
2666    }    }
2667      
2668    /**    /**
2669     * Recursively paints all elements of the tree Package private for use in     * Recursively paints all elements of the tree Package private for use in
2670     * inner classes.     * inner classes.
# Line 2665  public class BasicTreeUI extends TreeUI Line 2680  public class BasicTreeUI extends TreeUI
2680     *     *
2681     * @return int - current descent of the tree     * @return int - current descent of the tree
2682     */     */
2683    int paintRecursive(Graphics g, int indentation, int descent,    int paintRecursive(Graphics g, int indentation, int descent, int childNumber,
2684                       int childNumber, int depth, JTree tree, TreeModel mod, Object curr)                       int depth, JTree tree, TreeModel mod, Object curr)
2685    {    {
2686      Rectangle clip = g.getClipBounds();      Rectangle clip = g.getClipBounds();
2687      if (indentation > clip.x + clip.width + rightChildIndent      if (indentation > clip.x + clip.width + rightChildIndent
2688          || descent > clip.y + clip.height + getRowHeight())          || descent > clip.y + clip.height + getRowHeight())
2689        return descent;        return descent;
2690        
2691      int halfHeight = getRowHeight() / 2;      int halfHeight = getRowHeight() / 2;
2692      int halfWidth = rightChildIndent / 2;      int halfWidth = rightChildIndent / 2;
2693      int y0 = descent + halfHeight;      int y0 = descent + halfHeight;
2694      int heightOfLine = descent + halfHeight;      int heightOfLine = descent + halfHeight;
2695      boolean isRootVisible = tree.isRootVisible();      boolean isRootVisible = tree.isRootVisible();
2696        
2697      if (mod.isLeaf(curr))      if (mod.isLeaf(curr))
2698        {        {
2699          paintNode(g, indentation + 4, descent, tree, curr, true);          paintNode(g, indentation + 4, descent, tree, curr, true);
# Line 2692  public class BasicTreeUI extends TreeUI Line 2707  public class BasicTreeUI extends TreeUI
2707              descent += getRowHeight();              descent += getRowHeight();
2708              y0 += halfHeight;              y0 += halfHeight;
2709            }            }
2710            
2711          int max = mod.getChildCount(curr);          int max = mod.getChildCount(curr);
2712          if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))          if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))
2713            {            {
# Line 2701  public class BasicTreeUI extends TreeUI Line 2716  public class BasicTreeUI extends TreeUI
2716                  int indent = indentation + rightChildIndent;                  int indent = indentation + rightChildIndent;
2717                  if (!isRootVisible && depth == 0)                  if (!isRootVisible && depth == 0)
2718                    indent = 0;                    indent = 0;
2719                  else if ((!isRootVisible && !curr.equals(mod.getRoot())) ||                  else if ((!isRootVisible && !curr.equals(mod.getRoot()))
2720                      isRootVisible)                           || isRootVisible)
2721                    {                    {
2722                      g.setColor(getHashColor());                      g.setColor(getHashColor());
2723                      heightOfLine = descent + halfHeight;                      heightOfLine = descent + halfHeight;
2724                      g.drawLine(indentation + halfWidth, heightOfLine, indentation                      g.drawLine(indentation + halfWidth, heightOfLine,
2725                                 + rightChildIndent, heightOfLine);                                 indentation + rightChildIndent, heightOfLine);
2726                    }                    }
2727                    
2728                  descent = paintRecursive(g, indent,                  descent = paintRecursive(g, indent, descent, i, depth + 1,
2729                                           descent, i, depth + 1, tree, mod,                                           tree, mod, mod.getChild(curr, i));
                                          mod.getChild(curr, i));  
2730                }                }
2731            }            }
2732        }        }
2733        
2734      if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))      if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))
2735        if (y0 != heightOfLine && mod.getChildCount(curr) > 0)        if (y0 != heightOfLine && mod.getChildCount(curr) > 0)
2736          {          {
# Line 2724  public class BasicTreeUI extends TreeUI Line 2738  public class BasicTreeUI extends TreeUI
2738            g.drawLine(indentation + halfWidth, y0, indentation + halfWidth,            g.drawLine(indentation + halfWidth, y0, indentation + halfWidth,
2739                       heightOfLine);                       heightOfLine);
2740          }          }
2741        
2742      return descent;      return descent;
2743    }    }
2744      
2745    /**    /**
2746     * Recursively paints all the control icons on the tree.     * Recursively paints all the control icons on the tree.
2747     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2744  public class BasicTreeUI extends TreeUI Line 2758  public class BasicTreeUI extends TreeUI
2758     * @return int - current descent of the tree     * @return int - current descent of the tree
2759     */     */
2760    int paintControlIcons(Graphics g, int indentation, int descent,    int paintControlIcons(Graphics g, int indentation, int descent,
2761                          int childNumber, int depth, JTree tree, TreeModel mod, Object node)                          int childNumber, int depth, JTree tree, TreeModel mod,
2762                            Object node)
2763    {    {
2764      int h = descent;      int h = descent;
2765      int rowHeight = getRowHeight();      int rowHeight = getRowHeight();
2766      Icon ei = UIManager.getLookAndFeelDefaults()      Icon ei = UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon");
2767      .getIcon("Tree.expandedIcon");      Icon ci = UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon");
     Icon ci = UIManager.getLookAndFeelDefaults()  
     .getIcon("Tree.collapsedIcon");  
2768      Rectangle clip = g.getClipBounds();      Rectangle clip = g.getClipBounds();
2769      if (indentation > clip.x + clip.width + rightChildIndent      if (indentation > clip.x + clip.width + rightChildIndent
2770          || descent > clip.y + clip.height + getRowHeight())          || descent > clip.y + clip.height + getRowHeight())
2771        return descent;        return descent;
2772        
2773      if (mod.isLeaf(node))      if (mod.isLeaf(node))
2774        descent += rowHeight;        descent += rowHeight;
2775      else      else
2776        {        {
2777          if (depth > 0 || tree.isRootVisible())          if (depth > 0 || tree.isRootVisible())
2778            descent += rowHeight;            descent += rowHeight;
2779            
2780          int max = mod.getChildCount(node);          int max = mod.getChildCount(node);
2781          if (tree.isExpanded(new TreePath(getPathToRoot(node, 0))))          if (tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
2782            {            {
2783              if (!node.equals(mod.getRoot()))              if (!node.equals(mod.getRoot()))
2784                ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h);                ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h);
2785                
2786              for (int i = 0; i < max; ++i)              for (int i = 0; i < max; ++i)
2787                {                {
2788                  int indent = indentation + rightChildIndent;                  int indent = indentation + rightChildIndent;
2789                  if (depth == 0 && !tree.isRootVisible())                  if (depth == 0 && !tree.isRootVisible())
2790                    indent = -1;                    indent = -1;
2791                    
2792                  descent = paintControlIcons(g, indent,                  descent = paintControlIcons(g, indent, descent, i, depth + 1,
2793                                              descent, i, depth + 1, tree, mod,                                              tree, mod, mod.getChild(node, i));
                                             mod.getChild(node, i));  
2794                }                }
2795            }            }
2796          else if (!node.equals(mod.getRoot()))          else if (!node.equals(mod.getRoot()))
2797            ci.paintIcon(tree, g, indentation - rightChildIndent - 3,            ci.paintIcon(tree, g, indentation - rightChildIndent - 3,
2798                         descent - getRowHeight());                         descent - getRowHeight());
2799        }        }
2800        
2801      return descent;      return descent;
2802    }    }
2803      
2804    /**    /**
2805     * Returns true if the LookAndFeel implements the control icons     * Returns true if the LookAndFeel implements the control icons
2806     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2797  public class BasicTreeUI extends TreeUI Line 2809  public class BasicTreeUI extends TreeUI
2809     */     */
2810    boolean hasControlIcons()    boolean hasControlIcons()
2811    {    {
2812      if (UIManager.getLookAndFeelDefaults().      if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") == null
2813          getIcon("Tree.expandedIcon") == null ||          || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") == null)
         UIManager.getLookAndFeelDefaults().  
         getIcon("Tree.collapsedIcon") == null)  
2814        return false;        return false;
2815      return true;      return true;
2816    }    }
2817      
2818    /**    /**
2819     * Returns the parent of the current node     * Returns the parent of the current node
2820     *     *
# Line 2820  public class BasicTreeUI extends TreeUI Line 2830  public class BasicTreeUI extends TreeUI
2830        return ((TreeNode) node).getParent();        return ((TreeNode) node).getParent();
2831      return findNode(root, node);      return findNode(root, node);
2832    }    }
2833      
2834    /**    /**
2835     * Recursively checks the tree for the specified node, starting     * Recursively checks the tree for the specified node, starting
2836     * at the root.     * at the root.
# Line 2833  public class BasicTreeUI extends TreeUI Line 2843  public class BasicTreeUI extends TreeUI
2843    {    {
2844      TreeModel mod = tree.getModel();      TreeModel mod = tree.getModel();
2845      for (int i = 0; i < mod.getChildCount(root); i++)      for (int i = 0; i < mod.getChildCount(root); i++)
2846      {        {
2847        if (mod.getIndexOfChild(root, node) != -1)          if (mod.getIndexOfChild(root, node) != -1)
2848          return root;            return root;
2849          
2850        Object n = findNode(mod.getChild(root, i), node);          Object n = findNode(mod.getChild(root, i), node);
2851        if (n != null)          if (n != null)
2852          return  n;            return n;
2853      }        }
2854      return null;      return null;
2855    }    }
2856      
2857    /**    /**
2858     * Get next visible node in the tree. Package private for use in inner     * Get next visible node in the tree. Package private for use in inner
2859     * classes.     * classes.
# Line 2856  public class BasicTreeUI extends TreeUI Line 2866  public class BasicTreeUI extends TreeUI
2866    {    {
2867      Object next = null;      Object next = null;
2868      TreePath current = null;      TreePath current = null;
2869        
2870      if (node != null)      if (node != null)
2871        next = getNextNode(node);        next = getNextNode(node);
2872        
2873      if (next != null)      if (next != null)
2874        {        {
2875          current = new TreePath(getPathToRoot(next, 0));          current = new TreePath(getPathToRoot(next, 0));
2876          if (tree.isVisible(current))          if (tree.isVisible(current))
2877            return next;            return next;
2878            
2879          while (next != null && !tree.isVisible(current))          while (next != null && !tree.isVisible(current))
2880            {            {
2881              next = getNextNode(next);              next = getNextNode(next);
2882                
2883              if (next != null)              if (next != null)
2884                current = new TreePath(getPathToRoot(next, 0));                current = new TreePath(getPathToRoot(next, 0));
2885            }            }
2886        }        }
2887      return next;      return next;
2888    }    }
2889      
2890    /**    /**
2891     * Get previous visible node in the tree.     * Get previous visible node in the tree.
2892     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2889  public class BasicTreeUI extends TreeUI Line 2899  public class BasicTreeUI extends TreeUI
2899    {    {
2900      Object prev = null;      Object prev = null;
2901      TreePath current = null;      TreePath current = null;
2902        
2903      if (node != null)      if (node != null)
2904        prev = getPreviousNode(node);        prev = getPreviousNode(node);
2905        
2906      if (prev != null)      if (prev != null)
2907        {        {
2908          current = new TreePath(getPathToRoot(prev, 0));          current = new TreePath(getPathToRoot(prev, 0));
2909          if (tree.isVisible(current))          if (tree.isVisible(current))
2910            return prev;            return prev;
2911            
2912          while (prev != null && !tree.isVisible(current))          while (prev != null && !tree.isVisible(current))
2913            {            {
2914              prev = getPreviousNode(prev);              prev = getPreviousNode(prev);
2915                
2916              if (prev != null)              if (prev != null)
2917                current = new TreePath(getPathToRoot(prev, 0));                current = new TreePath(getPathToRoot(prev, 0));
2918            }            }
2919        }        }
2920      return prev;      return prev;
2921    }    }
2922      
2923    /**    /**
2924     * Returns the next node in the tree     * Returns the next node in the tree
2925     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2925  public class BasicTreeUI extends TreeUI Line 2935  public class BasicTreeUI extends TreeUI
2935    
2936      Object node = curr;      Object node = curr;
2937      Object sibling = null;      Object sibling = null;
2938        
2939      do      do
2940        {        {
2941          sibling = getNextSibling(node);          sibling = getNextSibling(node);
2942          node = getParent(mod.getRoot(), node);          node = getParent(mod.getRoot(), node);
2943        }        }
2944      while (sibling == null &&      while (sibling == null && node != null);
2945             node != null);  
       
2946      return sibling;      return sibling;
2947    }    }
2948    
# Line 2950  public class BasicTreeUI extends TreeUI Line 2959  public class BasicTreeUI extends TreeUI
2959      Object parent = getParent(mod.getRoot(), node);      Object parent = getParent(mod.getRoot(), node);
2960      if (parent == null)      if (parent == null)
2961        return null;        return null;
2962        
2963      Object sibling = getPreviousSibling(node);      Object sibling = getPreviousSibling(node);
2964    
2965      if (sibling == null)      if (sibling == null)
# Line 2958  public class BasicTreeUI extends TreeUI Line 2967  public class BasicTreeUI extends TreeUI
2967    
2968      int size = mod.getChildCount(sibling);      int size = mod.getChildCount(sibling);
2969      while (size > 0)      while (size > 0)
2970      {        {
2971        sibling = mod.getChild(sibling, size - 1);          sibling = mod.getChild(sibling, size - 1);
2972        size = mod.getChildCount(sibling);          size = mod.getChildCount(sibling);
2973      }        }
2974          
2975      return sibling;      return sibling;
2976    }    }
2977      
2978    /**    /**
2979     * Returns the next sibling in the tree     * Returns the next sibling in the tree
2980     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 2981  public class BasicTreeUI extends TreeUI Line 2990  public class BasicTreeUI extends TreeUI
2990        return null;        return null;
2991    
2992      int index = mod.getIndexOfChild(parent, node) + 1;      int index = mod.getIndexOfChild(parent, node) + 1;
2993        
2994      if (index == 0 || index >= mod.getChildCount(parent))      if (index == 0 || index >= mod.getChildCount(parent))
2995        return null;        return null;
2996    
# Line 3009  public class BasicTreeUI extends TreeUI Line 3018  public class BasicTreeUI extends TreeUI
3018    
3019      return mod.getChild(parent, index);      return mod.getChild(parent, index);
3020    }    }
3021      
3022    /**    /**
3023     * Selects the specified path in the tree depending on modes.     * Selects the specified path in the tree depending on modes.
3024     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 3023  public class BasicTreeUI extends TreeUI Line 3032  public class BasicTreeUI extends TreeUI
3032        {        {
3033          if (tree.isPathSelected(path))          if (tree.isPathSelected(path))
3034            tree.removeSelectionPath(path);            tree.removeSelectionPath(path);
3035          else if (tree.getSelectionModel().getSelectionMode()          else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.SINGLE_TREE_SELECTION)
             == TreeSelectionModel.SINGLE_TREE_SELECTION)  
3036            {            {
3037              tree.getSelectionModel().clearSelection();              tree.getSelectionModel().clearSelection();
3038              tree.addSelectionPath(path);              tree.addSelectionPath(path);
3039              tree.setLeadSelectionPath(path);              tree.setLeadSelectionPath(path);
3040            }            }
3041          else if (tree.getSelectionModel().getSelectionMode()          else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
             == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)  
3042            {            {
3043              // TODO              // TODO
3044            }            }
# Line 3044  public class BasicTreeUI extends TreeUI Line 3051  public class BasicTreeUI extends TreeUI
3051            }            }
3052        }        }
3053    }    }
3054      
3055    /**    /**
3056     * Returns the path from node to the root.     * Returns the path from node to the root.
3057     * Package private for use in inner classes.     * Package private for use in inner classes.
# Line 3061  public class BasicTreeUI extends TreeUI Line 3068  public class BasicTreeUI extends TreeUI
3068        {        {
3069          if (depth == 0)          if (depth == 0)
3070            return null;            return null;
3071            
3072          return new Object[depth];          return new Object[depth];
3073        }        }
3074    
3075      Object[] path = getPathToRoot(getParent(mod.getRoot(),      Object[] path = getPathToRoot(getParent(mod.getRoot(), node), depth + 1);
         node), depth + 1);  
3076      path[path.length - depth - 1] = node;      path[path.length - depth - 1] = node;
3077      return path;      return path;
3078    }    }
3079      
3080    /**    /**
3081     * Returns the level of the node in the tree.     * Returns the level of the node in the tree.
3082     *     *
# Line 3091  public class BasicTreeUI extends TreeUI Line 3097  public class BasicTreeUI extends TreeUI
3097    
3098      return count;      return count;
3099    }    }
3100      
3101    /**    /**
3102     * Draws a vertical line using the given graphic context     * Draws a vertical line using the given graphic context
3103     *     *
# Line 3101  public class BasicTreeUI extends TreeUI Line 3107  public class BasicTreeUI extends TreeUI
3107     * @param top specifies the top of the line     * @param top specifies the top of the line
3108     * @param bottom specifies the bottom of the line     * @param bottom specifies the bottom of the line
3109     */     */
3110    protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) {    protected void paintVerticalLine(Graphics g, JComponent c, int x, int top,
3111                                       int bottom)
3112      {
3113      g.drawLine(x, top, x, bottom);      g.drawLine(x, top, x, bottom);
3114    }    }
3115      
3116    /**    /**
3117     * Draws a horizontal line using the given graphic context     * Draws a horizontal line using the given graphic context
3118     *     *
# Line 3114  public class BasicTreeUI extends TreeUI Line 3122  public class BasicTreeUI extends TreeUI
3122     * @param left specifies the left point of the line     * @param left specifies the left point of the line
3123     * @param right specifies the right point of the line     * @param right specifies the right point of the line
3124     */     */
3125    protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) {    protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left,
3126                                         int right)
3127      {
3128      g.drawLine(left, y, right, y);      g.drawLine(left, y, right, y);
3129    }    }
3130      
3131    /**    /**
3132     * Draws an icon at around a specific position     * Draws an icon at around a specific position
3133     *     *
# Line 3129  public class BasicTreeUI extends TreeUI Line 3139  public class BasicTreeUI extends TreeUI
3139     *     *
3140     * FIXME what to do if x < (icon.width / 2). Same with y     * FIXME what to do if x < (icon.width / 2). Same with y
3141     */     */
3142    protected void drawCentered(JComponent c, Graphics g, Icon icon, int x, int y) {    protected void drawCentered(JComponent c, Graphics g, Icon icon, int x, int y)
3143      {
3144      int beginPositionX = x - icon.getIconWidth() / 2;      int beginPositionX = x - icon.getIconWidth() / 2;
3145      int beginPositionY = y - icon.getIconHeight() / 2;      int beginPositionY = y - icon.getIconHeight() / 2;
3146      icon.paintIcon(c, g, beginPositionX, beginPositionY);      icon.paintIcon(c, g, beginPositionX, beginPositionY);
3147    }      }
3148  } // BasicTreeUI  } // BasicTreeUI

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.59

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26