src/share/classes/javax/swing/table/DefaultTableModel.java

Print this page

        

*** 68,81 **** /** * The <code>Vector</code> of <code>Vectors</code> of * <code>Object</code> values. */ ! protected Vector<Vector<Object>> dataVector; /** The <code>Vector</code> of column identifiers. */ ! protected Vector<Object> columnIdentifiers; // // Constructors // --- 68,89 ---- /** * The <code>Vector</code> of <code>Vectors</code> of * <code>Object</code> values. */ ! @SuppressWarnings("rawtypes") ! protected Vector<Vector> dataVector; /** The <code>Vector</code> of column identifiers. */ ! @SuppressWarnings("rawtypes") ! protected Vector columnIdentifiers; ! // Unfortunately, for greater source compatibility the inner-most ! // Vector in the two fields above is being left raw. The Vector is ! // read as well as written so using Vector<?> is not suitable and ! // using Vector<Object> (without adding copying of input Vectors), ! // would disallow existing code that used, say, a Vector<String> ! // as an input parameter. // // Constructors //
*** 119,129 **** * <code>null</code> then the model has no columns * @param rowCount the number of rows the table holds * @see #setDataVector * @see #setValueAt */ ! public DefaultTableModel(Vector<Object> columnNames, int rowCount) { setDataVector(newVector(rowCount), columnNames); } /** * Constructs a <code>DefaultTableModel</code> with as many --- 127,137 ---- * <code>null</code> then the model has no columns * @param rowCount the number of rows the table holds * @see #setDataVector * @see #setValueAt */ ! public DefaultTableModel(Vector<?> columnNames, int rowCount) { setDataVector(newVector(rowCount), columnNames); } /** * Constructs a <code>DefaultTableModel</code> with as many
*** 154,164 **** * @param columnNames <code>vector</code> containing the names * of the new columns * @see #getDataVector * @see #setDataVector */ ! public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) { setDataVector(data, columnNames); } /** * Constructs a <code>DefaultTableModel</code> and initializes the table --- 162,172 ---- * @param columnNames <code>vector</code> containing the names * of the new columns * @see #getDataVector * @see #setDataVector */ ! public DefaultTableModel(Vector<Vector<?>> data, Vector<?> columnNames) { setDataVector(data, columnNames); } /** * Constructs a <code>DefaultTableModel</code> and initializes the table
*** 189,199 **** * * @see #newDataAvailable * @see #newRowsAdded * @see #setDataVector */ ! public Vector<Vector<Object>> getDataVector() { return dataVector; } private static <E> Vector<E> nonNullVector(Vector<E> v) { return (v != null) ? v : new Vector<>(); --- 197,208 ---- * * @see #newDataAvailable * @see #newRowsAdded * @see #setDataVector */ ! @SuppressWarnings("rawtypes") ! public Vector<Vector> getDataVector() { return dataVector; } private static <E> Vector<E> nonNullVector(Vector<E> v) { return (v != null) ? v : new Vector<>();
*** 217,229 **** * * @param dataVector the new data vector * @param columnIdentifiers the names of the columns * @see #getDataVector */ ! public void setDataVector(Vector<Vector<Object>> dataVector, ! Vector<Object> columnIdentifiers) { ! this.dataVector = nonNullVector(dataVector); this.columnIdentifiers = nonNullVector(columnIdentifiers); justifyRows(0, getRowCount()); fireTableStructureChanged(); } --- 226,239 ---- * * @param dataVector the new data vector * @param columnIdentifiers the names of the columns * @see #getDataVector */ ! @SuppressWarnings({"rawtypes", "unchecked"}) ! public void setDataVector(Vector<Vector<?>> dataVector, ! Vector<?> columnIdentifiers) { ! this.dataVector = nonNullVector((Vector<Vector>)((Vector)dataVector)); this.columnIdentifiers = nonNullVector(columnIdentifiers); justifyRows(0, getRowCount()); fireTableStructureChanged(); }
*** 265,275 **** for (int i = from; i < to; i++) { if (dataVector.elementAt(i) == null) { dataVector.setElementAt(new Vector<>(), i); } ! ((Vector)dataVector.elementAt(i)).setSize(getColumnCount()); } } /** * Ensures that the new rows have the correct number of columns. --- 275,285 ---- for (int i = from; i < to; i++) { if (dataVector.elementAt(i) == null) { dataVector.setElementAt(new Vector<>(), i); } ! dataVector.elementAt(i).setSize(getColumnCount()); } } /** * Ensures that the new rows have the correct number of columns.
*** 372,382 **** * * @param row the row index of the row to be inserted * @param rowData optional data of the row being added * @exception ArrayIndexOutOfBoundsException if the row was invalid */ ! public void insertRow(int row, Vector<Object> rowData) { dataVector.insertElementAt(rowData, row); justifyRows(row, row+1); fireTableRowsInserted(row, row); } --- 382,392 ---- * * @param row the row index of the row to be inserted * @param rowData optional data of the row being added * @exception ArrayIndexOutOfBoundsException if the row was invalid */ ! public void insertRow(int row, Vector<?> rowData) { dataVector.insertElementAt(rowData, row); justifyRows(row, row+1); fireTableRowsInserted(row, row); }
*** 482,493 **** * @param columnIdentifiers vector of column identifiers. If * <code>null</code>, set the model * to zero columns * @see #setNumRows */ ! public void setColumnIdentifiers(Vector<Object> columnIdentifiers) { ! setDataVector(dataVector, columnIdentifiers); } /** * Replaces the column identifiers in the model. If the number of * <code>newIdentifier</code>s is greater than the current number --- 492,503 ---- * @param columnIdentifiers vector of column identifiers. If * <code>null</code>, set the model * to zero columns * @see #setNumRows */ ! public void setColumnIdentifiers(Vector<?> columnIdentifiers) { ! setDataVector((Vector<Vector<?>>)dataVector, columnIdentifiers); } /** * Replaces the column identifiers in the model. If the number of * <code>newIdentifier</code>s is greater than the current number
*** 548,557 **** --- 558,568 ---- * <code>tableChanged</code> notification message to all the listeners. * * @param columnName the identifier of the column being added * @param columnData optional data of the column being added */ + @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers public void addColumn(Object columnName, Vector<Object> columnData) { columnIdentifiers.addElement(columnName); if (columnData != null) { int columnSize = columnData.size(); if (columnSize > getRowCount()) {
*** 650,661 **** * @return the value Object at the specified cell * @exception ArrayIndexOutOfBoundsException if an invalid row or * column was given */ public Object getValueAt(int row, int column) { ! Vector<Object> rowVector = dataVector.elementAt(row); ! return rowVector.elementAt(column); } /** * Sets the object value for the cell at <code>column</code> and * <code>row</code>. <code>aValue</code> is the new value. This method --- 661,671 ---- * @return the value Object at the specified cell * @exception ArrayIndexOutOfBoundsException if an invalid row or * column was given */ public Object getValueAt(int row, int column) { ! return dataVector.elementAt(row).elementAt(column); } /** * Sets the object value for the cell at <code>column</code> and * <code>row</code>. <code>aValue</code> is the new value. This method
*** 665,677 **** * @param row the row whose value is to be changed * @param column the column whose value is to be changed * @exception ArrayIndexOutOfBoundsException if an invalid row or * column was given */ public void setValueAt(Object aValue, int row, int column) { ! Vector<Object> rowVector = dataVector.elementAt(row); ! rowVector.setElementAt(aValue, column); fireTableCellUpdated(row, column); } // // Protected Methods --- 675,687 ---- * @param row the row whose value is to be changed * @param column the column whose value is to be changed * @exception ArrayIndexOutOfBoundsException if an invalid row or * column was given */ + @SuppressWarnings("unchecked") public void setValueAt(Object aValue, int row, int column) { ! dataVector.elementAt(row).setElementAt(aValue, column); fireTableCellUpdated(row, column); } // // Protected Methods
*** 698,712 **** * Returns a vector of vectors that contains the same objects as the array. * @param anArray the double array to be converted * @return the new vector of vectors; if <code>anArray</code> is * <code>null</code>, returns <code>null</code> */ protected static Vector<Vector<Object>> convertToVector(Object[][] anArray) { if (anArray == null) { return null; } ! Vector<Vector<Object>> v = new Vector<>(anArray.length); for (Object[] o : anArray) { v.addElement(convertToVector(o)); } return v; } --- 708,724 ---- * Returns a vector of vectors that contains the same objects as the array. * @param anArray the double array to be converted * @return the new vector of vectors; if <code>anArray</code> is * <code>null</code>, returns <code>null</code> */ + @SuppressWarnings("rawtypes") protected static Vector<Vector<Object>> convertToVector(Object[][] anArray) { if (anArray == null) { return null; } ! @SuppressWarnings("rawtypes") ! Vector<Vector> v = new Vector<>(anArray.length); for (Object[] o : anArray) { v.addElement(convertToVector(o)); } return v; }