/[classpath]/classpath/javax/swing/table/AbstractTableModel.java
ViewVC logotype

Diff of /classpath/javax/swing/table/AbstractTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by trebligd, Fri Jun 24 21:06:28 2005 UTC revision 1.13 by trebligd, Tue Jun 28 11:40:09 2005 UTC
# Line 1  Line 1 
1  /* AbstractTableModel.java --  /* AbstractTableModel.java --
2     Copyright (C) 2002, 2004  Free Software Foundation, Inc.     Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 46  import javax.swing.event.TableModelEvent Line 46  import javax.swing.event.TableModelEvent
46  import javax.swing.event.TableModelListener;  import javax.swing.event.TableModelListener;
47    
48  /**  /**
49   * AbstractTableModel   * A base class that can be used to create implementations of the
50     * {@link TableModel} interface.
51   *   *
52   * @author Andrew Selkirk   * @author Andrew Selkirk
53   */   */
# Line 55  public abstract class AbstractTableModel Line 56  public abstract class AbstractTableModel
56    static final long serialVersionUID = -5798593159423650347L;    static final long serialVersionUID = -5798593159423650347L;
57    
58    /**    /**
59     * listenerList     * Storage for the listeners registered with this model.
60     */     */
61    protected EventListenerList listenerList = new EventListenerList();    protected EventListenerList listenerList = new EventListenerList();
62    
63    /**    /**
64     * Constructor AbstractTableModel     * Creates a default instance.
65     */     */
66    public AbstractTableModel()    public AbstractTableModel()
67    {    {
68      // TODO      // no setup required here
69    }    }
70    
71    /**    /**
72     * Get the name of the column for this index. If you do not override     * Returns the name of the specified column.  This method generates default
73     * this methode, you'll get something like: 0, A; 1, B; ...; AA; AB;     * names in a sequence (starting with column 0):  A, B, C, ..., Z, AA, AB,
74     * ...     * AC, ..., AZ, BA, BB, BC, and so on.  Subclasses may override this method
75       * to allow column names to be specified on some other basis.
76     *     *
77     * @param columnIndex The index of the column.     * @param columnIndex  the column index.
78     *     *
79     * @return The name of the column.     * @return The name of the column.
80     */     */
81    public String getColumnName (int columnIndex)    public String getColumnName(int columnIndex)
82    {    {
83      StringBuffer buffer = new StringBuffer();      StringBuffer buffer = new StringBuffer();
84      while (columnIndex >= 0)      while (columnIndex >= 0)
85        {        {
86          buffer.insert (0, (char) ('A' + columnIndex % 26));          buffer.insert (0, (char) ('A' + columnIndex % 26));
87          columnIndex = columnIndex / 26 - 1;          columnIndex = columnIndex / 26 - 1;
88        }        }
89      return buffer.toString();      return buffer.toString();
90    }    }
91    
92    /**    /**
93     * Return the index of the given name.     * Return the index of the specified column, or <code>-1</code> if there is
94       * no column with the specified name.
95     *     *
96     * @param columnName The name of the column.     * @param columnName  the name of the column (<code>null</code> not permitted).
97     *     *
98     * @return The index of the column, -1 if not found.     * @return The index of the column, -1 if not found.
99       *
100       * @see #getColumnName(int)
101       * @throws NullPointerException if <code>columnName</code> is
102       *         <code>null</code>.
103     */     */
104    public int findColumn (String columnName)    public int findColumn(String columnName)
105    {    {
106      int count = getColumnCount();      int count = getColumnCount();
107            
108      for (int index = 0; index < count; index++)      for (int index = 0; index < count; index++)
109        {        {
110          String name = getColumnName (index);          String name = getColumnName(index);
111                    
112          if (columnName.equals(name))          if (columnName.equals(name))
113            return index;            return index;
# Line 111  public abstract class AbstractTableModel Line 118  public abstract class AbstractTableModel
118    }    }
119    
120    /**    /**
121     * Returns the class of a comlumn.     * Returns the <code>Class</code> for all <code>Object</code> instances
122     *     * in the specified column.  
123     * @param columnIndex The index of the column.     *
124     *     * @param columnIndex the column index.
125     * @return The class type of the column.     *
126       * @return The class.
127     */     */
128    public Class getColumnClass (int columnIndex)    public Class getColumnClass(int columnIndex)
129    {    {
130      return Object.class;      return Object.class;
131    }    }
132    
133    /**    /**
134     * Tells whether a cell is editable.     * Returns <code>true</code> if the specified cell is editable, and
135       * <code>false</code> if it is not.  This implementation returns
136       * <code>false</code> for all arguments, subclasses should override the
137       * method if necessary.
138     *     *
139     * @param rowIndex The row of the cell.     * @param rowIndex  the row index of the cell.
140     * @param columnIndex The index of the cell.     * @param columnIndex  the column index of the cell.
141     *     *
142     * @return True if cell is editable.     * @return <code>false</code>.
143     */     */
144    public boolean isCellEditable (int rowIndex, int columnIndex)    public boolean isCellEditable(int rowIndex, int columnIndex)
145    {    {
146      return false;      return false;
147    }    }
148    
149    /**    /**
150     * Sets a cell to a value.     * Sets the value of the given cell.  This implementation ignores all
151     *     * arguments and does nothing, subclasses should override the
152     * @param value New value of cell.     * method if necessary.
153     * @param rowIndex The row of the cell.     *
154     * @param columnIndex The column of the cell.     * @param value  the new value (<code>null</code> permitted).
155       * @param rowIndex  the row index of the cell.
156       * @param columnIndex  the column index of the cell.
157     */     */
158    public void setValueAt (Object value, int rowIndex, int columnIndex)    public void setValueAt(Object value, int rowIndex, int columnIndex)
159    {    {
160      // Do nothing...      // Do nothing...
161    }    }
162    
163    /**    /**
164     * Add a TableModelListener.     * Adds a listener to the table model.  The listener will receive notification
165       * of all changes to the table model.
166     *     *
167     * @param listener The listener to add.     * @param listener  the listener.
168     */     */
169    public void addTableModelListener (TableModelListener listener)    public void addTableModelListener(TableModelListener listener)
170    {    {
171      listenerList.add (TableModelListener.class, listener);      listenerList.add(TableModelListener.class, listener);
172    }    }
173    
174    /**    /**
175     * Removes a TableModelListener.     * Removes a listener from the table model so that it will no longer receive
176       * notification of changes to the table model.
177     *     *
178     * @param listener The listener to remove.     * @param listener  the listener to remove.
179     */     */
180    public void removeTableModelListener (TableModelListener listener)    public void removeTableModelListener(TableModelListener listener)
181    {    {
182      listenerList.remove (TableModelListener.class, listener);      listenerList.remove(TableModelListener.class, listener);
183    }    }
184    
185    /**    /**
186     * Return all registered TableModelListener objects.     * Returns an array containing the listeners that have been added to the
187       * table model.
188     *     *
189     * @return Array of TableModelListener objects.     * @return Array of {@link TableModelListener} objects.
190     *     *
191     * @since 1.4     * @since 1.4
192     */     */
193    public TableModelListener[] getTableModelListeners()    public TableModelListener[] getTableModelListeners()
194    {    {
195      return (TableModelListener[])      return (TableModelListener[])
196        listenerList.getListeners (TableModelListener.class);        listenerList.getListeners(TableModelListener.class);
197    }    }
198    
199    /**    /**
200     * fireTableDataChanged     * Sends a {@link TableModelEvent} to all registered listeners to inform
201       * them that the table data has changed.
202     */     */
203    public void fireTableDataChanged()    public void fireTableDataChanged()
204    {    {
# Line 189  public abstract class AbstractTableModel Line 206  public abstract class AbstractTableModel
206    }    }
207    
208    /**    /**
209     * fireTableStructureChanged     * Sends a {@link TableModelEvent} to all registered listeners to inform
210       * them that the table structure has changed.
211     */     */
212    public void fireTableStructureChanged()    public void fireTableStructureChanged()
213    {    {
214      fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW));      fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
215    }    }
216    
217    /**    /**
218     * fireTableRowsInserted     * Sends a {@link TableModelEvent} to all registered listeners to inform
219     * @param value0 TODO     * them that some rows have been inserted into the model.
220     * @param value1 TODO     *
221       * @param firstRow  the index of the first row.
222       * @param lastRow  the index of the last row.
223     */     */
224    public void fireTableRowsInserted (int firstRow, int lastRow)    public void fireTableRowsInserted (int firstRow, int lastRow)
225    {    {
226      fireTableChanged (new TableModelEvent (this, firstRow, lastRow,      fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
227                                             TableModelEvent.ALL_COLUMNS,                                           TableModelEvent.ALL_COLUMNS,
228                                             TableModelEvent.INSERT));                                           TableModelEvent.INSERT));
229    }    }
230    
231    /**    /**
232     * fireTableRowsUpdated     * Sends a {@link TableModelEvent} to all registered listeners to inform
233     * @param value0 TODO     * them that some rows have been updated.
234     * @param value1 TODO     *
235       * @param firstRow  the index of the first row.
236       * @param lastRow  the index of the last row.
237     */     */
238    public void fireTableRowsUpdated (int firstRow, int lastRow)    public void fireTableRowsUpdated (int firstRow, int lastRow)
239    {    {
240      fireTableChanged (new TableModelEvent (this, firstRow, lastRow,      fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
241                                             TableModelEvent.ALL_COLUMNS,                                           TableModelEvent.ALL_COLUMNS,
242                                             TableModelEvent.UPDATE));                                           TableModelEvent.UPDATE));
243    }    }
244    
245    /**    /**
246     * fireTableRowsDeleted     * Sends a {@link TableModelEvent} to all registered listeners to inform
247     * @param value0 TODO     * them that some rows have been deleted from the model.
248     * @param value1 TODO     *
249       * @param firstRow  the index of the first row.
250       * @param lastRow  the index of the last row.
251     */     */
252    public void fireTableRowsDeleted(int firstRow, int lastRow)    public void fireTableRowsDeleted(int firstRow, int lastRow)
253    {    {
254      fireTableChanged (new TableModelEvent (this, firstRow, lastRow,      fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
255                                             TableModelEvent.ALL_COLUMNS,                                           TableModelEvent.ALL_COLUMNS,
256                                             TableModelEvent.DELETE));                                           TableModelEvent.DELETE));
257    }    }
258    
259    /**    /**
260     * fireTableCellUpdated     * Sends a {@link TableModelEvent} to all registered listeners to inform
261     * @param value0 TODO     * them that a single cell has been updated.
262     * @param value1 TODO     *
263       * @param row  the row index.
264       * @param column  the column index.
265     */     */
266    public void fireTableCellUpdated (int row, int column)    public void fireTableCellUpdated (int row, int column)
267    {    {
268      fireTableChanged (new TableModelEvent (this, row, row, column));      fireTableChanged(new TableModelEvent(this, row, row, column));
269    }    }
270    
271    /**    /**
272     * fireTableChanged     * Sends the specified event to all registered listeners.
273     * @param value0 TODO     *
274       * @param event  the event to send.
275     */     */
276    public void fireTableChanged (TableModelEvent event)    public void fireTableChanged(TableModelEvent event)
277    {    {
278      int index;      int index;
279      TableModelListener listener;      TableModelListener listener;
# Line 260  public abstract class AbstractTableModel Line 287  public abstract class AbstractTableModel
287    }    }
288    
289    /**    /**
290     * getListeners     * Returns an array of listeners of the given type that are registered with
291     * @param value0 TODO     * this model.
292     * @return EventListener[]     *
293       * @param listenerType  the listener class.
294       *
295       * @return An array of listeners (possibly empty).
296     */     */
297    public EventListener[] getListeners (Class listenerType)    public EventListener[] getListeners(Class listenerType)
298    {    {
299      return listenerList.getListeners (listenerType);      return listenerList.getListeners(listenerType);
300    }    }
301  }  }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26