2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This is an implementation of <code>TableModel</code> that 0N/A * uses a <code>Vector</code> of <code>Vectors</code> to store the 0N/A * cell value objects. 0N/A * <strong>Warning:</strong> <code>DefaultTableModel</code> returns a 0N/A * column class of <code>Object</code>. When 0N/A * <code>DefaultTableModel</code> is used with a 0N/A * <code>TableRowSorter</code> this will result in extensive use of 0N/A * <code>toString</code>, which for non-<code>String</code> data types 0N/A * is expensive. If you use <code>DefaultTableModel</code> with a 0N/A * <code>TableRowSorter</code> you are strongly encouraged to override 0N/A * <code>getColumnClass</code> to return the appropriate type. 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * @author Philip Milne 0N/A * @see #getDataVector 0N/A// Instance Variables 0N/A * The <code>Vector</code> of <code>Vectors</code> of 0N/A * <code>Object</code> values. 0N/A /** The <code>Vector</code> of column identifiers. */ 0N/A * Constructs a default <code>DefaultTableModel</code> 0N/A * which is a table of zero columns and zero rows. 0N/A * Constructs a <code>DefaultTableModel</code> with 0N/A * <code>rowCount</code> and <code>columnCount</code> of 0N/A * <code>null</code> object values. 0N/A * @param rowCount the number of rows the table holds 0N/A * @param columnCount the number of columns the table holds 0N/A * Constructs a <code>DefaultTableModel</code> with as many columns 0N/A * as there are elements in <code>columnNames</code> 0N/A * and <code>rowCount</code> of <code>null</code> 0N/A * object values. Each column's name will be taken from 0N/A * the <code>columnNames</code> vector. 0N/A * @param columnNames <code>vector</code> containing the names 0N/A * of the new columns; if this is 0N/A * <code>null</code> then the model has no columns 0N/A * @param rowCount the number of rows the table holds 0N/A * @see #setDataVector 0N/A * Constructs a <code>DefaultTableModel</code> with as many 0N/A * columns as there are elements in <code>columnNames</code> 0N/A * and <code>rowCount</code> of <code>null</code> 0N/A * object values. Each column's name will be taken from 0N/A * the <code>columnNames</code> array. 0N/A * @param columnNames <code>array</code> containing the names 0N/A * of the new columns; if this is 0N/A * <code>null</code> then the model has no columns 0N/A * @param rowCount the number of rows the table holds 0N/A * @see #setDataVector 0N/A * Constructs a <code>DefaultTableModel</code> and initializes the table 0N/A * by passing <code>data</code> and <code>columnNames</code> 0N/A * to the <code>setDataVector</code> method. 0N/A * @param data the data of the table, a <code>Vector</code> 0N/A * of <code>Vector</code>s of <code>Object</code> 0N/A * @param columnNames <code>vector</code> containing the names 0N/A * of the new columns 0N/A * @see #getDataVector 0N/A * @see #setDataVector 0N/A * Constructs a <code>DefaultTableModel</code> and initializes the table 0N/A * by passing <code>data</code> and <code>columnNames</code> 0N/A * to the <code>setDataVector</code> 0N/A * method. The first index in the <code>Object[][]</code> array is 0N/A * the row index and the second is the column index. 0N/A * @param data the data of the table 0N/A * @param columnNames the names of the columns 0N/A * @see #getDataVector 0N/A * @see #setDataVector 0N/A * Returns the <code>Vector</code> of <code>Vectors</code> 0N/A * that contains the table's 0N/A * data values. The vectors contained in the outer vector are 0N/A * each a single row of values. In other words, to get to the cell 0N/A * at row 1, column 5: <p> 0N/A * <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code><p> 0N/A * @return the vector of vectors containing the tables data values 0N/A * @see #newDataAvailable 0N/A * @see #newRowsAdded 0N/A * @see #setDataVector 0N/A * Replaces the current <code>dataVector</code> instance variable 0N/A * with the new <code>Vector</code> of rows, <code>dataVector</code>. 0N/A * Each row is represented in <code>dataVector</code> as a 0N/A * <code>Vector</code> of <code>Object</code> values. 0N/A * <code>columnIdentifiers</code> are the names of the new 0N/A * columns. The first name in <code>columnIdentifiers</code> is 0N/A * mapped to column 0 in <code>dataVector</code>. Each row in 0N/A * <code>dataVector</code> is adjusted to match the number of 0N/A * columns in <code>columnIdentifiers</code> 0N/A * either by truncating the <code>Vector</code> if it is too long, 0N/A * or adding <code>null</code> values if it is too short. 0N/A * <p>Note that passing in a <code>null</code> value for 0N/A * <code>dataVector</code> results in unspecified behavior, 0N/A * an possibly an exception. 0N/A * @param dataVector the new data vector 0N/A * @param columnIdentifiers the names of the columns 0N/A * @see #getDataVector 0N/A * Replaces the value in the <code>dataVector</code> instance 0N/A * variable with the values in the array <code>dataVector</code>. 0N/A * The first index in the <code>Object[][]</code> 0N/A * array is the row index and the second is the column index. 0N/A * <code>columnIdentifiers</code> are the names of the new columns. 0N/A * @param dataVector the new data vector 0N/A * @param columnIdentifiers the names of the columns 0N/A * @see #setDataVector(Vector, Vector) 0N/A * Equivalent to <code>fireTableChanged</code>. 0N/A * @param event the change event 0N/A // Sometimes the DefaultTableModel is subclassed 0N/A // instead of the AbstractTableModel by mistake. 0N/A // Set the number of rows for the case when getRowCount 0N/A * Ensures that the new rows have the correct number of columns. 0N/A * This is accomplished by using the <code>setSize</code> method in 0N/A * <code>Vector</code> which truncates vectors 0N/A * which are too long, and appends <code>null</code>s if they 0N/A * This method also sends out a <code>tableChanged</code> 0N/A * notification message to all the listeners. 0N/A * @param e this <code>TableModelEvent</code> describes 0N/A * where the rows were added. 0N/A * If <code>null</code> it assumes 0N/A * all the rows were newly added 0N/A * @see #getDataVector 0N/A * Equivalent to <code>fireTableChanged</code>. 0N/A * @param event the change event 0N/A * Obsolete as of Java 2 platform v1.3. Please use <code>setRowCount</code> instead. 0N/A * Sets the number of rows in the model. If the new size is greater 0N/A * than the current size, new rows are added to the end of the model 0N/A * If the new size is less than the current size, all 0N/A * rows at index <code>rowCount</code> and greater are discarded. <p> 0N/A * @param rowCount the new number of rows 0N/A * Sets the number of rows in the model. If the new size is greater 0N/A * than the current size, new rows are added to the end of the model 0N/A * If the new size is less than the current size, all 0N/A * rows at index <code>rowCount</code> and greater are discarded. <p> 0N/A * @see #setColumnCount 0N/A * Adds a row to the end of the model. The new row will contain 0N/A * <code>null</code> values unless <code>rowData</code> is specified. 0N/A * Notification of the row being added will be generated. 0N/A * @param rowData optional data of the row being added 0N/A * Adds a row to the end of the model. The new row will contain 0N/A * <code>null</code> values unless <code>rowData</code> is specified. 0N/A * Notification of the row being added will be generated. 0N/A * @param rowData optional data of the row being added 0N/A * Inserts a row at <code>row</code> in the model. The new row 0N/A * will contain <code>null</code> values unless <code>rowData</code> 0N/A * is specified. Notification of the row being added will be generated. 0N/A * @param row the row index of the row to be inserted 0N/A * @param rowData optional data of the row being added 0N/A * @exception ArrayIndexOutOfBoundsException if the row was invalid 0N/A * Inserts a row at <code>row</code> in the model. The new row 0N/A * will contain <code>null</code> values unless <code>rowData</code> 0N/A * is specified. Notification of the row being added will be generated. 0N/A * @param row the row index of the row to be inserted 0N/A * @param rowData optional data of the row being added 0N/A * @exception ArrayIndexOutOfBoundsException if the row was invalid 0N/A private static int gcd(
int i,
int j) {
0N/A return (j ==
0) ? i :
gcd(j, i%j);
0N/A for(
int i =
0; i < g; i++) {
0N/A * Moves one or more rows from the inclusive range <code>start</code> to 0N/A * <code>end</code> to the <code>to</code> position in the model. 0N/A * After the move, the row that was at index <code>start</code> 0N/A * will be at index <code>to</code>. 0N/A * This method will send a <code>tableChanged</code> notification 0N/A * message to all the listeners. <p> 0N/A * Examples of moves: 0N/A * 1. moveRow(1,3,5); 0N/A * a|B|C|D|e|f|g|h|i|j|k - before 0N/A * a|e|f|g|h|B|C|D|i|j|k - after 0N/A * 2. moveRow(6,7,1); 0N/A * a|b|c|d|e|f|G|H|i|j|k - before 0N/A * a|G|H|b|c|d|e|f|i|j|k - after 0N/A * @param start the starting row index to be moved 0N/A * @param end the ending row index to be moved 0N/A * @param to the destination of the rows to be moved 0N/A * @exception ArrayIndexOutOfBoundsException if any of the elements 0N/A * would be moved out of the table's range 0N/A * Removes the row at <code>row</code> from the model. Notification 0N/A * of the row being removed will be sent to all the listeners. 0N/A * @param row the row index of the row to be removed 0N/A * @exception ArrayIndexOutOfBoundsException if the row was invalid 0N/A// Manipulating columns 0N/A * Replaces the column identifiers in the model. If the number of 0N/A * <code>newIdentifier</code>s is greater than the current number 0N/A * of columns, new columns are added to the end of each row in the model. 0N/A * If the number of <code>newIdentifier</code>s is less than the current 0N/A * number of columns, all the extra columns at the end of a row are 0N/A * @param columnIdentifiers vector of column identifiers. If 0N/A * <code>null</code>, set the model 0N/A * Replaces the column identifiers in the model. If the number of 0N/A * <code>newIdentifier</code>s is greater than the current number 0N/A * of columns, new columns are added to the end of each row in the model. 0N/A * If the number of <code>newIdentifier</code>s is less than the current 0N/A * number of columns, all the extra columns at the end of a row are 0N/A * @param newIdentifiers array of column identifiers. 0N/A * If <code>null</code>, set 0N/A * the model to zero columns 0N/A * Sets the number of columns in the model. If the new size is greater 0N/A * than the current size, new columns are added to the end of the model 0N/A * with <code>null</code> cell values. 0N/A * If the new size is less than the current size, all columns at index 0N/A * <code>columnCount</code> and greater are discarded. 0N/A * @param columnCount the new number of columns in the model 0N/A * @see #setColumnCount 0N/A * Adds a column to the model. The new column will have the 0N/A * identifier <code>columnName</code>, which may be null. This method 0N/A * <code>tableChanged</code> notification message to all the listeners. 0N/A * This method is a cover for <code>addColumn(Object, Vector)</code> which 0N/A * uses <code>null</code> as the data vector. 0N/A * @param columnName the identifier of the column being added 0N/A * Adds a column to the model. The new column will have the 0N/A * identifier <code>columnName</code>, which may be null. 0N/A * <code>columnData</code> is the 0N/A * optional vector of data for the column. If it is <code>null</code> 0N/A * the column is filled with <code>null</code> values. Otherwise, 0N/A * the new data will be added to model starting with the first 0N/A * element going to row 0, etc. This method will send a 0N/A * <code>tableChanged</code> notification message to all the listeners. 0N/A * @param columnName the identifier of the column being added 0N/A * @param columnData optional data of the column being added 0N/A * Adds a column to the model. The new column will have the 0N/A * identifier <code>columnName</code>. <code>columnData</code> is the 0N/A * optional array of data for the column. If it is <code>null</code> 0N/A * the column is filled with <code>null</code> values. Otherwise, 0N/A * the new data will be added to model starting with the first 0N/A * element going to row 0, etc. This method will send a 0N/A * <code>tableChanged</code> notification message to all the listeners. 0N/A * @see #addColumn(Object, Vector) 0N/A// Implementing the TableModel interface 0N/A * Returns the number of rows in this data table. 0N/A * @return the number of rows in the model 0N/A * Returns the number of columns in this data table. 0N/A * @return the number of columns in the model 0N/A * Returns the column name. 0N/A * @return a name for this column using the string value of the 0N/A * appropriate member in <code>columnIdentifiers</code>. 0N/A * If <code>columnIdentifiers</code> does not have an entry 0N/A * for this index, returns the default 0N/A * name provided by the superclass. 0N/A // This test is to cover the case when 0N/A // getColumnCount has been subclassed by mistake ... 0N/A * Returns true regardless of parameter values. 0N/A * @param row the row whose value is to be queried 0N/A * @param column the column whose value is to be queried 0N/A * Returns an attribute value for the cell at <code>row</code> 0N/A * and <code>column</code>. 0N/A * @param row the row whose value is to be queried 0N/A * @param column the column whose value is to be queried 0N/A * @return the value Object at the specified cell 0N/A * @exception ArrayIndexOutOfBoundsException if an invalid row or 0N/A * Sets the object value for the cell at <code>column</code> and 0N/A * <code>row</code>. <code>aValue</code> is the new value. This method 0N/A * will generate a <code>tableChanged</code> notification. 0N/A * @param aValue the new value; this can be null 0N/A * @param row the row whose value is to be changed 0N/A * @param column the column whose value is to be changed 0N/A * @exception ArrayIndexOutOfBoundsException if an invalid row or 0N/A * Returns a vector that contains the same objects as the array. 0N/A * @param anArray the array to be converted 0N/A * @return the new vector; if <code>anArray</code> is <code>null</code>, 0N/A * returns <code>null</code> 0N/A * Returns a vector of vectors that contains the same objects as the array. 0N/A * @param anArray the double array to be converted 0N/A * @return the new vector of vectors; if <code>anArray</code> is 0N/A * <code>null</code>, returns <code>null</code> 0N/A}
// End of class DefaultTableModel