After testing some new apps, I noticed that there was a slight problem
with some custom icons. I almost have it fixed completely.

2005-10-14  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/LookAndFeel.java
        (makeIcon): Implemented.
        * javax/swing/plaf/basic/BasicTreeUI.java
        (updateCachedPreferredSize): Should only add with of control
icon if
        not a leaf.
        (mousePressed): Fixed to use new gap field.
        (paintRecursive): Likewise.
        (paintRow): Likewise.
        (updateCurrentVisiblePath): Shouldn't include root if it is
        not of a valid size to be painted.

Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.5235
diff -u -r1.5235 ChangeLog
--- ChangeLog	14 Oct 2005 20:01:32 -0000	1.5235
+++ ChangeLog	14 Oct 2005 21:38:18 -0000
@@ -1,3 +1,12 @@
+2005-10-14  Lillian Angel  <[EMAIL PROTECTED]>
+
+	* javax/swing/LookAndFeel.java
+	(makeIcon): Implemented.
+	* javax/swing/plaf/basic/BasicTreeUI.java
+	(updateCachedPreferredSize): Should only add with of control icon if
+	not a leaf.
+	(mousePressed): Fixed clicking area
+
 2005-10-14  Audrius Meskauskas  <[EMAIL PROTECTED]>
 
         * org/omg/CORBA/PolicyErrorHelper.java,
Index: javax/swing/LookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/LookAndFeel.java,v
retrieving revision 1.12
diff -u -r1.12 LookAndFeel.java
--- javax/swing/LookAndFeel.java	12 Oct 2005 11:47:19 -0000	1.12
+++ javax/swing/LookAndFeel.java	14 Oct 2005 21:38:20 -0000
@@ -42,8 +42,10 @@
 import java.awt.Component;
 import java.awt.Font;
 import java.awt.Toolkit;
+import java.net.URL;
 
 import javax.swing.border.Border;
+import javax.swing.plaf.IconUIResource;
 import javax.swing.plaf.UIResource;
 import javax.swing.text.JTextComponent;
 
@@ -200,7 +202,14 @@
    */
   public static Object makeIcon(Class baseClass, String gifFile)
   {
-    return null;
+    final URL file = baseClass.getResource(gifFile);
+    return new UIDefaults.LazyValue() 
+      {
+        public Object createValue(UIDefaults table)
+        {
+          return new IconUIResource(new ImageIcon(file));
+        }
+      };
   }
 
   /**
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.97
diff -u -r1.97 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	14 Oct 2005 17:30:31 -0000	1.97
+++ javax/swing/plaf/basic/BasicTreeUI.java	14 Oct 2005 21:38:20 -0000
@@ -246,6 +246,9 @@
   
   /** The current path of the visible nodes in the tree. */
   TreePath currentVisiblePath;
+  
+  /** The gap between the icon and text. */
+  int gap = 4;
 
   /** Listeners */
   private PropertyChangeListener propertyChangeListener;
@@ -631,6 +634,7 @@
         if (treeModel != null)
           {
             Object root = treeModel.getRoot();
+
             if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
               root = getNextNode(root);
 
@@ -723,7 +727,7 @@
   {
     // FIXME: what if root is hidden? should not depend on (0,0)
     // should start counting rows from where root is.
-
+    
     int row = Math.round(y / getRowHeight());
     TreePath path = getPathForRow(tree, row);
 
@@ -1177,12 +1181,13 @@
         for (int i = 0; i < path.length; i++)
           {
             TreePath curr = new TreePath(getPathToRoot(path[i], 0));
-            Rectangle bounds = getPathBounds(tree, 
-                        curr);  
+            Rectangle bounds = getPathBounds(tree, curr);  
+            
             if (treeModel != null)
               isLeaf = treeModel.isLeaf(path[i]);
-            if (hasControlIcons())
+            if (!isLeaf && hasControlIcons())
               bounds.width += getCurrentControlIcon(curr).getIconWidth();
+
             maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
           }
         preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length));
@@ -2303,11 +2308,12 @@
           int row = getRowForPath(tree, path);
           boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);
           
-          if (isLeaf(row))
-              bounds.width += rightChildIndent + 4;
+          boolean isLeaf = isLeaf(row);
+          if (isLeaf)
+            bounds.width += rightChildIndent + gap;
           else if (hasControlIcons())
-            bounds.width += getCurrentControlIcon(path).getIconWidth() + 4;
-
+            bounds.width += getCurrentControlIcon(path).getIconWidth() + gap;
+          
           boolean inBounds = bounds.contains(click.x, click.y);
           if ((inBounds || cntlClick) && tree.isVisible(path))
             {
@@ -2996,8 +3002,7 @@
         FontMetrics fm = tree.getToolkit().getFontMetrics(f);
         
         if (s != null)
-          return new Rectangle(x, y,
-                               SwingUtilities.computeStringWidth(fm, s) + 4,
+          return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + gap,
                                fm.getHeight());
       }
     return new Rectangle(x, y, 0, 0);
@@ -3081,7 +3086,7 @@
     int iconWidth = 0;
     if (!isLeaf && hasControlIcons())
       iconWidth += getCurrentControlIcon(path).getIconWidth();
-    bounds.width += bounds.x + iconWidth;
+    bounds.width += bounds.x + iconWidth + gap;
     
     if (isLeaf)
       {
@@ -3678,7 +3683,7 @@
               dtcr = createDefaultCellRenderer();
             Component c = dtcr.getTreeCellRendererComponent(tree, node,
                                      selected, isExpanded, isLeaf, row, false);
-            bounds.x += 4;
+            bounds.x += gap;
             rendererPane.paintComponent(g, c, c.getParent(), bounds);
           }
       }
@@ -3720,7 +3725,13 @@
   void updateCurrentVisiblePath()
   {
     Object next = treeModel.getRoot();
-    if (!isRootVisible() && tree.isExpanded(new TreePath(next)))
+    Rectangle bounds = getCellBounds(0, 0, next);
+    
+    // If root is not a valid size to be visible, or is
+    // not visible and the tree is expanded, then the next node acts
+    // as the root
+    if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible() 
+        && tree.isExpanded(new TreePath(next))))
       next = getNextNode(next);
     TreePath current = null;
 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to