fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / javax / swing / table / DefaultTableModel.java
blob5c57f81c6396e3036d3e36c72dbc0d2f64125168
1 /* DefaultTableModel.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.table;
41 import java.io.Serializable;
42 import java.util.Vector;
43 import javax.swing.event.TableModelEvent;
45 /**
46 * DefaultTableModel
47 * @author Andrew Selkirk
49 public class DefaultTableModel extends AbstractTableModel
50 implements Serializable
52 static final long serialVersionUID = 6680042567037222321L;
54 //-------------------------------------------------------------
55 // Variables --------------------------------------------------
56 //-------------------------------------------------------------
58 /**
59 * dataVector
61 protected Vector dataVector;
63 /**
64 * columnIdentifiers
66 protected Vector columnIdentifiers;
69 //-------------------------------------------------------------
70 // Initialization ---------------------------------------------
71 //-------------------------------------------------------------
73 /**
74 * Constructor DefaultTableModel
76 public DefaultTableModel() {
77 this(0, 0);
78 } // DefaultTableModel()
80 /**
81 * Constructor DefaultTableModel
82 * @param value0 TODO
83 * @param value1 TODO
85 public DefaultTableModel(int numRows, int numColumns) {
87 // Variables
88 int columnIndex;
89 Vector defaultNames;
91 // Create Column Names
92 defaultNames = new Vector();
93 for (columnIndex = 0; columnIndex < numColumns; columnIndex++) {
94 defaultNames.addElement(super.getColumnName(columnIndex));
95 } // for
97 // Setup Data
98 // setDataVector(defaultNames, numRows);
100 } // DefaultTableModel()
103 * Constructor DefaultTableModel
104 * @param value0 TODO
105 * @param value1 TODO
107 public DefaultTableModel(Vector columnNames, int numRows) {
109 // Variables
110 Vector data;
111 Vector rowData;
112 int rowIndex;
113 int numColumns;
115 // Create Data
116 data = new Vector();
117 if (columnNames == null) {
118 numColumns = 0;
119 } else {
120 numColumns = columnNames.size();
121 } // if
122 for (rowIndex = 0; rowIndex < numRows; rowIndex++) {
123 rowData = new Vector();
124 rowData.setSize(numColumns);
125 data.addElement(rowData);
126 } // for
128 // Setup Data
129 setDataVector(data, columnNames);
131 } // DefaultTableModel()
134 * Constructor DefaultTableModel
135 * @param value0 TODO
136 * @param value1 TODO
138 public DefaultTableModel(Object[] columnNames, int numRows) {
139 this(convertToVector(columnNames), numRows);
140 } // DefaultTableModel()
143 * Constructor DefaultTableModel
144 * @param value0 TODO
145 * @param value1 TODO
147 public DefaultTableModel(Vector data, Vector columnNames) {
148 setDataVector(data, columnNames);
149 } // DefaultTableModel()
152 * Constructor DefaultTableModel
153 * @param value0 TODO
154 * @param value1 TODO
156 public DefaultTableModel(Object[][] data, Object[] columnNames) {
157 this(convertToVector(data), convertToVector(columnNames));
158 } // DefaultTableModel()
161 //-------------------------------------------------------------
162 // Methods ----------------------------------------------------
163 //-------------------------------------------------------------
166 * getDataVector
167 * @returns Vector
169 public Vector getDataVector() {
170 return dataVector;
171 } // getDataVector()
174 * setDataVector
175 * @param value0 TODO
176 * @param value1 TODO
178 public void setDataVector(Vector data, Vector columnNames) {
180 // Variables
181 int rowIndex;
182 int numRows;
183 int numColumns;
184 Vector columnVector;
186 // Set Data
187 dataVector = data;
188 columnIdentifiers = columnNames;
190 // Check Data
191 numRows = data.size();
192 numColumns = columnNames.size();
193 for (rowIndex = 0; rowIndex < numRows; rowIndex++) {
194 columnVector = (Vector) dataVector.get(rowIndex);
195 columnVector.setSize(numColumns);
196 } // for
198 } // setDataVector()
201 * setDataVector
202 * @param value0 TODO
203 * @param value1 TODO
205 public void setDataVector(Object[][] data, Object[] columnNames) {
206 setDataVector(convertToVector(data), convertToVector(columnNames));
207 } // setDataVector()
210 * newDataAvailable
211 * @param value0 TODO
213 public void newDataAvailable(TableModelEvent event) {
214 fireTableChanged(event);
215 } // newDataAvailable()
218 * newRowsAdded
219 * @param value0 TODO
221 public void newRowsAdded(TableModelEvent event) {
222 // TODO
223 } // newRowsAdded()
226 * rowsRemoved
227 * @param value0 TODO
229 public void rowsRemoved(TableModelEvent event) {
230 fireTableChanged(event);
231 } // rowsRemoved()
234 * setColumnIdentifiers
235 * @param value0 TODO
237 public void setColumnIdentifiers(Vector columnIdentifiers) {
238 this.columnIdentifiers = columnIdentifiers;
239 setColumnCount(columnIdentifiers.size());
240 } // setColumnIdentifiers()
243 * setColumnIdentifiers
244 * @param value0 TODO
246 public void setColumnIdentifiers(Object[] columnIdentifiers) {
247 setColumnIdentifiers(convertToVector(columnIdentifiers));
248 } // setColumnIdentifiers()
251 * setNumRows
252 * @param value0 TODO
254 public void setNumRows(int numRows) {
255 setRowCount(numRows);
256 } // setNumRows()
259 * setRowCount
260 * @param value0 TODO
262 public void setRowCount(int rowCount) {
263 // TODO
264 } // setRowCount()
267 * setColumnCount
268 * @param value0 TODO
270 public void setColumnCount(int columnCount) {
271 // TODO
272 } // setColumnCount()
275 * addColumn
276 * @param value0 TODO
278 public void addColumn(Object columnName) {
279 addColumn(columnName, new Vector(dataVector.size()));
280 } // addColumn()
283 * addColumn
284 * @param value0 TODO
285 * @param value1 TODO
287 public void addColumn(Object columnName, Vector columnData) {
288 // TODO
289 } // addColumn()
292 * addColumn
293 * @param value0 TODO
294 * @param value1 TODO
296 public void addColumn(Object columnName, Object[] columnData) {
297 // TODO
298 } // addColumn()
301 * addRow
302 * @param value0 TODO
304 public void addRow(Vector rowData) {
305 // TODO
306 } // addRow()
309 * addRow
310 * @param value0 TODO
312 public void addRow(Object[] rowData) {
313 addRow(convertToVector(rowData));
314 } // addRow()
317 * insertRow
318 * @param value0 TODO
319 * @param value1 TODO
321 public void insertRow(int row, Vector rowData) {
322 dataVector.add(row, rowData);
323 } // insertRow()
326 * insertRow
327 * @param value0 TODO
328 * @param value1 TODO
330 public void insertRow(int row, Object[] rowData) {
331 insertRow(row, convertToVector(rowData));
332 } // insertRow()
335 * moveRow
336 * @param value0 TODO
337 * @param value1 TODO
338 * @param value2 TODO
340 public void moveRow(int startIndex, int endIndex, int toIndex) {
342 // Variables
343 int index;
344 Vector vector;
346 // Move Rows
347 for (index = 0; index < (endIndex - startIndex); index++) {
348 vector = (Vector) dataVector.remove(startIndex);
349 dataVector.add(toIndex, vector);
350 } // for
352 } // moveRow()
355 * removeRow
356 * @param value0 TODO
358 public void removeRow(int row) {
359 dataVector.remove(row);
360 } // removeRow()
363 * getRowCount
364 * @returns int
366 public int getRowCount() {
367 return dataVector.size();
368 } // getRowCount()
371 * getColumnCount
372 * @returns int
374 public int getColumnCount() {
375 return columnIdentifiers.size();
376 } // getColumnCount()
379 * getColumnName
380 * @param value0 TODO
381 * @returns String
383 public String getColumnName(int column) {
385 // Check for Column
386 if (columnIdentifiers == null || column >= getColumnCount()) {
387 return super.getColumnName(column);
388 } // if
390 // Return Column name
391 return (String) columnIdentifiers.get(column);
393 } // getColumnName()
396 * isCellEditable
397 * @param value0 TODO
398 * @param value1 TODO
399 * @returns boolean
401 public boolean isCellEditable(int row, int column) {
402 return true;
403 } // isCellEditable()
406 * getValueAt
407 * @param value0 TODO
408 * @param value1 TODO
409 * @returns Object
411 public Object getValueAt(int row, int column) {
413 // Variables
414 Vector rowVector;
416 // Get Row Vector
417 rowVector = (Vector) dataVector.get(row);
419 // Get Data
420 return rowVector.get(column);
422 } // getValueAt()
425 * setValueAt
426 * @param value0 TODO
427 * @param value1 TODO
428 * @param value2 TODO
430 public void setValueAt(Object value, int row, int column) {
432 // Variables
433 Vector rowVector;
435 // Get Row Vector
436 rowVector = (Vector) dataVector.get(row);
438 // Set Data
439 rowVector.remove(column);
440 rowVector.add(column, value);
442 } // setValueAt()
445 * convertToVector
446 * @param value0 TODO
447 * @returns Vector
449 protected static Vector convertToVector(Object[] data) {
451 // Variables
452 int index;
453 Vector vector;
455 // Check for null
456 if (data == null) {
457 return null;
458 } // if
460 // Process
461 vector = new Vector();
462 for (index = 0; index < data.length; index++) {
463 vector.add(data[index]);
464 } // for: index
466 // Return new Vector
467 return vector;
469 } // convertToVector()
472 * convertToVector
473 * @param value0 TODO
474 * @returns Vector
476 protected static Vector convertToVector(Object[][] data) {
478 // Variables
479 int index;
480 Vector vector;
482 // Process
483 vector = new Vector();
484 for (index = 0; index < data.length; index++) {
485 vector.add(convertToVector(data[index]));
486 } // for: index
488 // Return new Vector
489 return vector;
491 } // convertToVector()
494 } // DefaultTableModel