/[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.11 by langel, Wed Jun 29 13:25:24 2005 UTC revision 1.12 by langel, Thu Jun 30 14:42:56 2005 UTC
# Line 1  Line 1 
1  /* BasicTreeUI.java --  /*
2  Copyright (C) 2002, 2004  Free Software Foundation, Inc.   * BasicTreeUI.java -- Copyright (C) 2002, 2004 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 it
7  it under the terms of the GNU General Public License as published by   * under the terms of the GNU General Public License as published by the Free
8  the Free Software Foundation; either version 2, or (at your option)   * Software Foundation; either version 2, or (at your option) any later version.
9  any later version.   *
10     * GNU Classpath is distributed in the hope that it will be useful, but WITHOUT
11  GNU Classpath is distributed in the hope that it will be useful, but   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  WITHOUT ANY WARRANTY; without even the implied warranty of   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   * details.
14  General Public License for more details.   *
15     * You should have received a copy of the GNU General Public License along with
16  You should have received a copy of the GNU General Public License   * GNU Classpath; see the file COPYING. If not, write to the Free Software
17  along with GNU Classpath; see the file COPYING.  If not, write to the   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   *
19  02111-1307 USA.   * Linking this library statically or dynamically with other modules is making a
20     * combined work based on this library. Thus, the terms and conditions of the
21  Linking this library statically or dynamically with other modules is   * GNU General Public License cover the whole combination.
22  making a combined work based on this library.  Thus, the terms and   *
23  conditions of the GNU General Public License cover the whole   * As a special exception, the copyright holders of this library give you
24  combination.   * permission to link this library with independent modules to produce an
25     * executable, regardless of the license terms of these independent modules, and
26  As a special exception, the copyright holders of this library give you   * to copy and distribute the resulting executable under terms of your choice,
27  permission to link this library with independent modules to produce an   * provided that you also meet, for each linked independent module, the terms
28  executable, regardless of the license terms of these independent   * and conditions of the license of that module. An independent module is a
29  modules, and to copy and distribute the resulting executable under   * module which is not derived from or based on this library. If you modify this
30  terms of your choice, provided that you also meet, for each linked   * library, you may extend this exception to your version of the library, but
31  independent module, the terms and conditions of the license of that   * you are not obligated to do so. If you do not wish to do so, delete this
32  module.  An independent module is a module which is not derived from   * exception statement from your version.
33  or based on this library.  If you modify this library, you may extend   */
 this exception to your version of the library, but you are not  
 obligated to do so.  If you do not wish to do so, delete this  
 exception statement from your version. */  
34    
35  package javax.swing.plaf.basic;  package javax.swing.plaf.basic;
36    
# Line 221  public class BasicTreeUI Line 218  public class BasicTreeUI
218    
219          /** Listeners */          /** Listeners */
220          private PropertyChangeListener propertyChangeListener;          private PropertyChangeListener propertyChangeListener;
   
221          private FocusListener focusListener;          private FocusListener focusListener;
   
222          private TreeSelectionListener treeSelectionListener;          private TreeSelectionListener treeSelectionListener;
   
223          private MouseInputListener mouseInputListener;          private MouseInputListener mouseInputListener;
   
224          private KeyListener keyListener;          private KeyListener keyListener;
   
225          private PropertyChangeListener selectionModelPropertyChangeListener;          private PropertyChangeListener selectionModelPropertyChangeListener;
   
226          private ComponentListener componentListener;          private ComponentListener componentListener;
   
227          private CellEditorListener cellEditorListener;          private CellEditorListener cellEditorListener;
   
228          private TreeExpansionListener treeExpansionListener;          private TreeExpansionListener treeExpansionListener;
   
229          private TreeModelListener treeModelListener;          private TreeModelListener treeModelListener;
230    
231          /**          /**
# Line 564  public class BasicTreeUI Line 552  public class BasicTreeUI
552          {          {
553                  if (newLSM != null)                  if (newLSM != null)
554                  {                  {
                         tree  
                                         .removePropertyChangeListener(selectionModelPropertyChangeListener);  
555                          treeSelectionModel = newLSM;                          treeSelectionModel = newLSM;
                         treeState.setSelectionModel(newLSM);  
                         tree  
                                         .addPropertyChangeListener(selectionModelPropertyChangeListener);  
556                          tree.setSelectionModel(treeSelectionModel);                          tree.setSelectionModel(treeSelectionModel);
557                  }                  }
558          }          }
# Line 599  public class BasicTreeUI Line 582  public class BasicTreeUI
582                  // FIXME: not implemented                  // FIXME: not implemented
583                  return null;                  return null;
584          }          }
585            
586          /**          /**
587           * 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
588           * returned.           * returned.
# Line 619  public class BasicTreeUI Line 602  public class BasicTreeUI
602                          if (pathForRow != null)                          if (pathForRow != null)
603                                  pathForRow = pathForRow.getNextNode();                                  pathForRow = pathForRow.getNextNode();
604                  }                  }
605                    if (pathForRow == null)
606                            return null;
607                  return new TreePath(pathForRow.getPath());                  return new TreePath(pathForRow.getPath());
608          }          }
609    
# Line 635  public class BasicTreeUI Line 620  public class BasicTreeUI
620          public int getRowForPath(JTree tree, TreePath path)          public int getRowForPath(JTree tree, TreePath path)
621          {          {
622                  // FIXME: check visibility                  // FIXME: check visibility
623                  // right now, just returns last element because                  // right now, just returns last element because
624                  // expand/collapse is not implemented                  // expand/collapse is not implemented
625                  return path.getPathCount() - 1;                  return path.getPathCount() - 1;
626          }          }
# Line 1094  public class BasicTreeUI Line 1079  public class BasicTreeUI
1079                  // FIXME: not implemented                  // FIXME: not implemented
1080          }          }
1081    
1082            /**
1083             * Install all defaults for the tree.
1084             *
1085             * @param tree is the JTree to install defaults for
1086             */
1087          protected void installDefaults(JTree tree)          protected void installDefaults(JTree tree)
1088          {          {
1089                  UIDefaults defaults = UIManager.getLookAndFeelDefaults();                  UIDefaults defaults = UIManager.getLookAndFeelDefaults();
# Line 1108  public class BasicTreeUI Line 1098  public class BasicTreeUI
1098                  setRowHeight(defaults.getInt("Tree.rowHeight"));                  setRowHeight(defaults.getInt("Tree.rowHeight"));
1099          }          }
1100    
1101            /**
1102             * Install all keyboard actions for this
1103             */
1104          protected void installKeyboardActions()          protected void installKeyboardActions()
1105          {          {
1106          }          }
1107    
1108            /**
1109             * Install all listeners for this
1110             */
1111          protected void installListeners()          protected void installListeners()
1112          {          {
1113                  tree.addPropertyChangeListener(propertyChangeListener);                  tree.addPropertyChangeListener(propertyChangeListener);
# Line 1126  public class BasicTreeUI Line 1122  public class BasicTreeUI
1122                  treeModel.addTreeModelListener(treeModelListener);                  treeModel.addTreeModelListener(treeModelListener);
1123          }          }
1124    
1125            /**
1126             * Install the UI for the component
1127             *
1128             * @param c the component to install UI for
1129             */
1130          public void installUI(JComponent c)          public void installUI(JComponent c)
1131          {          {
1132                  super.installUI(c);                  super.installUI(c);
# Line 1138  public class BasicTreeUI Line 1139  public class BasicTreeUI
1139                  completeUIInstall();                  completeUIInstall();
1140          }          }
1141    
1142            /**
1143             * Uninstall the defaults for the tree
1144             *
1145             * @param tree to uninstall defaults for
1146             */
1147          protected void uninstallDefaults(JTree tree)          protected void uninstallDefaults(JTree tree)
1148          {          {
1149                  UIDefaults defaults = UIManager.getLookAndFeelDefaults();                  UIDefaults defaults = UIManager.getLookAndFeelDefaults();
# Line 1147  public class BasicTreeUI Line 1153  public class BasicTreeUI
1153                  tree.setCellRenderer(null);                  tree.setCellRenderer(null);
1154          }          }
1155    
1156            /**
1157             * Uninstall the UI for the component
1158             *
1159             * @param c the component to uninstall UI for
1160             */
1161          public void uninstallUI(JComponent c)          public void uninstallUI(JComponent c)
1162          {          {
1163                  uninstallDefaults((JTree) c);                  uninstallDefaults((JTree) c);
# Line 1156  public class BasicTreeUI Line 1167  public class BasicTreeUI
1167                  completeUIUninstall();                  completeUIUninstall();
1168          }          }
1169    
1170            /**
1171             *     Paints the specified component appropriate for the look and feel.
1172             *     This method is invoked from the ComponentUI.update method when the
1173             *     specified component is being painted. Subclasses should override
1174             *     this method and use the specified Graphics object to render the
1175             *     content of the component.
1176             *    
1177             *     @param g the Graphics context in which to paint
1178             *     @param c the component being painted; this argument is often
1179             *     ignored, but might be used if the UI object is stateless and
1180             *     shared by multiple components
1181             */
1182          public void paint(Graphics g, JComponent c)          public void paint(Graphics g, JComponent c)
1183          {          {
1184                  JTree tree = (JTree) c;                  JTree tree = (JTree) c;
# Line 1700  public class BasicTreeUI Line 1723  public class BasicTreeUI
1723                  {                  {
1724                          Point click = e.getPoint();                          Point click = e.getPoint();
1725                          int row = ((int) click.getY() / getRowHeight()) - 1;                          int row = ((int) click.getY() / getRowHeight()) - 1;
1726                        
1727                          if (BasicTreeUI.this.tree.getSelectionModel().getSelectionMode() == treeSelectionModel.SINGLE_TREE_SELECTION)                          if (BasicTreeUI.this.tree.isRowSelected(row))
                                 BasicTreeUI.this.tree.addSelectionRow(row);  
                         else if (BasicTreeUI.this.tree.isRowSelected(row))  
1728                                  BasicTreeUI.this.tree.removeSelectionRow(row);                                  BasicTreeUI.this.tree.removeSelectionRow(row);
1729                            else if (BasicTreeUI.this.tree.getSelectionModel()
1730                                            .getSelectionMode() == treeSelectionModel.SINGLE_TREE_SELECTION)
1731                                    BasicTreeUI.this.tree.addSelectionRow(row);
1732                          // FIXME: add in selection for more than 1 row, or an entire                          // FIXME: add in selection for more than 1 row, or an entire
1733                          // path                          // path
1734                  }                  }
# Line 2232  public class BasicTreeUI Line 2256  public class BasicTreeUI
2256    
2257          /* * HELPER METHODS FOR PAINTING * */          /* * HELPER METHODS FOR PAINTING * */
2258    
2259            /**
2260             * Paints a leaf in the tree
2261             *
2262             * @param g the Graphics context in which to paint
2263             * @param x the x location of the leaf
2264             * @param y the y location of the leaf
2265             * @param tree the tree to draw on
2266             * @param leaf the object to draw
2267             */
2268          private void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf)          private void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf)
2269          {          {
2270                    TreePath tp = new TreePath(((DefaultMutableTreeNode) leaf).getPath());
2271                    boolean selected = tree.isPathSelected(tp);
2272    
2273                  Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,                  Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
2274                                  leaf, false, false, true, 0, false);                                  leaf, selected, false, true, 0, false);
2275    
2276                    if (selected)
2277                    {
2278                            Component comp = tree.getCellRenderer()
2279                                            .getTreeCellRendererComponent(tree, leaf, true, false,
2280                                                            true, 0, false);
2281                            rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10,
2282                                            25));
2283                    }
2284    
2285                  g.translate(x, y);                  g.translate(x, y);
2286                  c.paint(g);                  c.paint(g);
2287                  g.translate(-x, -y);                  g.translate(-x, -y);
2288          }          }
2289    
2290            /**
2291             * Paints a non-leaf in the tree
2292             *
2293             * @param g the Graphics context in which to paint
2294             * @param x the x location of the non-leaf
2295             * @param y the y location of the non-leaf
2296             * @param tree the tree to draw on
2297             * @param nonLeaf the object to draw
2298             */
2299          private void paintNonLeaf(Graphics g, int x, int y, JTree tree,          private void paintNonLeaf(Graphics g, int x, int y, JTree tree,
2300                          Object nonLeaf)                          Object nonLeaf)
2301          {          {
2302                    TreePath tp = new TreePath(((DefaultMutableTreeNode) nonLeaf).getPath());
2303                    boolean selected = tree.isPathSelected(tp);
2304    
2305                  Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,                  Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
2306                                  nonLeaf, false, false, false, 0, false);                                  nonLeaf, selected, false, false, 0, false);
2307    
2308                    if (selected)
2309                    {
2310                            Component comp = tree.getCellRenderer()
2311                                            .getTreeCellRendererComponent(tree, nonLeaf, true, false,
2312                                                            true, 0, false);
2313                            rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10,
2314                                            25));
2315                    }
2316                  g.translate(x, y);                  g.translate(x, y);
2317                  c.paint(g);                  c.paint(g);
2318                  g.translate(-x, -y);                  g.translate(-x, -y);
2319          }          }
2320    
2321            /**
2322             * Recursively paints all elements of the tree
2323             *
2324             * @param g the Graphics context in which to paint
2325             * @param indentation of the current object
2326             * @param descent is the number of elements drawn
2327             * @param childNumber is the index of the current child in the tree
2328             * @param depth is the depth of the current object in the tree
2329             * @param tree is the tree to draw to
2330             * @param mod is the TreeModel we are using to draw
2331             * @param curr is the current object to draw
2332             *
2333             * @return int - current descent of the tree
2334             */
2335          private int paintRecursive(Graphics g, int indentation, int descent,          private int paintRecursive(Graphics g, int indentation, int descent,
2336                          int childNumber, int depth, JTree tree, TreeModel mod, Object curr)                          int childNumber, int depth, JTree tree, TreeModel mod, Object curr)
2337          {          {

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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