1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.table;
  27 
  28 import java.io.Serializable;
  29 import java.util.Vector;
  30 import java.util.Enumeration;
  31 import javax.swing.event.TableModelEvent;
  32 
  33 
  34 /**
  35  * This is an implementation of <code>TableModel</code> that
  36  * uses a <code>Vector</code> of <code>Vectors</code> to store the
  37  * cell value objects.
  38  * <p>
  39  * <strong>Warning:</strong> <code>DefaultTableModel</code> returns a
  40  * column class of <code>Object</code>.  When
  41  * <code>DefaultTableModel</code> is used with a
  42  * <code>TableRowSorter</code> this will result in extensive use of
  43  * <code>toString</code>, which for non-<code>String</code> data types
  44  * is expensive.  If you use <code>DefaultTableModel</code> with a
  45  * <code>TableRowSorter</code> you are strongly encouraged to override
  46  * <code>getColumnClass</code> to return the appropriate type.
  47  * <p>
  48  * <strong>Warning:</strong>
  49  * Serialized objects of this class will not be compatible with
  50  * future Swing releases. The current serialization support is
  51  * appropriate for short term storage or RMI between applications running
  52  * the same version of Swing.  As of 1.4, support for long term storage
  53  * of all JavaBeans&trade;
  54  * has been added to the <code>java.beans</code> package.
  55  * Please see {@link java.beans.XMLEncoder}.
  56  *
  57  * @author Philip Milne
  58  *
  59  * @see TableModel
  60  * @see #getDataVector
  61  */
  62 @SuppressWarnings("serial") // Same-version serialization only
  63 public class DefaultTableModel extends AbstractTableModel implements Serializable {
  64 
  65 //
  66 // Instance Variables
  67 //
  68 
  69     /**
  70      * The <code>Vector</code> of <code>Vectors</code> of
  71      * <code>Object</code> values.
  72      */
  73     protected Vector    dataVector;
  74 
  75     /** The <code>Vector</code> of column identifiers. */
  76     protected Vector    columnIdentifiers;
  77 
  78 //
  79 // Constructors
  80 //
  81 
  82     /**
  83      *  Constructs a default <code>DefaultTableModel</code>
  84      *  which is a table of zero columns and zero rows.
  85      */
  86     public DefaultTableModel() {
  87         this(0, 0);
  88     }
  89 
  90     private static Vector newVector(int size) {
  91         Vector v = new Vector(size);
  92         v.setSize(size);
  93         return v;
  94     }
  95 
  96     /**
  97      *  Constructs a <code>DefaultTableModel</code> with
  98      *  <code>rowCount</code> and <code>columnCount</code> of
  99      *  <code>null</code> object values.
 100      *
 101      * @param rowCount           the number of rows the table holds
 102      * @param columnCount        the number of columns the table holds
 103      *
 104      * @see #setValueAt
 105      */
 106     public DefaultTableModel(int rowCount, int columnCount) {
 107         this(newVector(columnCount), rowCount);
 108     }
 109 
 110     /**
 111      *  Constructs a <code>DefaultTableModel</code> with as many columns
 112      *  as there are elements in <code>columnNames</code>
 113      *  and <code>rowCount</code> of <code>null</code>
 114      *  object values.  Each column's name will be taken from
 115      *  the <code>columnNames</code> vector.
 116      *
 117      * @param columnNames       <code>vector</code> containing the names
 118      *                          of the new columns; if this is
 119      *                          <code>null</code> then the model has no columns
 120      * @param rowCount           the number of rows the table holds
 121      * @see #setDataVector
 122      * @see #setValueAt
 123      */
 124     public DefaultTableModel(Vector columnNames, int rowCount) {
 125         setDataVector(newVector(rowCount), columnNames);
 126     }
 127 
 128     /**
 129      *  Constructs a <code>DefaultTableModel</code> with as many
 130      *  columns as there are elements in <code>columnNames</code>
 131      *  and <code>rowCount</code> of <code>null</code>
 132      *  object values.  Each column's name will be taken from
 133      *  the <code>columnNames</code> array.
 134      *
 135      * @param columnNames       <code>array</code> containing the names
 136      *                          of the new columns; if this is
 137      *                          <code>null</code> then the model has no columns
 138      * @param rowCount           the number of rows the table holds
 139      * @see #setDataVector
 140      * @see #setValueAt
 141      */
 142     public DefaultTableModel(Object[] columnNames, int rowCount) {
 143         this(convertToVector(columnNames), rowCount);
 144     }
 145 
 146     /**
 147      *  Constructs a <code>DefaultTableModel</code> and initializes the table
 148      *  by passing <code>data</code> and <code>columnNames</code>
 149      *  to the <code>setDataVector</code> method.
 150      *
 151      * @param data              the data of the table, a <code>Vector</code>
 152      *                          of <code>Vector</code>s of <code>Object</code>
 153      *                          values
 154      * @param columnNames       <code>vector</code> containing the names
 155      *                          of the new columns
 156      * @see #getDataVector
 157      * @see #setDataVector
 158      */
 159     public DefaultTableModel(Vector data, Vector columnNames) {
 160         setDataVector(data, columnNames);
 161     }
 162 
 163     /**
 164      *  Constructs a <code>DefaultTableModel</code> and initializes the table
 165      *  by passing <code>data</code> and <code>columnNames</code>
 166      *  to the <code>setDataVector</code>
 167      *  method. The first index in the <code>Object[][]</code> array is
 168      *  the row index and the second is the column index.
 169      *
 170      * @param data              the data of the table
 171      * @param columnNames       the names of the columns
 172      * @see #getDataVector
 173      * @see #setDataVector
 174      */
 175     public DefaultTableModel(Object[][] data, Object[] columnNames) {
 176         setDataVector(data, columnNames);
 177     }
 178 
 179     /**
 180      *  Returns the <code>Vector</code> of <code>Vectors</code>
 181      *  that contains the table's
 182      *  data values.  The vectors contained in the outer vector are
 183      *  each a single row of values.  In other words, to get to the cell
 184      *  at row 1, column 5: <p>
 185      *
 186      *  <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code>
 187      *
 188      * @return  the vector of vectors containing the tables data values
 189      *
 190      * @see #newDataAvailable
 191      * @see #newRowsAdded
 192      * @see #setDataVector
 193      */
 194     public Vector getDataVector() {
 195         return dataVector;
 196     }
 197 
 198     private static Vector nonNullVector(Vector v) {
 199         return (v != null) ? v : new Vector();
 200     }
 201 
 202     /**
 203      *  Replaces the current <code>dataVector</code> instance variable
 204      *  with the new <code>Vector</code> of rows, <code>dataVector</code>.
 205      *  Each row is represented in <code>dataVector</code> as a
 206      *  <code>Vector</code> of <code>Object</code> values.
 207      *  <code>columnIdentifiers</code> are the names of the new
 208      *  columns.  The first name in <code>columnIdentifiers</code> is
 209      *  mapped to column 0 in <code>dataVector</code>. Each row in
 210      *  <code>dataVector</code> is adjusted to match the number of
 211      *  columns in <code>columnIdentifiers</code>
 212      *  either by truncating the <code>Vector</code> if it is too long,
 213      *  or adding <code>null</code> values if it is too short.
 214      *  <p>Note that passing in a <code>null</code> value for
 215      *  <code>dataVector</code> results in unspecified behavior,
 216      *  an possibly an exception.
 217      *
 218      * @param   dataVector         the new data vector
 219      * @param   columnIdentifiers     the names of the columns
 220      * @see #getDataVector
 221      */
 222     public void setDataVector(Vector dataVector, Vector columnIdentifiers) {
 223         this.dataVector = nonNullVector(dataVector);
 224         this.columnIdentifiers = nonNullVector(columnIdentifiers);
 225         justifyRows(0, getRowCount());
 226         fireTableStructureChanged();
 227     }
 228 
 229     /**
 230      *  Replaces the value in the <code>dataVector</code> instance
 231      *  variable with the values in the array <code>dataVector</code>.
 232      *  The first index in the <code>Object[][]</code>
 233      *  array is the row index and the second is the column index.
 234      *  <code>columnIdentifiers</code> are the names of the new columns.
 235      *
 236      * @param dataVector                the new data vector
 237      * @param columnIdentifiers the names of the columns
 238      * @see #setDataVector(Vector, Vector)
 239      */
 240     public void setDataVector(Object[][] dataVector, Object[] columnIdentifiers) {
 241         setDataVector(convertToVector(dataVector), convertToVector(columnIdentifiers));
 242     }
 243 
 244     /**
 245      *  Equivalent to <code>fireTableChanged</code>.
 246      *
 247      * @param event  the change event
 248      *
 249      */
 250     public void newDataAvailable(TableModelEvent event) {
 251         fireTableChanged(event);
 252     }
 253 
 254 //
 255 // Manipulating rows
 256 //
 257 
 258     private void justifyRows(int from, int to) {
 259         // Sometimes the DefaultTableModel is subclassed
 260         // instead of the AbstractTableModel by mistake.
 261         // Set the number of rows for the case when getRowCount
 262         // is overridden.
 263         dataVector.setSize(getRowCount());
 264 
 265         for (int i = from; i < to; i++) {
 266             if (dataVector.elementAt(i) == null) {
 267                 dataVector.setElementAt(new Vector(), i);
 268             }
 269             ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
 270         }
 271     }
 272 
 273     /**
 274      *  Ensures that the new rows have the correct number of columns.
 275      *  This is accomplished by  using the <code>setSize</code> method in
 276      *  <code>Vector</code> which truncates vectors
 277      *  which are too long, and appends <code>null</code>s if they
 278      *  are too short.
 279      *  This method also sends out a <code>tableChanged</code>
 280      *  notification message to all the listeners.
 281      *
 282      * @param e         this <code>TableModelEvent</code> describes
 283      *                           where the rows were added.
 284      *                           If <code>null</code> it assumes
 285      *                           all the rows were newly added
 286      * @see #getDataVector
 287      */
 288     public void newRowsAdded(TableModelEvent e) {
 289         justifyRows(e.getFirstRow(), e.getLastRow() + 1);
 290         fireTableChanged(e);
 291     }
 292 
 293     /**
 294      *  Equivalent to <code>fireTableChanged</code>.
 295      *
 296      *  @param event the change event
 297      *
 298      */
 299     public void rowsRemoved(TableModelEvent event) {
 300         fireTableChanged(event);
 301     }
 302 
 303     /**
 304      * Obsolete as of Java 2 platform v1.3.  Please use <code>setRowCount</code> instead.
 305      */
 306     /*
 307      *  Sets the number of rows in the model.  If the new size is greater
 308      *  than the current size, new rows are added to the end of the model
 309      *  If the new size is less than the current size, all
 310      *  rows at index <code>rowCount</code> and greater are discarded.
 311      *
 312      * @param   rowCount   the new number of rows
 313      * @see #setRowCount
 314      */
 315     public void setNumRows(int rowCount) {
 316         int old = getRowCount();
 317         if (old == rowCount) {
 318             return;
 319         }
 320         dataVector.setSize(rowCount);
 321         if (rowCount <= old) {
 322             fireTableRowsDeleted(rowCount, old-1);
 323         }
 324         else {
 325             justifyRows(old, rowCount);
 326             fireTableRowsInserted(old, rowCount-1);
 327         }
 328     }
 329 
 330     /**
 331      *  Sets the number of rows in the model.  If the new size is greater
 332      *  than the current size, new rows are added to the end of the model
 333      *  If the new size is less than the current size, all
 334      *  rows at index <code>rowCount</code> and greater are discarded.
 335      *
 336      *  @see #setColumnCount
 337      * @since 1.3
 338      *
 339      * @param rowCount  number of rows in the model
 340      */
 341     public void setRowCount(int rowCount) {
 342         setNumRows(rowCount);
 343     }
 344 
 345     /**
 346      *  Adds a row to the end of the model.  The new row will contain
 347      *  <code>null</code> values unless <code>rowData</code> is specified.
 348      *  Notification of the row being added will be generated.
 349      *
 350      * @param   rowData          optional data of the row being added
 351      */
 352     public void addRow(Vector rowData) {
 353         insertRow(getRowCount(), rowData);
 354     }
 355 
 356     /**
 357      *  Adds a row to the end of the model.  The new row will contain
 358      *  <code>null</code> values unless <code>rowData</code> is specified.
 359      *  Notification of the row being added will be generated.
 360      *
 361      * @param   rowData          optional data of the row being added
 362      */
 363     public void addRow(Object[] rowData) {
 364         addRow(convertToVector(rowData));
 365     }
 366 
 367     /**
 368      *  Inserts a row at <code>row</code> in the model.  The new row
 369      *  will contain <code>null</code> values unless <code>rowData</code>
 370      *  is specified.  Notification of the row being added will be generated.
 371      *
 372      * @param   row             the row index of the row to be inserted
 373      * @param   rowData         optional data of the row being added
 374      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
 375      */
 376     public void insertRow(int row, Vector rowData) {
 377         dataVector.insertElementAt(rowData, row);
 378         justifyRows(row, row+1);
 379         fireTableRowsInserted(row, row);
 380     }
 381 
 382     /**
 383      *  Inserts a row at <code>row</code> in the model.  The new row
 384      *  will contain <code>null</code> values unless <code>rowData</code>
 385      *  is specified.  Notification of the row being added will be generated.
 386      *
 387      * @param   row      the row index of the row to be inserted
 388      * @param   rowData          optional data of the row being added
 389      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
 390      */
 391     public void insertRow(int row, Object[] rowData) {
 392         insertRow(row, convertToVector(rowData));
 393     }
 394 
 395     private static int gcd(int i, int j) {
 396         return (j == 0) ? i : gcd(j, i%j);
 397     }
 398 
 399     private static void rotate(Vector v, int a, int b, int shift) {
 400         int size = b - a;
 401         int r = size - shift;
 402         int g = gcd(size, r);
 403         for(int i = 0; i < g; i++) {
 404             int to = i;
 405             Object tmp = v.elementAt(a + to);
 406             for(int from = (to + r) % size; from != i; from = (to + r) % size) {
 407                 v.setElementAt(v.elementAt(a + from), a + to);
 408                 to = from;
 409             }
 410             v.setElementAt(tmp, a + to);
 411         }
 412     }
 413 
 414     /**
 415      *  Moves one or more rows from the inclusive range <code>start</code> to
 416      *  <code>end</code> to the <code>to</code> position in the model.
 417      *  After the move, the row that was at index <code>start</code>
 418      *  will be at index <code>to</code>.
 419      *  This method will send a <code>tableChanged</code> notification
 420        message to all the listeners.
 421      *
 422      *  <pre>
 423      *  Examples of moves:
 424      *
 425      *  1. moveRow(1,3,5);
 426      *          a|B|C|D|e|f|g|h|i|j|k   - before
 427      *          a|e|f|g|h|B|C|D|i|j|k   - after
 428      *
 429      *  2. moveRow(6,7,1);
 430      *          a|b|c|d|e|f|G|H|i|j|k   - before
 431      *          a|G|H|b|c|d|e|f|i|j|k   - after
 432      *  </pre>
 433      *
 434      * @param   start       the starting row index to be moved
 435      * @param   end         the ending row index to be moved
 436      * @param   to          the destination of the rows to be moved
 437      * @exception  ArrayIndexOutOfBoundsException  if any of the elements
 438      * would be moved out of the table's range
 439      *
 440      */
 441     public void moveRow(int start, int end, int to) {
 442         int shift = to - start;
 443         int first, last;
 444         if (shift < 0) {
 445             first = to;
 446             last = end;
 447         }
 448         else {
 449             first = start;
 450             last = to + end - start;
 451         }
 452         rotate(dataVector, first, last + 1, shift);
 453 
 454         fireTableRowsUpdated(first, last);
 455     }
 456 
 457     /**
 458      *  Removes the row at <code>row</code> from the model.  Notification
 459      *  of the row being removed will be sent to all the listeners.
 460      *
 461      * @param   row      the row index of the row to be removed
 462      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
 463      */
 464     public void removeRow(int row) {
 465         dataVector.removeElementAt(row);
 466         fireTableRowsDeleted(row, row);
 467     }
 468 
 469 //
 470 // Manipulating columns
 471 //
 472 
 473     /**
 474      * Replaces the column identifiers in the model.  If the number of
 475      * <code>newIdentifier</code>s is greater than the current number
 476      * of columns, new columns are added to the end of each row in the model.
 477      * If the number of <code>newIdentifier</code>s is less than the current
 478      * number of columns, all the extra columns at the end of a row are
 479      * discarded.
 480      *
 481      * @param   columnIdentifiers  vector of column identifiers.  If
 482      *                          <code>null</code>, set the model
 483      *                          to zero columns
 484      * @see #setNumRows
 485      */
 486     public void setColumnIdentifiers(Vector columnIdentifiers) {
 487         setDataVector(dataVector, columnIdentifiers);
 488     }
 489 
 490     /**
 491      * Replaces the column identifiers in the model.  If the number of
 492      * <code>newIdentifier</code>s is greater than the current number
 493      * of columns, new columns are added to the end of each row in the model.
 494      * If the number of <code>newIdentifier</code>s is less than the current
 495      * number of columns, all the extra columns at the end of a row are
 496      * discarded.
 497      *
 498      * @param   newIdentifiers  array of column identifiers.
 499      *                          If <code>null</code>, set
 500      *                          the model to zero columns
 501      * @see #setNumRows
 502      */
 503     public void setColumnIdentifiers(Object[] newIdentifiers) {
 504         setColumnIdentifiers(convertToVector(newIdentifiers));
 505     }
 506 
 507     /**
 508      *  Sets the number of columns in the model.  If the new size is greater
 509      *  than the current size, new columns are added to the end of the model
 510      *  with <code>null</code> cell values.
 511      *  If the new size is less than the current size, all columns at index
 512      *  <code>columnCount</code> and greater are discarded.
 513      *
 514      *  @param columnCount  the new number of columns in the model
 515      *
 516      *  @see #setColumnCount
 517      * @since 1.3
 518      */
 519     public void setColumnCount(int columnCount) {
 520         columnIdentifiers.setSize(columnCount);
 521         justifyRows(0, getRowCount());
 522         fireTableStructureChanged();
 523     }
 524 
 525     /**
 526      *  Adds a column to the model.  The new column will have the
 527      *  identifier <code>columnName</code>, which may be null.  This method
 528      *  will send a
 529      *  <code>tableChanged</code> notification message to all the listeners.
 530      *  This method is a cover for <code>addColumn(Object, Vector)</code> which
 531      *  uses <code>null</code> as the data vector.
 532      *
 533      * @param   columnName the identifier of the column being added
 534      */
 535     public void addColumn(Object columnName) {
 536         addColumn(columnName, (Vector)null);
 537     }
 538 
 539     /**
 540      *  Adds a column to the model.  The new column will have the
 541      *  identifier <code>columnName</code>, which may be null.
 542      *  <code>columnData</code> is the
 543      *  optional vector of data for the column.  If it is <code>null</code>
 544      *  the column is filled with <code>null</code> values.  Otherwise,
 545      *  the new data will be added to model starting with the first
 546      *  element going to row 0, etc.  This method will send a
 547      *  <code>tableChanged</code> notification message to all the listeners.
 548      *
 549      * @param   columnName the identifier of the column being added
 550      * @param   columnData       optional data of the column being added
 551      */
 552     public void addColumn(Object columnName, Vector columnData) {
 553         columnIdentifiers.addElement(columnName);
 554         if (columnData != null) {
 555             int columnSize = columnData.size();
 556             if (columnSize > getRowCount()) {
 557                 dataVector.setSize(columnSize);
 558             }
 559             justifyRows(0, getRowCount());
 560             int newColumn = getColumnCount() - 1;
 561             for(int i = 0; i < columnSize; i++) {
 562                   Vector row = (Vector)dataVector.elementAt(i);
 563                   row.setElementAt(columnData.elementAt(i), newColumn);
 564             }
 565         }
 566         else {
 567             justifyRows(0, getRowCount());
 568         }
 569 
 570         fireTableStructureChanged();
 571     }
 572 
 573     /**
 574      *  Adds a column to the model.  The new column will have the
 575      *  identifier <code>columnName</code>.  <code>columnData</code> is the
 576      *  optional array of data for the column.  If it is <code>null</code>
 577      *  the column is filled with <code>null</code> values.  Otherwise,
 578      *  the new data will be added to model starting with the first
 579      *  element going to row 0, etc.  This method will send a
 580      *  <code>tableChanged</code> notification message to all the listeners.
 581      *
 582      * @param columnName  identifier of the newly created column
 583      * @param columnData  new data to be added to the column
 584      *
 585      * @see #addColumn(Object, Vector)
 586      */
 587     public void addColumn(Object columnName, Object[] columnData) {
 588         addColumn(columnName, convertToVector(columnData));
 589     }
 590 
 591 //
 592 // Implementing the TableModel interface
 593 //
 594 
 595     /**
 596      * Returns the number of rows in this data table.
 597      * @return the number of rows in the model
 598      */
 599     public int getRowCount() {
 600         return dataVector.size();
 601     }
 602 
 603     /**
 604      * Returns the number of columns in this data table.
 605      * @return the number of columns in the model
 606      */
 607     public int getColumnCount() {
 608         return columnIdentifiers.size();
 609     }
 610 
 611     /**
 612      * Returns the column name.
 613      *
 614      * @return a name for this column using the string value of the
 615      * appropriate member in <code>columnIdentifiers</code>.
 616      * If <code>columnIdentifiers</code> does not have an entry
 617      * for this index, returns the default
 618      * name provided by the superclass.
 619      */
 620     public String getColumnName(int column) {
 621         Object id = null;
 622         // This test is to cover the case when
 623         // getColumnCount has been subclassed by mistake ...
 624         if (column < columnIdentifiers.size() && (column >= 0)) {
 625             id = columnIdentifiers.elementAt(column);
 626         }
 627         return (id == null) ? super.getColumnName(column)
 628                             : id.toString();
 629     }
 630 
 631     /**
 632      * Returns true regardless of parameter values.
 633      *
 634      * @param   row             the row whose value is to be queried
 635      * @param   column          the column whose value is to be queried
 636      * @return                  true
 637      * @see #setValueAt
 638      */
 639     public boolean isCellEditable(int row, int column) {
 640         return true;
 641     }
 642 
 643     /**
 644      * Returns an attribute value for the cell at <code>row</code>
 645      * and <code>column</code>.
 646      *
 647      * @param   row             the row whose value is to be queried
 648      * @param   column          the column whose value is to be queried
 649      * @return                  the value Object at the specified cell
 650      * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
 651      *               column was given
 652      */
 653     public Object getValueAt(int row, int column) {
 654         Vector rowVector = (Vector)dataVector.elementAt(row);
 655         return rowVector.elementAt(column);
 656     }
 657 
 658     /**
 659      * Sets the object value for the cell at <code>column</code> and
 660      * <code>row</code>.  <code>aValue</code> is the new value.  This method
 661      * will generate a <code>tableChanged</code> notification.
 662      *
 663      * @param   aValue          the new value; this can be null
 664      * @param   row             the row whose value is to be changed
 665      * @param   column          the column whose value is to be changed
 666      * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
 667      *               column was given
 668      */
 669     public void setValueAt(Object aValue, int row, int column) {
 670         Vector rowVector = (Vector)dataVector.elementAt(row);
 671         rowVector.setElementAt(aValue, column);
 672         fireTableCellUpdated(row, column);
 673     }
 674 
 675 //
 676 // Protected Methods
 677 //
 678 
 679     /**
 680      * Returns a vector that contains the same objects as the array.
 681      * @param anArray  the array to be converted
 682      * @return  the new vector; if <code>anArray</code> is <code>null</code>,
 683      *                          returns <code>null</code>
 684      */
 685     protected static Vector convertToVector(Object[] anArray) {
 686         if (anArray == null) {
 687             return null;
 688         }
 689         Vector<Object> v = new Vector<Object>(anArray.length);
 690         for (Object o : anArray) {
 691             v.addElement(o);
 692         }
 693         return v;
 694     }
 695 
 696     /**
 697      * Returns a vector of vectors that contains the same objects as the array.
 698      * @param anArray  the double array to be converted
 699      * @return the new vector of vectors; if <code>anArray</code> is
 700      *                          <code>null</code>, returns <code>null</code>
 701      */
 702     protected static Vector convertToVector(Object[][] anArray) {
 703         if (anArray == null) {
 704             return null;
 705         }
 706         Vector<Vector> v = new Vector<Vector>(anArray.length);
 707         for (Object[] o : anArray) {
 708             v.addElement(convertToVector(o));
 709         }
 710         return v;
 711     }
 712 
 713 } // End of class DefaultTableModel