Hey,

This patch fixes a few bugs exposed by Bugzilla Bug #203674.  I think
the ChangeLog explains the changes well.

Could someone kindly approve/comment on this patch.

Thanks,
Tania

2006-08-28  Tania Bento  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTableUI.java
        (getPreferredSize): The number of iterations for the for-loop should be
the number of columns in the table's column model, not the number of
columns of the table.
        * gnu/java/awt/peer/gtk/ComponentGraphics.java
        (drawImage): Added a try/catch block to prevent a NullPointerException
from being thrown.
        * javax/swing/JTable.java
        (JTable(TableModel, TableColumnModel, ListSelectionModel): Removed 4
lines that are not needed.
        (initializeLocalVars): dragEnabled should be set to false, not true.
        (getCellRenderer): Added a check to prevent an
ArrayIndexOutOfBoundsException.
        (doLayout): The number of iterations for the for-loops should be the
number of columns in the table's column model, not the number of columns
of the table.
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.20
diff -u -r1.20 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	3 Aug 2006 08:08:13 -0000	1.20
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	28 Sep 2006 20:35:54 -0000
@@ -107,8 +107,8 @@
     Integer i = (Integer) hasLock.get();
     if (i == null)
       {
-	start_gdk_drawing();
-	hasLock.set(ONE);
+        start_gdk_drawing();
+        hasLock.set(ONE);
       }
     else
       hasLock.set(Integer.valueOf(i.intValue() + 1));
@@ -121,8 +121,8 @@
       throw new IllegalStateException();
     if (i == ONE)
       {
-	hasLock.set(null);
-	end_gdk_drawing();
+        hasLock.set(null);
+        end_gdk_drawing();
       }
     else
       hasLock.set(Integer.valueOf(i.intValue() - 1));
@@ -170,11 +170,11 @@
   private static native Pointer nativeGrab(GtkComponentPeer component);
 
   private native void copyAreaNative(GtkComponentPeer component, int x, int y, 
-				     int width, int height, int dx, int dy);
+                                     int width, int height, int dx, int dy);
 
   private native void drawVolatile(GtkComponentPeer component,
-				   long vimg, int x, int y, 
-				   int width, int height, int cx, int cy,
+                                   long vimg, int x, int y, 
+                                   int width, int height, int cx, int cy,
                                    int cw, int ch);
 
   /**
@@ -227,11 +227,11 @@
     lock();
     try
       {
-	super.draw(s);
+        super.draw(s);
       }
     finally
       {
-	unlock();
+        unlock();
       }
   }
 
@@ -240,11 +240,11 @@
     lock();
     try
       {
-	super.fill(s);
+        super.fill(s);
       }
     finally
       {
-	unlock();
+        unlock();
       }
   }
 
@@ -253,26 +253,26 @@
     lock();
     try
       {
-	super.drawRenderedImage(image, xform);
+        super.drawRenderedImage(image, xform);
       }
     finally
       {
-	unlock();
+        unlock();
       }
   }
 
   protected boolean drawImage(Image img, AffineTransform xform,
-			      Color bgcolor, ImageObserver obs)
+                              Color bgcolor, ImageObserver obs)
   {
     boolean rv;
     lock();
     try
       {
-	rv = super.drawImage(img, xform, bgcolor, obs);
+        rv = super.drawImage(img, xform, bgcolor, obs);
       }
     finally
       {
-	unlock();
+        unlock();
       }
     return rv;
   }
@@ -282,11 +282,11 @@
     lock();
     try
       {
-	super.drawGlyphVector(gv, x, y);
+        super.drawGlyphVector(gv, x, y);
       }
     finally
       {
-	unlock();
+        unlock();
       }
   }
   
@@ -316,8 +316,8 @@
                          (int) r.getHeight());
             return true;
           }
-	else
-	  return super.drawImage(vimg.getSnapshot(), x, y, observer);
+        else
+          return super.drawImage(vimg.getSnapshot(), x, y, observer);
       }
 
     BufferedImage bimg;
@@ -325,9 +325,15 @@
       bimg = (BufferedImage) img;
     else
       {
-	ImageProducer source = img.getSource();
-        if (source == null)
-          return false;
+        ImageProducer source;
+        try
+          {
+            source = img.getSource();
+          }
+        catch (NullPointerException e)
+          {
+            return false;
+          }
         bimg = (BufferedImage) Toolkit.getDefaultToolkit().createImage(source);
       }
     return super.drawImage(bimg, x, y, observer);
@@ -361,9 +367,9 @@
                          (int) r.getHeight());
             return true;
           }
-	else
-	  return super.drawImage(vimg.getSnapshot(), x, y,
-				 width, height, observer);
+        else
+          return super.drawImage(vimg.getSnapshot(), x, y,
+                                 width, height, observer);
       }
 
     BufferedImage bimg;
@@ -371,7 +377,7 @@
       bimg = (BufferedImage) img;
     else
       {
-	ImageProducer source = img.getSource();
+        ImageProducer source = img.getSource();
         if (source == null)
           return false;
         bimg = (BufferedImage) Toolkit.getDefaultToolkit().createImage(source);
@@ -423,11 +429,11 @@
     lock();
     try
       {
-	super.setClip(s);
+        super.setClip(s);
       }
     finally
       {
-	unlock();
+        unlock();
       }
   }
 
Index: javax/swing/plaf/basic/BasicTableUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v
retrieving revision 1.58
diff -u -r1.58 BasicTableUI.java
--- javax/swing/plaf/basic/BasicTableUI.java	8 Aug 2006 12:32:12 -0000	1.58
+++ javax/swing/plaf/basic/BasicTableUI.java	28 Sep 2006 20:35:54 -0000
@@ -443,11 +443,14 @@
   public Dimension getPreferredSize(JComponent comp) 
   {
     int prefTotalColumnWidth = 0;
-    for (int i = 0; i < table.getColumnCount(); i++)
+    TableColumnModel tcm = table.getColumnModel();
+
+    for (int i = 0; i < tcm.getColumnCount(); i++)
       {
-        TableColumn col = table.getColumnModel().getColumn(i);
+        TableColumn col = tcm.getColumn(i);
         prefTotalColumnWidth += col.getPreferredWidth();
       }
+
     return new Dimension(prefTotalColumnWidth, getHeight());
   }
 
@@ -455,7 +458,7 @@
    * Returns the table height. This helper method is used by
    * [EMAIL PROTECTED] #getMinimumSize(JComponent)}, [EMAIL PROTECTED] #getPreferredSize(JComponent)}
    * and [EMAIL PROTECTED] #getMaximumSize(JComponent)} to determine the table height.
-   *
+   * 
    * @return the table height
    */
   private int getHeight()
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.121
diff -u -r1.121 JTable.java
--- javax/swing/JTable.java	14 Aug 2006 14:28:43 -0000	1.121
+++ javax/swing/JTable.java	28 Sep 2006 20:35:54 -0000
@@ -2635,6 +2635,7 @@
     setModel(dm == null ? createDefaultDataModel() : dm);
     setAutoCreateColumnsFromModel(autoCreate);
     initializeLocalVars();
+    
     // The following four lines properly set the lead selection indices.
     // After this, the UI will handle the lead selection indices.
     // FIXME: this should probably not be necessary, if the UI is installed
@@ -2642,11 +2643,13 @@
     // own, but certain variables need to be set before the UI can be installed
     // so we must get the correct order for all the method calls in this
     // constructor.
-    selectionModel.setAnchorSelectionIndex(0);    
-    selectionModel.setLeadSelectionIndex(0);
-    columnModel.getSelectionModel().setAnchorSelectionIndex(0);
-    columnModel.getSelectionModel().setLeadSelectionIndex(0);
-    updateUI();
+    // These four lines are not needed.  A Mauve test that shows this is
+    // gnu.testlet.javax.swing.JTable.constructors(linesNotNeeded).
+    // selectionModel.setAnchorSelectionIndex(-1);
+    // selectionModel.setLeadSelectionIndex(-1);
+    // columnModel.getSelectionModel().setAnchorSelectionIndex(-1);
+    // columnModel.getSelectionModel().setLeadSelectionIndex(-1);
+    updateUI(); 
   }
   
   /**
@@ -2675,10 +2678,12 @@
     setRowHeight(16);
     this.rowMargin = 1;
     this.rowSelectionAllowed = true;
+    
     // this.accessibleContext = new AccessibleJTable();
     this.cellEditor = null;
+    
     // COMPAT: Both Sun and IBM have drag enabled
-    this.dragEnabled = true;
+    this.dragEnabled = false;
     this.preferredViewportSize = new Dimension(450,400);
     this.showHorizontalLines = true;
     this.showVerticalLines = true;
@@ -3267,7 +3272,7 @@
             cellRect.x += cMargin / 2;
             cellRect.width -= cMargin;
           }
-      }
+      } 
 
     return cellRect;
   }
@@ -3446,7 +3451,9 @@
    */
   public TableCellRenderer getCellRenderer(int row, int column)
   {
-    TableCellRenderer renderer = columnModel.getColumn(column).getCellRenderer();
+    TableCellRenderer renderer = null;
+    if (columnModel.getColumnCount() > 0)
+      renderer = columnModel.getColumn(column).getCellRenderer();
     if (renderer == null)
       {
         int mcolumn = convertColumnIndexToModel(column);
@@ -3563,7 +3570,7 @@
 
     return renderer.getTableCellRendererComponent(this,
                                                   dataModel.getValueAt(row, 
-						                       convertColumnIndexToModel(column)),
+                                                                       convertColumnIndexToModel(column)),
                                                   isSel,
                                                   hasFocus,
                                                   row, column);
@@ -4441,7 +4448,7 @@
   {
     TableColumn resizingColumn = null;
     
-    int ncols = getColumnCount();
+    int ncols = columnModel.getColumnCount();
     if (ncols < 1)
       return;
 
@@ -4450,7 +4457,7 @@
 
     if (tableHeader != null)
       resizingColumn = tableHeader.getResizingColumn();
-
+     
     for (int i = 0; i < ncols; ++i)
       {
         TableColumn col = columnModel.getColumn(i);
@@ -4459,7 +4466,7 @@
         if (resizingColumn == col)
           rCol = i;
       }
-
+ 
     int spill = getWidth() - prefSum;
 
     if (resizingColumn != null)
@@ -4525,9 +4532,11 @@
       }
     else
       {
-        TableColumn [] cols = new TableColumn[ncols];
+        TableColumn[] cols = new TableColumn[ncols];
+
         for (int i = 0; i < ncols; ++i)
           cols[i] = columnModel.getColumn(i);
+
         distributeSpill(cols, spill);
       }
     
@@ -4740,7 +4749,7 @@
     if ((index0 < 0 || index0 > (getRowCount()-1)
          || index1 < 0 || index1 > (getRowCount()-1)))
       throw new IllegalArgumentException("Row index out of range.");
-      	
+        
     getSelectionModel().addSelectionInterval(index0, index1);
   }
   

Reply via email to