Fixed more NPEs. It appears that after the latest painting fixes,
editing does not paint properly :( I will look into this.\



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

        * javax/swing/plaf/basic/BasicTreeUI.java
        (getPreferredSize): Added check to prevent NPE.
        (mousePressed): Likewise.
        (paintRecursive): Likewise.
        (paintExpandedControlIcons): Likewise.
        (paintRow): Fixed painting location of textarea.


On Thu, 2005-10-13 at 10:17 -0400, Lillian Angel wrote:
> Sorry about that. I fixed this.
> Also, it seemed that the width was not being calculated properly, so the
> labels were cut off. I fixed this too.
> 
> 
> 2005-10-13  Lillian Angel  <[EMAIL PROTECTED]>
> 
>         * javax/swing/plaf/basic/BasicTreeUI.java
>         (getPathForRow): Added check to prevent NPE.
>         (getRowCount): Likewise.
>         (getRowForPath): Likewise.
>         (getPreferredSize): Adjusted width depending on x location and
>         icon.
>         (paintRecursive): Likewise.
>         (getPreviousNode): Added check to prevent NPE.
>         (getNextVisibleNode): Likewise.
> 
> 
> On Wed, 2005-10-12 at 23:10 +0200, Mark Wielaard wrote:
> > Hi Lillian,
> > 
> > On Wed, 2005-10-05 at 17:28 -0400, Lillian Angel wrote:
> > > Fixed up BasicTreeUI because it was not efficent when painting.
> > > 
> > > 2005-10-05  Lillian Angel  <[EMAIL PROTECTED]>
> > > 
> > >         * javax/swing/plaf/metal/MetalTreeUI.java
> > >         (installUI): Fixed to call toggleExpandState instead.
> > >         * javax/swing/plaf/basic/BasicTreeUI.java
> > >         (getPathForRow): Used currentVisiblePath to get Path.
> > >         (getRowForPath): Used currentVisiblePath to get row.
> > >         (getRowCount): Returned currentVisiblePath length.
> > >         (updateLayoutCacheExpandedNodes): Took out unneeded code.
> > >         (installUI): Fixed to call toggleExpandState instead.
> > >         (getPreferredSize): Made more efficent by using 
> > >   currentVisiblePath.
> > >         (toggleExpandState): Called updateCurrentVisiblePath.
> > >         (getCellLocation): Made more efficent.
> > >         (paintNode): Removed.
> > >         (paintRecursive): Made more efficent, changed paintNode calls to
> > >         paintRow.
> > >         (getNextVisibleNode): Reimplemented to use currentVisiblePath.
> > >         (getPreviousVisibleNode): Likewise.
> > >         (paintRow): Implemented.
> > >         (updateCurrentVisiblePath): New helper used to cache the current
> > >         visible path.
> > 
> > This broke junit for me (see stack trace below). The problem is that
> > newly introduces currentVisiblePath field can be NULL, but is used in
> > various places without checking whether or not it is NUll.
> > 
> > java.lang.NullPointerException
> >    at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize 
> > (BasicTreeUI.java:1474)
> >    at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize 
> > (BasicTreeUI.java:1457)
> >    at javax.swing.JComponent.getPreferredSize (JComponent.java:1083)
> >    at javax.swing.JViewport.getViewSize (JViewport.java:297)
> >    at javax.swing.plaf.basic.BasicScrollPaneUI.syncScrollPaneWithViewport 
> > (BasicScrollPaneUI.java:434)
> >    at 
> > javax.swing.plaf.basic.BasicScrollPaneUI$ViewportChangeHandler.stateChanged 
> > (BasicScrollPaneUI.java:160)
> >    at javax.swing.JViewport.fireStateChanged (JViewport.java:623)
> >    at javax.swing.JViewport.revalidate (JViewport.java:422)
> >    at javax.swing.JComponent$1.run (JComponent.java:2111)
> >    at java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:191)
> >    at java.awt.EventQueue.dispatchEvent (EventQueue.java:465)
> >    at java.awt.EventDispatchThread.run (EventDispatchThread.java:75)
> > 
> _______________________________________________
> Classpath-patches mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/classpath-patches
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.92
diff -u -r1.92 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	13 Oct 2005 14:17:48 -0000	1.92
+++ javax/swing/plaf/basic/BasicTreeUI.java	13 Oct 2005 16:05:01 -0000
@@ -1475,6 +1475,7 @@
   {
     // FIXME: checkConsistancy not implemented, c not used
     int maxWidth = 0;
+    int iconWidth = 0;
     if (currentVisiblePath != null)
       {
         Object[] path = currentVisiblePath.getPath();
@@ -1483,8 +1484,11 @@
             TreePath curr = new TreePath(getPathToRoot(path[i], 0));
             Rectangle bounds = getPathBounds(tree, 
                         curr);
+            iconWidth = 0;
+            if (hasControlIcons())
+              iconWidth = getCurrentControlIcon(curr).getIconWidth();
             maxWidth = Math.max(maxWidth, bounds.x + bounds.width
-                                + getCurrentControlIcon(curr).getIconWidth());
+                                + iconWidth);
           }
         return new Dimension(maxWidth, (getRowHeight() * path.length));
       }
@@ -1663,9 +1667,8 @@
         if (bounds == null)
           bounds = getPathBounds(tree, path);
 
-        Icon controlIcon = getCurrentControlIcon(path);
-        if (controlIcon != null && (mouseX < bounds.x) 
-            && (mouseX > (bounds.x - controlIcon.getIconWidth())))
+        if (hasControlIcons() && (mouseX < bounds.x) 
+            && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth())))
           cntlClick = true;
       }
     return cntlClick;
@@ -3066,6 +3069,9 @@
     boolean isLeaf = mod.isLeaf(curr);
     Rectangle bounds = getPathBounds(tree, path);
     Object root = mod.getRoot();
+    int iconWidth = 0;
+    if (hasControlIcons())
+      iconWidth = getCurrentControlIcon(path).getIconWidth();      
     
     if (isLeaf)
       {
@@ -3075,7 +3081,7 @@
       }
     else
       {
-        bounds.width += bounds.x + getCurrentControlIcon(path).getIconWidth();
+        bounds.width += bounds.x + iconWidth;
         if (depth > 0 || isRootVisible)
           {
             paintRow(g, clip, null, bounds, path, row, isExpanded, false, false);
@@ -3582,7 +3588,7 @@
                                     boolean isExpanded, boolean hasBeenExpanded,
                                     boolean isLeaf)
   {
-    if (treeModel != null)
+    if (treeModel != null && hasControlIcons())
       paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, path.getLastPathComponent());
   }
 
@@ -3648,16 +3654,17 @@
     boolean selected = tree.isPathSelected(path);
     boolean hasIcons = false;
     Object node = path.getLastPathComponent();
-
+    
     if (tree.isVisible(path))
       {
         if (editingComponent != null && editingPath != null && isEditing(tree)
             && node.equals(editingPath.getLastPathComponent()))
           {
+            if (hasControlIcons())
+              bounds.x += getCurrentControlIcon(path).getIconWidth() - 5;
+            bounds.width = editingComponent.getSize().width + bounds.x;
             rendererPane.paintComponent(g, editingComponent.getParent(), null,
-                                        new Rectangle(getCurrentControlIcon(path).
-                                                      getIconWidth() - 5, 0, bounds.width, 
-                                                      bounds.height));
+                                        bounds);
           }
         else
           {
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to