equal
deleted
inserted
replaced
68 |
68 |
69 /** |
69 /** |
70 * The <code>Vector</code> of <code>Vectors</code> of |
70 * The <code>Vector</code> of <code>Vectors</code> of |
71 * <code>Object</code> values. |
71 * <code>Object</code> values. |
72 */ |
72 */ |
73 protected Vector<Vector<Object>> dataVector; |
73 @SuppressWarnings("rawtypes") |
|
74 protected Vector<Vector> dataVector; |
74 |
75 |
75 /** The <code>Vector</code> of column identifiers. */ |
76 /** The <code>Vector</code> of column identifiers. */ |
76 protected Vector<Object> columnIdentifiers; |
77 @SuppressWarnings("rawtypes") |
|
78 protected Vector columnIdentifiers; |
|
79 // Unfortunately, for greater source compatibility the inner-most |
|
80 // Vector in the two fields above is being left raw. The Vector is |
|
81 // read as well as written so using Vector<?> is not suitable and |
|
82 // using Vector<Object> (without adding copying of input Vectors), |
|
83 // would disallow existing code that used, say, a Vector<String> |
|
84 // as an input parameter. |
77 |
85 |
78 // |
86 // |
79 // Constructors |
87 // Constructors |
80 // |
88 // |
81 |
89 |
119 * <code>null</code> then the model has no columns |
127 * <code>null</code> then the model has no columns |
120 * @param rowCount the number of rows the table holds |
128 * @param rowCount the number of rows the table holds |
121 * @see #setDataVector |
129 * @see #setDataVector |
122 * @see #setValueAt |
130 * @see #setValueAt |
123 */ |
131 */ |
124 public DefaultTableModel(Vector<Object> columnNames, int rowCount) { |
132 public DefaultTableModel(Vector<?> columnNames, int rowCount) { |
125 setDataVector(newVector(rowCount), columnNames); |
133 setDataVector(newVector(rowCount), columnNames); |
126 } |
134 } |
127 |
135 |
128 /** |
136 /** |
129 * Constructs a <code>DefaultTableModel</code> with as many |
137 * Constructs a <code>DefaultTableModel</code> with as many |
154 * @param columnNames <code>vector</code> containing the names |
162 * @param columnNames <code>vector</code> containing the names |
155 * of the new columns |
163 * of the new columns |
156 * @see #getDataVector |
164 * @see #getDataVector |
157 * @see #setDataVector |
165 * @see #setDataVector |
158 */ |
166 */ |
159 public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) { |
167 @SuppressWarnings("rawtypes") |
|
168 public DefaultTableModel(Vector<? extends Vector> data, Vector<?> columnNames) { |
160 setDataVector(data, columnNames); |
169 setDataVector(data, columnNames); |
161 } |
170 } |
162 |
171 |
163 /** |
172 /** |
164 * Constructs a <code>DefaultTableModel</code> and initializes the table |
173 * Constructs a <code>DefaultTableModel</code> and initializes the table |
189 * |
198 * |
190 * @see #newDataAvailable |
199 * @see #newDataAvailable |
191 * @see #newRowsAdded |
200 * @see #newRowsAdded |
192 * @see #setDataVector |
201 * @see #setDataVector |
193 */ |
202 */ |
194 public Vector<Vector<Object>> getDataVector() { |
203 @SuppressWarnings("rawtypes") |
|
204 public Vector<Vector> getDataVector() { |
195 return dataVector; |
205 return dataVector; |
196 } |
206 } |
197 |
207 |
198 private static <E> Vector<E> nonNullVector(Vector<E> v) { |
208 private static <E> Vector<E> nonNullVector(Vector<E> v) { |
199 return (v != null) ? v : new Vector<>(); |
209 return (v != null) ? v : new Vector<>(); |
217 * |
227 * |
218 * @param dataVector the new data vector |
228 * @param dataVector the new data vector |
219 * @param columnIdentifiers the names of the columns |
229 * @param columnIdentifiers the names of the columns |
220 * @see #getDataVector |
230 * @see #getDataVector |
221 */ |
231 */ |
222 public void setDataVector(Vector<Vector<Object>> dataVector, |
232 @SuppressWarnings({"rawtypes", "unchecked"}) |
223 Vector<Object> columnIdentifiers) { |
233 public void setDataVector(Vector<? extends Vector> dataVector, |
224 this.dataVector = nonNullVector(dataVector); |
234 Vector<?> columnIdentifiers) { |
|
235 this.dataVector = nonNullVector((Vector<Vector>)dataVector); |
225 this.columnIdentifiers = nonNullVector(columnIdentifiers); |
236 this.columnIdentifiers = nonNullVector(columnIdentifiers); |
226 justifyRows(0, getRowCount()); |
237 justifyRows(0, getRowCount()); |
227 fireTableStructureChanged(); |
238 fireTableStructureChanged(); |
228 } |
239 } |
229 |
240 |
265 |
276 |
266 for (int i = from; i < to; i++) { |
277 for (int i = from; i < to; i++) { |
267 if (dataVector.elementAt(i) == null) { |
278 if (dataVector.elementAt(i) == null) { |
268 dataVector.setElementAt(new Vector<>(), i); |
279 dataVector.setElementAt(new Vector<>(), i); |
269 } |
280 } |
270 ((Vector)dataVector.elementAt(i)).setSize(getColumnCount()); |
281 dataVector.elementAt(i).setSize(getColumnCount()); |
271 } |
282 } |
272 } |
283 } |
273 |
284 |
274 /** |
285 /** |
275 * Ensures that the new rows have the correct number of columns. |
286 * Ensures that the new rows have the correct number of columns. |
348 * <code>null</code> values unless <code>rowData</code> is specified. |
359 * <code>null</code> values unless <code>rowData</code> is specified. |
349 * Notification of the row being added will be generated. |
360 * Notification of the row being added will be generated. |
350 * |
361 * |
351 * @param rowData optional data of the row being added |
362 * @param rowData optional data of the row being added |
352 */ |
363 */ |
353 public void addRow(Vector<Object> rowData) { |
364 public void addRow(Vector<?> rowData) { |
354 insertRow(getRowCount(), rowData); |
365 insertRow(getRowCount(), rowData); |
355 } |
366 } |
356 |
367 |
357 /** |
368 /** |
358 * Adds a row to the end of the model. The new row will contain |
369 * Adds a row to the end of the model. The new row will contain |
372 * |
383 * |
373 * @param row the row index of the row to be inserted |
384 * @param row the row index of the row to be inserted |
374 * @param rowData optional data of the row being added |
385 * @param rowData optional data of the row being added |
375 * @exception ArrayIndexOutOfBoundsException if the row was invalid |
386 * @exception ArrayIndexOutOfBoundsException if the row was invalid |
376 */ |
387 */ |
377 public void insertRow(int row, Vector<Object> rowData) { |
388 public void insertRow(int row, Vector<?> rowData) { |
378 dataVector.insertElementAt(rowData, row); |
389 dataVector.insertElementAt(rowData, row); |
379 justifyRows(row, row+1); |
390 justifyRows(row, row+1); |
380 fireTableRowsInserted(row, row); |
391 fireTableRowsInserted(row, row); |
381 } |
392 } |
382 |
393 |
482 * @param columnIdentifiers vector of column identifiers. If |
493 * @param columnIdentifiers vector of column identifiers. If |
483 * <code>null</code>, set the model |
494 * <code>null</code>, set the model |
484 * to zero columns |
495 * to zero columns |
485 * @see #setNumRows |
496 * @see #setNumRows |
486 */ |
497 */ |
487 public void setColumnIdentifiers(Vector<Object> columnIdentifiers) { |
498 public void setColumnIdentifiers(Vector<?> columnIdentifiers) { |
488 setDataVector(dataVector, columnIdentifiers); |
499 setDataVector(dataVector, columnIdentifiers); |
489 } |
500 } |
490 |
501 |
491 /** |
502 /** |
492 * Replaces the column identifiers in the model. If the number of |
503 * Replaces the column identifiers in the model. If the number of |
548 * <code>tableChanged</code> notification message to all the listeners. |
559 * <code>tableChanged</code> notification message to all the listeners. |
549 * |
560 * |
550 * @param columnName the identifier of the column being added |
561 * @param columnName the identifier of the column being added |
551 * @param columnData optional data of the column being added |
562 * @param columnData optional data of the column being added |
552 */ |
563 */ |
553 public void addColumn(Object columnName, Vector<Object> columnData) { |
564 @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers |
|
565 public void addColumn(Object columnName, Vector<?> columnData) { |
554 columnIdentifiers.addElement(columnName); |
566 columnIdentifiers.addElement(columnName); |
555 if (columnData != null) { |
567 if (columnData != null) { |
556 int columnSize = columnData.size(); |
568 int columnSize = columnData.size(); |
557 if (columnSize > getRowCount()) { |
569 if (columnSize > getRowCount()) { |
558 dataVector.setSize(columnSize); |
570 dataVector.setSize(columnSize); |
650 * @return the value Object at the specified cell |
662 * @return the value Object at the specified cell |
651 * @exception ArrayIndexOutOfBoundsException if an invalid row or |
663 * @exception ArrayIndexOutOfBoundsException if an invalid row or |
652 * column was given |
664 * column was given |
653 */ |
665 */ |
654 public Object getValueAt(int row, int column) { |
666 public Object getValueAt(int row, int column) { |
|
667 @SuppressWarnings("unchecked") |
655 Vector<Object> rowVector = dataVector.elementAt(row); |
668 Vector<Object> rowVector = dataVector.elementAt(row); |
656 return rowVector.elementAt(column); |
669 return rowVector.elementAt(column); |
657 } |
670 } |
658 |
671 |
659 /** |
672 /** |
666 * @param column the column whose value is to be changed |
679 * @param column the column whose value is to be changed |
667 * @exception ArrayIndexOutOfBoundsException if an invalid row or |
680 * @exception ArrayIndexOutOfBoundsException if an invalid row or |
668 * column was given |
681 * column was given |
669 */ |
682 */ |
670 public void setValueAt(Object aValue, int row, int column) { |
683 public void setValueAt(Object aValue, int row, int column) { |
|
684 @SuppressWarnings("unchecked") |
671 Vector<Object> rowVector = dataVector.elementAt(row); |
685 Vector<Object> rowVector = dataVector.elementAt(row); |
672 rowVector.setElementAt(aValue, column); |
686 rowVector.setElementAt(aValue, column); |
673 fireTableCellUpdated(row, column); |
687 fireTableCellUpdated(row, column); |
674 } |
688 } |
675 |
689 |