[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: various JTable fixes

Kaffe CVS cvs-commits at kaffe.org
Sat Jan 8 13:30:40 PST 2005


PatchSet 5818 
Date: 2005/01/08 21:26:21
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: various JTable fixes

Members: 
	ChangeLog:1.3362->1.3363 
	libraries/javalib/javax/swing/JTable.java:1.14->1.15 
	libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java:1.4->1.5 
	libraries/javalib/javax/swing/table/DefaultTableColumnModel.java:1.8->1.9 
	libraries/javalib/javax/swing/table/DefaultTableModel.java:1.4->1.5 
	libraries/javalib/javax/swing/table/TableModel.java:1.3->1.4 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3362 kaffe/ChangeLog:1.3363
--- kaffe/ChangeLog:1.3362	Sat Jan  8 19:25:10 2005
+++ kaffe/ChangeLog	Sat Jan  8 21:26:21 2005
@@ -1,5 +1,71 @@
 2005-01-08  Dalibor Topic  <robilad at kaffe.org>
 
+	Resynced with GNU Classpath.
+	
+	2005-01-07  Olga Rodimina  <rodimina at redhat.com>
+
+	* javax/swing/JTable.java
+	(columnAtPoint): New Method. Implemented.
+	(rowAtPoint): Likewise.
+	(countSelections): Fixed few small count errors.
+	(getSelections): Likewise.
+	(setSelectionMode): Set selection mode for column
+	selection model in addition to row selection model.
+	* javax/swing/plaf/basic/BasicTableUI.java:
+	(getRowForPoint): Removed. Replaced by
+	JTable.rowAtPoint().
+	(getColForPoint): Removed. Replaced by
+	JTable.columnAtPoint().
+	(updateSelection): Updated to call JTable.columnAtPoint
+	and JTable.rowAtPoint.
+	* javax/swing/table/DefaultTableColumnModel.java:
+	(getSelectedColumns): Implemented.
+	(getSelectedColumnCount): Implemented.
+
+	2005-01-07  David Gilbert  <david.gilbert at object-refinery.com>
+
+	* javax/swing/table/DefaultTableModel.java
+	(DefaultTableModel()): Added Javadocs.
+	(DefaultTableModel(int, int)): Fixed implementation.
+	(DefaultTableModel(Vector, int)): Throw IllegalArgumentException
+	for negative rowCount.
+	(DefaultTableModel(Object[], int)): Added Javadocs.
+	(DefaultTableModel(Vector, Vector)): Likewise.
+	(DefaultTableModel(Object[][], Object[])): Likewise.
+	(getDataVector): Likewise.
+	(setDataVector(Vector, Vector)): Likewise.
+	(setDataVector(Object[][], Object[])): Likewise.
+	(newDataAvailable): Likewise.
+	(newRowsAdded): Likewise.
+	(rowsRemoved): Likewise.
+	(setColumnIdentifiers(Vector)): Allow for null argument.
+	(setColumnIdentifiers(Object[])): Added Javadocs.
+	(setNumRows): Likewise.
+	(setRowCount): Adds new rows if necessary, and sends more specific
+	TableModelEvent.
+	(setColumnCount): Allow for null columnIdentifiers.
+	(addColumn(Object)): Added Javadocs.
+	(addColumn(Object, Vector)): Handle null columnData.
+	(addColumn(Object, Object[])): Handle columnData with more or less
+	entries than rows in the table.
+	(addRow(Vector)): Fire appropriate event.
+	(addRow(Object[])): Added Javadocs.
+	(insertRow(int, Vector)): Fire appropriate event.
+	(insertRow(int, Object[])): Added Javadocs.
+	(moveRow): Reimplemented.
+	(removeRow(int)): Fire appropriate event.
+	(getColumnCount): Allow for null columnIdentifiers.
+	(getColumnName): Now returns empty string when column index is too
+	large.
+	(isCellEditable): Added Javadocs.
+	(getValueAt): Likewise.
+	(setValueAt): Fire more specific event.
+	(convertToVector): Added Javadocs.
+	* javax/swing/table/TableModel.java
+	Added Javadocs.
+	
+2005-01-08  Dalibor Topic  <robilad at kaffe.org>
+
 	* test/jni/Makefile.am (jniReflect_LDADD, jniExecClass_LDADD): 
 	Added missing libraries.
 
Index: kaffe/libraries/javalib/javax/swing/JTable.java
diff -u kaffe/libraries/javalib/javax/swing/JTable.java:1.14 kaffe/libraries/javalib/javax/swing/JTable.java:1.15
--- kaffe/libraries/javalib/javax/swing/JTable.java:1.14	Thu Jan  6 17:31:26 2005
+++ kaffe/libraries/javalib/javax/swing/JTable.java	Sat Jan  8 21:26:25 2005
@@ -42,6 +42,7 @@
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Rectangle;
+import java.awt.Point;
 import java.util.Hashtable;
 import java.util.Vector;
 
@@ -571,6 +572,58 @@
     repaint();
   }
 
+ /**
+   * Returns index of the column that contains specified point 
+   * or -1 if this table doesn't contain this point.
+   *
+   * @param point point to identify the column
+   * @return index of the column that contains specified point or 
+   * -1 if this table doesn't contain this point.
+   */
+  public int columnAtPoint(Point point)
+  {
+    int x0 = getLocation().x;
+    int ncols = getColumnCount();
+    Dimension gap = getIntercellSpacing();
+    TableColumnModel cols = getColumnModel();
+    int x = point.x;
+    
+    for (int i = 0; i < ncols; ++i)
+      {
+        int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width);
+        if (0 <= x && x < width)
+          return i;
+        x -= width;  
+      }
+    
+    return -1;
+  }
+
+  /**
+   * Returns index of the row that contains specified point or 
+   * -1 if this table doesn't contain this point.
+   *
+   * @param point point to identify the row
+   * @return index of the row that contains specified point or 
+   * -1 if this table doesn't contain this point.
+   */
+  public int rowAtPoint(Point point)
+  {
+    int y0 = getLocation().y;
+    int nrows = getRowCount();
+    Dimension gap = getIntercellSpacing();
+    int height = getRowHeight() + (gap == null ? 0 : gap.height);
+    int y = point.y;
+    
+    for (int i = 0; i < nrows; ++i)
+      {
+        if (0 <= y && y < height)
+          return i;
+        y -= height;
+      }
+      
+    return -1;
+  }
 
   /** 
    * Calculate the visible rectangle for a particular row and column. The
@@ -921,11 +974,11 @@
             break;
             
           case ListSelectionModel.SINGLE_INTERVAL_SELECTION:
-            sum = hi - lo;
+            sum = hi - lo + 1;
             break;
             
           case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
-            for (int i = lo; i < hi; ++i)
+            for (int i = lo; i <= hi; ++i)
               if (lsm.isSelectedIndex(i))        
                 ++sum;
             break;
@@ -952,12 +1005,12 @@
             break;      
       
           case ListSelectionModel.SINGLE_INTERVAL_SELECTION:            
-            for (int i = lo; i < hi; ++i)
+            for (int i = lo; i <= hi; ++i)
               ret[j++] = i;
             break;
             
           case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
-            for (int i = lo; i < hi; ++i)
+            for (int i = lo; i <= hi; ++i)
               if (lsm.isSelectedIndex(i))        
                 ret[j++] = i;
             break;
@@ -1328,13 +1381,16 @@
 
   /**
    * Set the value of the {@link #selectionMode} property by
-   * delegation to the {@link #selectionModel} field.
+   * delegation to the {@link #selectionModel} field. The same selection
+   * mode is set for row and column selection models.
    *
    * @param s The new value of the property
    */ 
   public void setSelectionMode(int s)
-  {
-    selectionModel.setSelectionMode(s);
+  { 
+    selectionModel.setSelectionMode(s);    
+    columnModel.getSelectionModel().setSelectionMode(s);
+    
     repaint();
   }
 
Index: kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java
diff -u kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java:1.4 kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java:1.5
--- kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java:1.4	Thu Dec 16 19:13:19 2004
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTableUI.java	Sat Jan  8 21:26:25 2005
@@ -104,45 +104,12 @@
   {
     Point begin, curr;
 
-    private int getRowForPoint(Point p)
-    {      
-      int y0 = table.getLocation().y;
-      int nrows = table.getRowCount();
-      Dimension gap = table.getIntercellSpacing();
-      int height = table.getRowHeight() + (gap == null ? 0 : gap.height);
-      int y = p.y;
-      for (int i = 0; i < nrows; ++i)
-        {
-          if (0 <= y && y < height)
-            return i;
-          y -= height;
-        }
-      return -1;
-    }
-
-    private int getColForPoint(Point p)
-    {
-      int x0 = table.getLocation().x;
-      int ncols = table.getColumnCount();
-      Dimension gap = table.getIntercellSpacing();
-      TableColumnModel cols = table.getColumnModel();      
-      int x = p.x;
-      for (int i = 0; i < ncols; ++i)
-        {
-          int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width);
-          if (0 <= x && x < width)
-            return i;
-          x -= width;
-        }
-      return -1;
-    }
-
     private void updateSelection()
     {
       if (table.getRowSelectionAllowed())
         {
-          int lo_row = getRowForPoint(begin);
-          int hi_row  = getRowForPoint(curr);
+          int lo_row = table.rowAtPoint(begin);
+          int hi_row  = table.rowAtPoint(curr);
           ListSelectionModel rowModel = table.getSelectionModel();
           if (lo_row != -1 && hi_row != -1)
             rowModel.setSelectionInterval(lo_row, hi_row);
@@ -150,8 +117,8 @@
 
       if (table.getColumnSelectionAllowed())
         {
-          int lo_col = getColForPoint(begin);
-          int hi_col = getColForPoint(curr);
+          int lo_col = table.columnAtPoint(begin);
+          int hi_col = table.columnAtPoint(curr);
           ListSelectionModel colModel = table.getColumnModel().getSelectionModel();
           if (lo_col != -1 && hi_col != -1)
             colModel.setSelectionInterval(lo_col, hi_col);
Index: kaffe/libraries/javalib/javax/swing/table/DefaultTableColumnModel.java
diff -u kaffe/libraries/javalib/javax/swing/table/DefaultTableColumnModel.java:1.8 kaffe/libraries/javalib/javax/swing/table/DefaultTableColumnModel.java:1.9
--- kaffe/libraries/javalib/javax/swing/table/DefaultTableColumnModel.java:1.8	Thu Jan  6 00:53:06 2005
+++ kaffe/libraries/javalib/javax/swing/table/DefaultTableColumnModel.java	Sat Jan  8 21:26:25 2005
@@ -298,7 +298,40 @@
    */
   public int[] getSelectedColumns()
   {
-    return null; // TODO
+    // FIXME: Implementation of this method was taken from private method 
+    // JTable.getSelections(), which is used in various places in JTable
+    // including selected row calculations and cannot be simply removed.
+    // This design should be improved to illuminate duplication of code.
+    
+    ListSelectionModel lsm = this.selectionModel;    
+    int sz = getSelectedColumnCount();
+    int [] ret = new int[sz];
+
+    int lo = lsm.getMinSelectionIndex();
+    int hi = lsm.getMaxSelectionIndex();
+    int j = 0;
+    java.util.ArrayList ls = new java.util.ArrayList();
+    if (lo != -1 && hi != -1)
+      {
+        switch (lsm.getSelectionMode())
+          {
+          case ListSelectionModel.SINGLE_SELECTION:
+            ret[0] = lo;
+            break;      
+      
+          case ListSelectionModel.SINGLE_INTERVAL_SELECTION:            
+            for (int i = lo; i <= hi; ++i)
+              ret[j++] = i;
+            break;
+            
+          case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
+            for (int i = lo; i <= hi; ++i)
+              if (lsm.isSelectedIndex(i))        
+                ret[j++] = i;
+            break;
+          }
+      }
+    return ret;
   }
 
   /**
@@ -307,7 +340,37 @@
    */
   public int getSelectedColumnCount()
   {
-    return 0; // TODO
+    // FIXME: Implementation of this method was taken from private method 
+    // JTable.countSelections(), which is used in various places in JTable
+    // including selected row calculations and cannot be simply removed.
+    // This design should be improved to illuminate duplication of code.
+   
+    ListSelectionModel lsm = this.selectionModel;
+    int lo = lsm.getMinSelectionIndex();
+    int hi = lsm.getMaxSelectionIndex();
+    int sum = 0;
+    
+    if (lo != -1 && hi != -1)
+      {
+        switch (lsm.getSelectionMode())
+          {
+          case ListSelectionModel.SINGLE_SELECTION:
+            sum = 1;
+            break;
+            
+          case ListSelectionModel.SINGLE_INTERVAL_SELECTION:
+            sum = hi - lo + 1;
+            break;
+            
+          case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
+            for (int i = lo; i <= hi; ++i)
+              if (lsm.isSelectedIndex(i))        
+                ++sum;
+            break;
+          }
+      }
+     
+     return sum;
   }
 
   /**
Index: kaffe/libraries/javalib/javax/swing/table/DefaultTableModel.java
diff -u kaffe/libraries/javalib/javax/swing/table/DefaultTableModel.java:1.4 kaffe/libraries/javalib/javax/swing/table/DefaultTableModel.java:1.5
--- kaffe/libraries/javalib/javax/swing/table/DefaultTableModel.java:1.4	Sun Oct 24 13:39:21 2004
+++ kaffe/libraries/javalib/javax/swing/table/DefaultTableModel.java	Sat Jan  8 21:26:26 2005
@@ -1,5 +1,5 @@
 /* DefaultTableModel.java --
-   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005,  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -44,15 +44,19 @@
 import javax.swing.event.TableModelEvent;
 
 /**
- * DefaultTableModel
+ * A two dimensional data structure used to store <code>Object</code> 
+ * instances, usually for display in a <code>JTable</code> component.
+ * 
  * @author	Andrew Selkirk
  */
 public class DefaultTableModel extends AbstractTableModel
   implements Serializable
 {
   static final long serialVersionUID = 6680042567037222321L;
+
   /**
-   * dataVector
+   * Storage for the rows in the table (each row is itself 
+   * a <code>Vector</code>).
    */
   protected Vector dataVector;
 
@@ -62,7 +66,7 @@
   protected Vector columnIdentifiers;
 
   /**
-   * Constructor DefaultTableModel
+   * Creates an empty table with zero rows and zero columns.
    */
   public DefaultTableModel() 
   {
@@ -70,9 +74,11 @@
   }
   
   /**
-   * Constructor DefaultTableModel
-   * @param value0 TODO
-   * @param value1 TODO
+   * Creates a new table with the specified number of rows and columns.
+   * All cells in the table are initially empty (set to <code>null</code>).
+   * 
+   * @param numRows  the number of rows.
+   * @param numColumns  the number of columns.
    */
   public DefaultTableModel(int numRows, int numColumns) 
   {
@@ -81,20 +87,28 @@
     for (int i = 0; i < numColumns; i++) 
       {
         defaultNames.add(super.getColumnName(i));
+      }          
+    for (int r = 0; r < numRows; r++) 
+      {
         Vector tmp = new Vector(numColumns);
         tmp.setSize(numColumns);
         data.add(tmp);
-      }          
-    setDataVector(defaultNames, data);
+      }
+    setDataVector(data, defaultNames);
   }
   
   /**
-   * Constructor DefaultTableModel
-   * @param value0 TODO
-   * @param value1 TODO
+   * Creates a new table with the specified column names and number of
+   * rows.  The number of columns is determined by the number of column
+   * names supplied.
+   *   
+   * @param columnNames the column names.
+   * @param numRows the number of rows.
    */
   public DefaultTableModel(Vector columnNames, int numRows) 
   {
+    if (numRows < 0)
+      throw new IllegalArgumentException("numRows < 0");
     Vector data = new Vector();
     int numColumns = 0;
 
@@ -111,9 +125,10 @@
   }
 
   /**
-   * Constructor DefaultTableModel
-   * @param value0 TODO
-   * @param value1 TODO
+   * Creates a new table with the specified column names and row count.
+   * 
+   * @param columnNames the column names.
+   * @param numRows the number of rows.
    */
   public DefaultTableModel(Object[] columnNames, int numRows) 
   {
@@ -121,9 +136,10 @@
   }
   
   /**
-   * Constructor DefaultTableModel
-   * @param value0 TODO
-   * @param value1 TODO
+   * Creates a new table with the specified data values and column names.
+   * 
+   * @param data the data values.
+   * @param columnNames the column names.
    */
   public DefaultTableModel(Vector data, Vector columnNames) 
   {
@@ -131,9 +147,10 @@
   }
 
   /**
-   * Constructor DefaultTableModel
-   * @param value0 TODO
-   * @param value1 TODO
+   * Creates a new table with the specified data values and column names.
+   * 
+   * @param data the data values.
+   * @param columnNames the column names.
    */
   public DefaultTableModel(Object[][] data, Object[] columnNames) 
   {
@@ -141,8 +158,9 @@
   }
 
   /**
-   * getDataVector
-   * @returns Vector
+   * Returns the vector containing the row data for the table.
+   * 
+   * @returns The data vector.
    */
   public Vector getDataVector() 
   {
@@ -150,9 +168,16 @@
   }
 
   /**
-   * setDataVector
-   * @param value0 TODO
-   * @param value1 TODO
+   * Sets the data and column identifiers for the table.  The data vector
+   * contains a <code>Vector</code> for each row in the table - if the
+   * number of objects in each row does not match the number of column
+   * names specified, the row data is truncated or expanded (by adding
+   * <code>null</code> values) as required.
+   * 
+   * @param data the data for the table (a vector of row vectors).
+   * @param columnNames the column names.
+   * 
+   * @throws NullPointerException if either argument is <code>null</code>.
    */
   public void setDataVector(Vector data, Vector columnNames) 
   {
@@ -164,9 +189,12 @@
   }
 
   /**
-   * setDataVector
-   * @param value0 TODO
-   * @param value1 TODO
+   * Sets the data and column identifiers for the table.
+   * 
+   * @param data the data for the table.
+   * @param columnNames the column names.
+   * 
+   * @throws NullPointerException if either argument is <code>null</code>.
    */
   public void setDataVector(Object[][] data, Object[] columnNames) 
   {
@@ -175,8 +203,11 @@
   }
   
   /**
-   * newDataAvailable
-   * @param value0 TODO
+   * Sends the specified <code>event</code> to all registered listeners.
+   * This method is equivalent to 
+   * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}.
+   * 
+   * @param event the event.
    */
   public void newDataAvailable(TableModelEvent event) 
   {
@@ -184,8 +215,11 @@
   }
 
   /**
-   * newRowsAdded
-   * @param value0 TODO
+   * Sends the specified <code>event</code> to all registered listeners.
+   * This method is equivalent to 
+   * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}.
+   * 
+   * @param event the event.
    */
   public void newRowsAdded(TableModelEvent event) 
   {
@@ -193,8 +227,11 @@
   }
 
   /**
-   * rowsRemoved
-   * @param value0 TODO
+   * Sends the specified <code>event</code> to all registered listeners.
+   * This method is equivalent to 
+   * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}.
+   * 
+   * @param event the event.
    */
   public void rowsRemoved(TableModelEvent event) 
   {
@@ -202,18 +239,26 @@
   }
 
   /**
-   * setColumnIdentifiers
-   * @param value0 TODO
+   * Sets the column identifiers, updates the data rows (truncating
+   * or padding each row with <code>null</code> values) to match the 
+   * number of columns, and sends a {@link TableModelEvent} to all
+   * registered listeners.
+   * 
+   * @param columnIdentifiers the column identifiers.
    */
   public void setColumnIdentifiers(Vector columnIdentifiers) 
   {
     this.columnIdentifiers = columnIdentifiers;
-    setColumnCount(columnIdentifiers.size());
+    setColumnCount((columnIdentifiers == null ? 0 : columnIdentifiers.size()));
   }
   
   /**
-   * setColumnIdentifiers
-   * @param value0 TODO
+   * Sets the column identifiers, updates the data rows (truncating
+   * or padding each row with <code>null</code> values) to match the 
+   * number of columns, and sends a {@link TableModelEvent} to all
+   * registered listeners.
+   * 
+   * @param columnIdentifiers the column identifiers.
    */
   public void setColumnIdentifiers(Object[] columnIdentifiers) 
   {
@@ -221,8 +266,9 @@
   }
 
   /**
-   * setNumRows
-   * @param value0 TODO
+   * This method is obsolete, use {@link #setRowCount(int)} instead.
+   * 
+   * @param numRows the number of rows.
    */
   public void setNumRows(int numRows) 
   {
@@ -230,18 +276,40 @@
   }
 
   /**
-   * setRowCount
-   * @param value0 TODO
+   * Sets the number of rows in the table.  If <code>rowCount</code> is less
+   * than the current number of rows in the table, rows are discarded.
+   * If <code>rowCount</code> is greater than the current number of rows in
+   * the table, new (empty) rows are added.
+   * 
+   * @param the row count.
    */
   public void setRowCount(int rowCount) 
   {
-    dataVector.setSize(rowCount);
-    fireTableDataChanged();
+    int existingRowCount = dataVector.size();
+    if (rowCount < existingRowCount) 
+    {
+      dataVector.setSize(rowCount);
+      fireTableRowsDeleted(rowCount,existingRowCount-1);      
+    }
+    else 
+    {
+      int rowsToAdd = rowCount - existingRowCount;
+      for (int i = 0; i < rowsToAdd; i++) 
+        {
+          Vector tmp = new Vector();
+          tmp.setSize(columnIdentifiers.size());
+          dataVector.add(tmp);
+        } 
+      fireTableRowsInserted(existingRowCount,rowCount-1);
+    }
   }
 
   /**
-   * setColumnCount
-   * @param value0 TODO
+   * Sets the number of columns in the table.  Existing rows are truncated
+   * or padded with <code>null</code> values to match the new column count.
+   * A {@link TableModelEvent} is sent to all registered listeners.
+   * 
+   * @param columnCount the column count.
    */
   public void setColumnCount(int columnCount) 
   {
@@ -249,13 +317,16 @@
       {
         ((Vector) dataVector.get(i)).setSize(columnCount);
       }
-    columnIdentifiers.setSize(columnCount);
+    if (columnIdentifiers != null)  
+      columnIdentifiers.setSize(columnCount);
     fireTableDataChanged();
   }
 
   /**
-   * addColumn
-   * @param value0 TODO
+   * Adds a column with the specified name to the table.  All cell values
+   * for the column are initially set to <code>null</code>.
+   * 
+   * @param columnName the column name (<code>null</code> permitted).
    */
   public void addColumn(Object columnName) 
   {
@@ -263,21 +334,52 @@
   }
 
   /**
-   * addColumn
-   * @param value0 TODO
-   * @param value1 TODO
+   * Adds a column with the specified name and data values to the table.  
+   * 
+   * @param columnName the column name (<code>null</code> permitted).
+   * @param columnData the column data.
    */
   public void addColumn(Object columnName, Vector columnData) 
   {
-    addColumn(columnName, columnData == null ? null : columnData.toArray());
+    Object[] dataArray = null;
+    if (columnData != null) 
+    {
+      int rowCount = dataVector.size();
+      if (columnData.size() < rowCount)
+        columnData.setSize(rowCount);
+      dataArray = columnData.toArray();
+    }
+    addColumn(columnName, dataArray);
   }
 
   /**
-   * addColumn
-   * @param value0 TODO
-   * @param value1 TODO
+   * Adds a column with the specified name and data values to the table.
+   * 
+   * @param columnName the column name (<code>null</code> permitted).
+   * @param columnData the column data.
    */
   public void addColumn(Object columnName, Object[] columnData) {
+    if (columnData != null)
+    {
+      // check columnData array for cases where the number of items
+      // doesn't match the number of rows in the existing table
+      if (columnData.length > dataVector.size()) 
+      {
+        int rowsToAdd = columnData.length - dataVector.size();
+        for (int i = 0; i < rowsToAdd; i++) 
+        {
+          Vector tmp = new Vector();
+          tmp.setSize(columnIdentifiers.size());
+          dataVector.add(tmp);
+        }
+      }
+      else if (columnData.length < dataVector.size())
+      {
+        Object[] tmp = new Object[dataVector.size()];
+        System.arraycopy(columnData, 0, tmp, 0, columnData.length);
+        columnData = tmp;
+      }
+    }
     for (int i = 0; i < dataVector.size(); ++i)
       {
         ((Vector) dataVector.get(i)).add(columnData == null ? null : columnData[i]);
@@ -287,62 +389,79 @@
   }
 
   /**
-   * addRow
-   * @param value0 TODO
+   * Adds a new row containing the specified data to the table and sends a
+   * {@link TableModelEvent} to all registered listeners.
+   * 
+   * @param rowData the row data (<code>null</code> permitted).
    */
   public void addRow(Vector rowData) {
     dataVector.add(rowData);
-    fireTableDataChanged();
+    newRowsAdded(new TableModelEvent(
+      this, dataVector.size(), dataVector.size(), -1, TableModelEvent.INSERT)
+    );
   }
 
   /**
-   * addRow
-   * @param value0 TODO
+   * Adds a new row containing the specified data to the table and sends a
+   * {@link TableModelEvent} to all registered listeners.
+   * 
+   * @param rowData the row data (<code>null</code> permitted).
    */
   public void addRow(Object[] rowData) {
     addRow(convertToVector(rowData));
   }
 
   /**
-   * insertRow
-   * @param value0 TODO
-   * @param value1 TODO
+   * Inserts a new row into the table.
+   * 
+   * @param row the row index.
+   * @param rowData the row data.
    */
   public void insertRow(int row, Vector rowData) {
     dataVector.add(row, rowData);
-    fireTableDataChanged();
+    fireTableRowsInserted(row,row);
   }
 
   /**
-   * insertRow
-   * @param value0 TODO
-   * @param value1 TODO
+   * Inserts a new row into the table.
+   * 
+   * @param row the row index.
+   * @param rowData the row data.
    */
   public void insertRow(int row, Object[] rowData) {
     insertRow(row, convertToVector(rowData));
   }
 
   /**
-   * moveRow
-   * @param value0 TODO
-   * @param value1 TODO
-   * @param value2 TODO
+   * Moves the rows from <code>startIndex</code> to <code>endIndex</code>
+   * (inclusive) to the specified row.
+   * 
+   * @param startIndex the start row.
+   * @param endIndex the end row.
+   * @param toIndex the row to move to.
    */
   public void moveRow(int startIndex, int endIndex, int toIndex) {
-    for (int index = 0; index < (endIndex - startIndex); index++) {
-      Vector vector = (Vector) dataVector.remove(startIndex);
-      dataVector.add(toIndex, vector);
+    Vector removed = new Vector();
+    for (int i = endIndex; i >= startIndex; i--)
+    {
+      removed.add(this.dataVector.remove(i));
+    }
+    for (int i = 0; i <= endIndex - startIndex; i++) 
+    {
+      dataVector.insertElementAt(removed.get(i), toIndex);  
     }
     fireTableDataChanged();
   }
 
   /**
-   * removeRow
-   * @param value0 TODO
+   * Removes a row from the table and sends a {@link TableModelEvent} to
+   * all registered listeners.
+   * 
+   * @param row the row index.
    */
   public void removeRow(int row) {
     dataVector.remove(row);
-    fireTableDataChanged();
+    fireTableRowsDeleted(row,row);
   }
 
   /**
@@ -354,63 +473,86 @@
   }
 
   /**
-   * getColumnCount
-   * @returns int
+   * Returns the number of columns in the model.
+   * 
+   * @return The column count.
    */
   public int getColumnCount() {
-    return columnIdentifiers.size();
+    return (columnIdentifiers == null ? 0 : columnIdentifiers.size());
   }
 
   /**
-   * getColumnName
-   * @param value0 TODO
-   * @returns String
+   * Returns the name of the specified column.
+   * 
+   * @param column the column index.
+   * 
+   * @returns The column name.
    */
   public String getColumnName(int column) {
-    // Check for Column
-    if (columnIdentifiers == null || column >= getColumnCount()) {
-      return super.getColumnName(column);
+    String result = "";
+    if (columnIdentifiers == null) 
+      result = super.getColumnName(column);
+    else 
+    {
+      if (column < getColumnCount())
+      {  
+        Object id = columnIdentifiers.get(column);
+        if (id != null) 
+          result = id.toString();
+        else
+          result = super.getColumnName(column);
+      }
     }
-          
-    // Return Column name
-    return (String) columnIdentifiers.get(column);          
+    return result;
   }
 
   /**
-   * isCellEditable
-   * @param value0 TODO
-   * @param value1 TODO
-   * @returns boolean
+   * Returns <code>true</code> if the specified cell can be modified, and
+   * <code>false</code> otherwise.  For this implementation, the method
+   * always returns <code>true</code>.
+   * 
+   * @param row the row index.
+   * @param column the column index.
+   * 
+   * @returns <code>true</code> in all cases.
    */
   public boolean isCellEditable(int row, int column) {
     return true;
   }
 
   /**
-   * getValueAt
-   * @param value0 TODO
-   * @param value1 TODO
-   * @returns Object
+   * Returns the value at the specified cell in the table.
+   * 
+   * @param row the row index.
+   * @param column the column index.
+   * 
+   * @returns The value (<code>Object</code>, possibly <code>null</code>) at 
+   *          the specified cell in the table.
    */
   public Object getValueAt(int row, int column) {
     return ((Vector) dataVector.get(row)).get(column);
   }
 
   /**
-   * setValueAt
-   * @param value0 TODO
-   * @param value1 TODO
-   * @param value2 TODO
+   * Sets the value for the specified cell in the table and sends a 
+   * {@link TableModelEvent} to all registered listeners.
+   * 
+   * @param value the value (<code>Object</code>, <code>null</code> permitted).
+   * @param row the row index.
+   * @param column the column index.
    */
   public void setValueAt(Object value, int row, int column) {
     ((Vector) dataVector.get(row)).set(column, value);
-    fireTableDataChanged();
+    fireTableCellUpdated(row,column);
   }
 
   /**
-   * convertToVector
-   * @param value0 TODO
-   * @returns Vector
+   * Converts the data array to a <code>Vector</code>.
+   * 
+   * @param data the data array (<code>null</code> permitted).
+   * 
+   * @returns A vector (or <code>null</code> if the data array 
+   *          is <code>null</code>).
    */
   protected static Vector convertToVector(Object[] data) {
     if (data == null)
@@ -422,9 +564,12 @@
   }
   
   /**
-   * convertToVector
-   * @param value0 TODO
-   * @returns Vector
+   * Converts the data array to a <code>Vector</code> of rows.
+   * 
+   * @param the data array (<code>null</code> permitted).
+   * 
+   * @returns A vector (or <code>null</code> if the data array 
+   *          is <code>null</code>.
    */
   protected static Vector convertToVector(Object[][] data) {
     if (data == null)
Index: kaffe/libraries/javalib/javax/swing/table/TableModel.java
diff -u kaffe/libraries/javalib/javax/swing/table/TableModel.java:1.3 kaffe/libraries/javalib/javax/swing/table/TableModel.java:1.4
--- kaffe/libraries/javalib/javax/swing/table/TableModel.java:1.3	Sun Sep 12 15:11:11 2004
+++ kaffe/libraries/javalib/javax/swing/table/TableModel.java	Sat Jan  8 21:26:26 2005
@@ -1,5 +1,5 @@
 /* TableModel.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2005, Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -39,72 +39,96 @@
 

*** Patch too long, truncated ***




More information about the kaffe mailing list