/[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.13 by mark, Sat Jul 2 20:32:50 2005 UTC revision 1.14 by langel, Mon Jul 4 14:41:23 2005 UTC
# Line 37  package javax.swing.plaf.basic; Line 37  package javax.swing.plaf.basic;
37  import java.awt.Color;  import java.awt.Color;
38  import java.awt.Component;  import java.awt.Component;
39  import java.awt.Dimension;  import java.awt.Dimension;
40    import java.awt.Font;
41    import java.awt.FontMetrics;
42  import java.awt.Graphics;  import java.awt.Graphics;
43  import java.awt.Point;  import java.awt.Point;
44  import java.awt.Rectangle;  import java.awt.Rectangle;
# Line 85  import javax.swing.tree.FixedHeightLayou Line 87  import javax.swing.tree.FixedHeightLayou
87  import javax.swing.tree.DefaultMutableTreeNode;  import javax.swing.tree.DefaultMutableTreeNode;
88  import javax.swing.tree.DefaultTreeCellEditor;  import javax.swing.tree.DefaultTreeCellEditor;
89  import javax.swing.tree.DefaultTreeCellRenderer;  import javax.swing.tree.DefaultTreeCellRenderer;
90    import javax.swing.SwingUtilities;
91  import javax.swing.tree.TreeCellEditor;  import javax.swing.tree.TreeCellEditor;
92  import javax.swing.tree.TreeCellRenderer;  import javax.swing.tree.TreeCellRenderer;
93  import javax.swing.tree.TreeSelectionModel;  import javax.swing.tree.TreeSelectionModel;
# Line 1723  public class BasicTreeUI Line 1726  public class BasicTreeUI
1726                  {                  {
1727                          Point click = e.getPoint();                          Point click = e.getPoint();
1728                          int row = ((int) click.getY() / getRowHeight()) - 1;                          int row = ((int) click.getY() / getRowHeight()) - 1;
1729                            
1730                          if (BasicTreeUI.this.tree.isRowSelected(row))                          if (BasicTreeUI.this.tree.isRowSelected(row))
1731                                  BasicTreeUI.this.tree.removeSelectionRow(row);                                  BasicTreeUI.this.tree.removeSelectionRow(row);
1732                          else if (BasicTreeUI.this.tree.getSelectionModel()                          else if (BasicTreeUI.this.tree.getSelectionModel()
1733                                          .getSelectionMode() == treeSelectionModel.SINGLE_TREE_SELECTION)                                          .getSelectionMode() ==
1734                                                    treeSelectionModel.SINGLE_TREE_SELECTION)
1735                            {
1736                                    // clear selection, since only able to select one row at a time.
1737                                    BasicTreeUI.this.tree.getSelectionModel().clearSelection();
1738                                    BasicTreeUI.this.tree.addSelectionRow(row);
1739                            }
1740                            else if (BasicTreeUI.this.tree.getSelectionModel()
1741                                            .getSelectionMode() ==
1742                                                    treeSelectionModel.CONTIGUOUS_TREE_SELECTION)
1743                            {
1744                                    //TODO
1745                            }
1746                            else
1747                            {
1748                                    BasicTreeUI.this.tree.getSelectionModel()
1749                                    .setSelectionMode(
1750                                                    treeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
1751                                  BasicTreeUI.this.tree.addSelectionRow(row);                                  BasicTreeUI.this.tree.addSelectionRow(row);
1752                          // FIXME: add in selection for more than 1 row, or an entire                          }
                         // path  
1753                  }                  }
1754    
1755                  /**                  /**
# Line 2257  public class BasicTreeUI Line 2276  public class BasicTreeUI
2276          /* * HELPER METHODS FOR PAINTING * */          /* * HELPER METHODS FOR PAINTING * */
2277    
2278          /**          /**
2279             * Returns the cell bounds for painting selected cells
2280             *
2281             * @param x is the x location of the cell
2282             * @param y is the y location of the cell
2283             * @param cell is the Object to get the bounds for
2284             *
2285             * @returns Rectangle that represents the cell bounds
2286             */
2287            private Rectangle getCellBounds(int x, int y, Object cell)
2288            {
2289                    String s = cell.toString();
2290                    Font f = tree.getFont();
2291                    FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());
2292    
2293                    return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), fm
2294                                    .getHeight());
2295            }
2296    
2297            /**
2298           * Paints a leaf in the tree           * Paints a leaf in the tree
2299           *           *
2300           * @param g the Graphics context in which to paint           * @param g the Graphics context in which to paint
# Line 2270  public class BasicTreeUI Line 2308  public class BasicTreeUI
2308                  TreePath tp = new TreePath(((DefaultMutableTreeNode) leaf).getPath());                  TreePath tp = new TreePath(((DefaultMutableTreeNode) leaf).getPath());
2309                  boolean selected = tree.isPathSelected(tp);                  boolean selected = tree.isPathSelected(tp);
2310    
                 Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,  
                                 leaf, selected, false, true, 0, false);  
   
2311                  if (selected)                  if (selected)
2312                  {                  {
2313                          Component comp = tree.getCellRenderer()                          Component comp = tree.getCellRenderer()
2314                                          .getTreeCellRendererComponent(tree, leaf, true, false,                                          .getTreeCellRendererComponent(tree, leaf, true, false,
2315                                                          true, 0, false);                                                          true, 0, false);
2316                          rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10,                          rendererPane.paintComponent(g, comp, tree, getCellBounds(x, y, leaf));
2317                                          25));                  }
2318                    else
2319                    {
2320                            Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
2321                                            leaf, false, false, true, 0, false);
2322                            
2323                            g.translate(x, y);
2324                            c.paint(g);
2325                            g.translate(-x, -y);
2326                  }                  }
   
                 g.translate(x, y);  
                 c.paint(g);  
                 g.translate(-x, -y);  
2327          }          }
2328    
2329          /**          /**
# Line 2302  public class BasicTreeUI Line 2341  public class BasicTreeUI
2341                  TreePath tp = new TreePath(((DefaultMutableTreeNode) nonLeaf).getPath());                  TreePath tp = new TreePath(((DefaultMutableTreeNode) nonLeaf).getPath());
2342                  boolean selected = tree.isPathSelected(tp);                  boolean selected = tree.isPathSelected(tp);
2343    
                 Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,  
                                 nonLeaf, selected, false, false, 0, false);  
   
2344                  if (selected)                  if (selected)
2345                  {                  {
2346                          Component comp = tree.getCellRenderer()                          Component comp = tree.getCellRenderer()
2347                                          .getTreeCellRendererComponent(tree, nonLeaf, true, false,                                          .getTreeCellRendererComponent(tree, nonLeaf, true, false,
2348                                                          true, 0, false);                                                          true, 0, false);
2349                          rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10,                          rendererPane.paintComponent(g, comp, tree, getCellBounds(x, y, nonLeaf));
2350                                          25));                  }
2351                    else
2352                    {
2353                            Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
2354                                            nonLeaf, false, false, false, 0, false);
2355                            
2356                            g.translate(x, y);
2357                            c.paint(g);
2358                            g.translate(-x, -y);
2359                  }                  }
                 g.translate(x, y);  
                 c.paint(g);  
                 g.translate(-x, -y);  
2360          }          }
2361    
2362          /**          /**

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

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