2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / table / AbstractTableModel.java
blob38e36e1744c5484a3aafaf2e4baeed22487d416b
1 /* AbstractTableModel.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.EventListener;
43 import javax.swing.event.EventListenerList;
44 import javax.swing.event.TableModelEvent;
45 import javax.swing.event.TableModelListener;
47 /**
48 * AbstractTableModel
50 * @author Andrew Selkirk
52 public abstract class AbstractTableModel implements TableModel, Serializable
54 static final long serialVersionUID = -5798593159423650347L;
56 /**
57 * listenerList
59 protected EventListenerList listenerList = new EventListenerList();
61 /**
62 * Constructor AbstractTableModel
64 public AbstractTableModel()
66 // TODO
69 /**
70 * Get the name of the column for this index. If you do not override
71 * this methode, you'll get something like: 0, A; 1, B; ...; AA; AB;
72 * ...
74 * @param columnIndex The index of the column.
76 * @return The name of the column.
78 public String getColumnName (int columnIndex)
80 int index = columnIndex + 1;
81 StringBuffer buffer = new StringBuffer();
83 while (index > 0)
85 buffer.insert (0, (char) ('A' + ((index - 1) % 26)));
86 index = (index - 1) / 26;
89 // Return column name.
90 return buffer.toString();
93 /**
94 * Return the index of the given name.
96 * @param columnName The name of the column.
98 * @return The index of the column, -1 if not found.
100 public int findColumn (String columnName)
102 int count = getColumnCount();
104 for (int index = 0; index < count; index++)
106 String name = getColumnName (index);
108 if (name.equals (columnName))
109 return index;
112 // Unable to locate.
113 return -1;
117 * Returns the class of a comlumn.
119 * @param columnIndex The index of the column.
121 * @return The class type of the column.
123 public Class getColumnClass (int columnIndex)
125 return Object.class;
129 * Tells whether a cell is editable.
131 * @param rowIndex The row of the cell.
132 * @param columnIndex The index of the cell.
134 * @return True if cell is editable.
136 public boolean isCellEditable (int rowIndex, int columnIndex)
138 return false;
142 * Sets a cell to a value.
144 * @param value New value of cell.
145 * @param rowIndex The row of the cell.
146 * @param columnIndex The column of the cell.
148 public void setValueAt (Object value, int rowIndex, int columnIndex)
150 // Do nothing...
154 * Add a TableModelListener.
156 * @param listener The listener to add.
158 public void addTableModelListener (TableModelListener listener)
160 listenerList.add (TableModelListener.class, listener);
164 * Removes a TableModelListener.
166 * @param listener The listener to remove.
168 public void removeTableModelListener (TableModelListener listener)
170 listenerList.remove (TableModelListener.class, listener);
174 * Return all registered TableModelListener objects.
176 * @return Array of TableModelListener objects.
178 * @since 1.4
180 public TableModelListener[] getTableModelListeners()
182 return (TableModelListener[])
183 listenerList.getListeners (TableModelListener.class);
187 * fireTableDataChanged
189 public void fireTableDataChanged()
191 fireTableChanged (new TableModelEvent (this));
195 * fireTableStructureChanged
197 public void fireTableStructureChanged()
199 fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW));
203 * fireTableRowsInserted
204 * @param value0 TODO
205 * @param value1 TODO
207 public void fireTableRowsInserted (int firstRow, int lastRow)
209 fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
210 TableModelEvent.ALL_COLUMNS,
211 TableModelEvent.INSERT));
215 * fireTableRowsUpdated
216 * @param value0 TODO
217 * @param value1 TODO
219 public void fireTableRowsUpdated (int firstRow, int lastRow)
221 fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
222 TableModelEvent.ALL_COLUMNS,
223 TableModelEvent.UPDATE));
227 * fireTableRowsDeleted
228 * @param value0 TODO
229 * @param value1 TODO
231 public void fireTableRowsDeleted(int firstRow, int lastRow)
233 fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
234 TableModelEvent.ALL_COLUMNS,
235 TableModelEvent.DELETE));
239 * fireTableCellUpdated
240 * @param value0 TODO
241 * @param value1 TODO
243 public void fireTableCellUpdated (int row, int column)
245 fireTableChanged (new TableModelEvent (this, row, row, column));
249 * fireTableChanged
250 * @param value0 TODO
252 public void fireTableChanged (TableModelEvent event)
254 int index;
255 TableModelListener listener;
256 Object[] list = listenerList.getListenerList();
258 for (index = 0; index < list.length; index += 2)
260 listener = (TableModelListener) list [index + 1];
261 listener.tableChanged (event);
266 * getListeners
267 * @param value0 TODO
268 * @return EventListener[]
270 public EventListener[] getListeners (Class listenerType)
272 return listenerList.getListeners (listenerType);
276 * getValueAt
277 * @param value0 TODO
278 * @param value1 TODO
279 * @return Object
281 public abstract Object getValueAt (int row, int column);
284 * getColumnCount
285 * @return int
287 public abstract int getColumnCount();
290 * getRowCount
291 * @return int
293 public abstract int getRowCount();
295 } // AbstractTableModel