/[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.35 by langel, Thu Jul 14 19:26:47 2005 UTC revision 1.36 by langel, Fri Jul 15 17:36:10 2005 UTC
# Line 1922  public class BasicTreeUI Line 1922  public class BasicTreeUI
1922        public void mouseClicked(MouseEvent e)        public void mouseClicked(MouseEvent e)
1923        {        {
1924           Point click = e.getPoint();           Point click = e.getPoint();
1925           int row = ((int) click.getY() / getRowHeight()) - 1;           int clickX = (int) click.getX();
1926             int clickY = (int) click.getY();
1927             int row = (clickY  / getRowHeight()) - 1;
1928           TreePath path = BasicTreeUI.this.tree.getPathForRow(row);           TreePath path = BasicTreeUI.this.tree.getPathForRow(row);
1929            
1930             // check if clicked in row area
1931             boolean inBounds = false;
1932             Object cell = path.getLastPathComponent();
1933             TreeModel mod = tree.getModel();
1934             Point loc = getCellLocation(0, 0, tree, mod, cell, mod.getRoot());
1935             int x = (int) loc.getX();
1936             int y = (int) loc.getY();
1937             Rectangle bounds = BasicTreeUI.this.getCellBounds(x, y, cell);
1938             if ((clickY >= (y - 10) && clickY <= (y + bounds.height + 10))
1939                   && (clickX >= x && clickX <= (x + bounds.width + 25)))
1940                inBounds = true;
1941    
1942           if (path == null)           if (inBounds && path != null && BasicTreeUI.this.tree.isVisible(path))
          {  
             // nothing should be selected if user clicks outside of tree  
             BasicTreeUI.this.tree.getSelectionModel().clearSelection();  
             BasicTreeUI.this.tree.repaint();  
          }  
          else if (BasicTreeUI.this.tree.isVisible(path))  
1943           {                     {          
1944              if (!BasicTreeUI.this.isLeaf(row))              if (!BasicTreeUI.this.isLeaf(row))
1945                 clickCount++;                 clickCount++;
# Line 2479  public class BasicTreeUI Line 2487  public class BasicTreeUI
2487        }        }
2488     } // TreeTraverseAction     } // TreeTraverseAction
2489    
    /* * HELPER METHODS FOR PAINTING * */  
   
2490     /**     /**
2491      * Returns the cell bounds for painting selected cells      * Returns the cell bounds for painting selected cells
2492      *      *
# Line 2497  public class BasicTreeUI Line 2503  public class BasicTreeUI
2503           String s = cell.toString();           String s = cell.toString();
2504           Font f = tree.getFont();           Font f = tree.getFont();
2505           FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());           FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());
2506            
2507           return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s),           return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s),
2508                 fm.getHeight());                 fm.getHeight());
2509        }        }
# Line 2505  public class BasicTreeUI Line 2511  public class BasicTreeUI
2511     }     }
2512    
2513     /**     /**
2514        * Retrieves the location of some node, recursively starting at from
2515        * some node.
2516        *
2517        * @param x is the starting x position, offset
2518        * @param y is the starting y position, offset
2519        * @param tree is the tree to traverse
2520        * @param mod is the TreeModel to use
2521        * @param node is the node to get the location for
2522        * @param startNode is the node to start searching from
2523        *
2524        * @return Point - the location of node
2525        */
2526       private Point getCellLocation(int x, int y, JTree tree, TreeModel mod,
2527             Object node, Object startNode)
2528       {
2529          int rowHeight = getRowHeight();
2530          if (startNode == null || startNode.equals(node))
2531             return new Point(x + ((((DefaultMutableTreeNode) node).
2532                   getLevel() + 1) * rightChildIndent), y);
2533    
2534          if (!mod.isLeaf(startNode)
2535                && tree.isExpanded(new TreePath(
2536                      ((DefaultMutableTreeNode) startNode).getPath())))
2537          {
2538             Object child = mod.getChild(startNode, 0);
2539             if (child != null)
2540                return getCellLocation(x, y + rowHeight, tree, mod,
2541                      node, child);
2542          }
2543          
2544             return getCellLocation(x, y + rowHeight, tree, mod, node,
2545                   getNextVisibleNode((DefaultMutableTreeNode) startNode));
2546       }
2547      
2548       /**
2549      * Paints a leaf in the tree      * Paints a leaf in the tree
2550      *      *
2551      * @param g the Graphics context in which to paint      * @param g the Graphics context in which to paint
# Line 2734  public class BasicTreeUI Line 2775  public class BasicTreeUI
2775           return descent;           return descent;
2776                
2777        if (mod.isLeaf(node))        if (mod.isLeaf(node))
       {  
2778           descent += rowHeight;           descent += rowHeight;
       }  
2779        else        else
2780        {        {
2781           if (depth > 0 || tree.isRootVisible())           if (depth > 0 || tree.isRootVisible())
          {  
2782              descent += rowHeight;              descent += rowHeight;
          }  
2783                    
2784           int max = mod.getChildCount(node);           int max = mod.getChildCount(node);
2785           if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node)           if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node)

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

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