/[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.101 by langel, Tue Oct 18 15:02:42 2005 UTC revision 1.102 by langel, Tue Oct 18 17:46:37 2005 UTC
# Line 225  public class BasicTreeUI Line 225  public class BasicTreeUI
225    
226    /** 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. */
227    protected boolean editorHasDifferentSize;    protected boolean editorHasDifferentSize;
   
   /** Leaf icon for the tree. */  
   Icon leafIcon;  
228        
229    /** The action listener for the editor's Timer. */    /** The action listener for the editor's Timer. */
230    Timer editorTimer = new EditorUpdateTimer();    Timer editorTimer = new EditorUpdateTimer();
# Line 285  public class BasicTreeUI Line 282  public class BasicTreeUI
282    
283      editingRow = -1;      editingRow = -1;
284      lastSelectedRow = -1;      lastSelectedRow = -1;
     leafIcon = UIManager.getIcon("Tree.leafIcon");  
285    }    }
286    
287    /**    /**
# Line 1233  public class BasicTreeUI Line 1229  public class BasicTreeUI
1229      tree.setRowHeight(UIManager.getInt("Tree.rowHeight"));      tree.setRowHeight(UIManager.getInt("Tree.rowHeight"));
1230      tree.requestFocusInWindow(false);      tree.requestFocusInWindow(false);
1231      tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand"));      tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand"));
1232      setExpandedIcon(UIManager.getIcon("Tree.openIcon"));      setExpandedIcon(UIManager.getIcon("Tree.expandedIcon"));
1233      setCollapsedIcon(UIManager.getIcon("Tree.closedIcon"));      setCollapsedIcon(UIManager.getIcon("Tree.collapsedIcon"));
1234    }    }
1235    
1236    /**    /**
# Line 1673  public class BasicTreeUI Line 1669  public class BasicTreeUI
1669            
1670      if (!isLeaf(row))      if (!isLeaf(row))
1671        {        {
1672          if (bounds == null)          bounds = getPathBounds(tree, path);
           bounds = getPathBounds(tree, path);  
1673    
1674          if (hasControlIcons() && (mouseX < bounds.x)          if (hasControlIcons() && (mouseX < bounds.x)
1675              && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth())))              && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap)))
1676            cntlClick = true;            cntlClick = true;
1677        }        }
1678      return cntlClick;      return cntlClick;
# Line 2310  public class BasicTreeUI Line 2305  public class BasicTreeUI
2305            bounds = getPathBounds(tree, path);            bounds = getPathBounds(tree, path);
2306            int row = getRowForPath(tree, path);            int row = getRowForPath(tree, path);
2307            boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);            boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);
2308              
2309            boolean isLeaf = isLeaf(row);            boolean isLeaf = isLeaf(row);
2310              
2311              TreeCellRenderer tcr = getCellRenderer();
2312              Icon icon;
2313            if (isLeaf)            if (isLeaf)
2314              bounds.width += rightChildIndent + gap;              icon = UIManager.getIcon("Tree.leafIcon");
2315            else if (hasControlIcons())            else if (tree.isExpanded(path))
2316              bounds.width += getCurrentControlIcon(path).getIconWidth() + gap;              icon = UIManager.getIcon("Tree.openIcon");
2317              else
2318                icon = UIManager.getIcon("Tree.closedIcon");
2319              
2320              if (tcr instanceof DefaultTreeCellRenderer)
2321                {
2322                 Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon();
2323                 if (tmp != null)
2324                   icon = tmp;
2325                }
2326                        
2327              // add gap*2 for the space before and after the text
2328              if (icon != null)
2329                bounds.width += icon.getIconWidth() + gap*2;
2330    
2331            boolean inBounds = bounds.contains(click.x, click.y);            boolean inBounds = bounds.contains(click.x, click.y);
2332            if ((inBounds || cntlClick) && tree.isVisible(path))            if ((inBounds || cntlClick) && tree.isVisible(path))
2333              {              {
# Line 3013  public class BasicTreeUI Line 3024  public class BasicTreeUI
3024          FontMetrics fm = tree.getToolkit().getFontMetrics(f);          FontMetrics fm = tree.getToolkit().getFontMetrics(f);
3025    
3026          if (s != null)          if (s != null)
3027              return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + gap,              return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s),
3028                                 fm.getHeight());                                 fm.getHeight());
3029        }        }
3030      return new Rectangle(x, y, 0, 0);      return new Rectangle(x, y, 0, 0);
# Line 3232  public class BasicTreeUI Line 3243  public class BasicTreeUI
3243     */     */
3244    boolean hasControlIcons()    boolean hasControlIcons()
3245    {    {
3246      if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null      if (expandedIcon != null || collapsedIcon != null)
         || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") != null)  
3247        return true;        return true;
3248      return false;      return false;
3249    }    }
# Line 3247  public class BasicTreeUI Line 3257  public class BasicTreeUI
3257    Icon getCurrentControlIcon(TreePath path)    Icon getCurrentControlIcon(TreePath path)
3258    {    {
3259      if (tree.isExpanded(path))      if (tree.isExpanded(path))
3260        return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon");        return expandedIcon;
3261      return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon");      return collapsedIcon;
3262    }    }
3263    
3264    /**    /**
# Line 3689  public class BasicTreeUI Line 3699  public class BasicTreeUI
3699            
3700      if (tree.isVisible(path))      if (tree.isVisible(path))
3701        {        {
3702          // need to set exact width of entire row          bounds.width = preferredSize.width;
3703          int iconWidth = 0;          bounds.x += gap;
         if (!isLeaf && hasControlIcons())  
           iconWidth = getCurrentControlIcon(path).getIconWidth();  
         if (isLeaf && leafIcon != null)  
           iconWidth += leafIcon.getIconWidth();  
         else if (isExpanded && expandedIcon != null)  
           iconWidth += expandedIcon.getIconWidth();  
         else if (collapsedIcon != null)  
           iconWidth += collapsedIcon.getIconWidth();  
         bounds.width += bounds.x + iconWidth + gap;  
3704                    
3705          if (editingComponent != null && editingPath != null && isEditing(tree)          if (editingComponent != null && editingPath != null && isEditing(tree)
3706              && node.equals(editingPath.getLastPathComponent()))              && node.equals(editingPath.getLastPathComponent()))
# Line 3715  public class BasicTreeUI Line 3716  public class BasicTreeUI
3716                            
3717              Component c = dtcr.getTreeCellRendererComponent(tree, node,              Component c = dtcr.getTreeCellRendererComponent(tree, node,
3718                                       selected, isExpanded, isLeaf, row, false);                                       selected, isExpanded, isLeaf, row, false);
             bounds.x += gap;  
3719              rendererPane.paintComponent(g, c, c.getParent(), bounds);              rendererPane.paintComponent(g, c, c.getParent(), bounds);
3720            }            }
3721        }        }
# Line 3780  public class BasicTreeUI Line 3780  public class BasicTreeUI
3780        }        }
3781      currentVisiblePath = current;      currentVisiblePath = current;
3782      tree.setVisibleRowCount(getRowCount(tree));      tree.setVisibleRowCount(getRowCount(tree));
3783        if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 &&
3784            currentVisiblePath != null)
3785          tree.addSelectionRow(0);
3786    }    }
3787        
3788    /**    /**

Legend:
Removed from v.1.101  
changed lines
  Added in v.1.102

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