source: trunk/gcc/libjava/javax/swing/table/AbstractTableModel.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1/* AbstractTableModel.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing.table;
39
40// Imports
41import java.io.*;
42import java.util.*;
43import javax.swing.event.*;
44
45/**
46 * AbstractTableModel
47 * @author Andrew Selkirk
48 */
49public abstract class AbstractTableModel implements TableModel, Serializable {
50
51 //-------------------------------------------------------------
52 // Variables --------------------------------------------------
53 //-------------------------------------------------------------
54
55 /**
56 * listenerList
57 */
58 protected EventListenerList listenerList = new EventListenerList();
59
60
61 //-------------------------------------------------------------
62 // Initialization ---------------------------------------------
63 //-------------------------------------------------------------
64
65 /**
66 * Constructor AbstractTableModel
67 */
68 public AbstractTableModel() {
69 // TODO
70 } // AbstractTableModel()
71
72
73 //-------------------------------------------------------------
74 // Methods ----------------------------------------------------
75 //-------------------------------------------------------------
76
77 /**
78 * getColumnName
79 * @param value0 TODO
80 * @returns String
81 */
82 public String getColumnName(int columnIndex) {
83
84 // Variables
85 int index;
86 int left;
87 int base;
88 int multiplier;
89 StringBuffer buffer;
90 boolean foundFirst;
91
92 // Ok, this is not the best solution in the world
93 // and it does produce wrong answers starting 1378
94 // but it's a start. I sure hope there is a more
95 // simple algorithm. I started with a base 10 to
96 // base 26 converter and later found that there
97 // were so many are exceptions that it has morphed
98 // into a pile of goop.
99
100 // NOTE2: I have a working algorithm which is much
101 // much simplier and works for all values...I'll
102 // be adding it soon...
103
104 // Process Exponent levels
105 buffer = new StringBuffer();
106 left = columnIndex;
107 foundFirst = false;
108 for (index = 6; index >= 0; index--) {
109 base = (int) (Math.pow(26, index));
110 if (index > 1) {
111 base = base + (int) (Math.pow(26, index - 1));
112 }
113 if (base <= left) {
114 multiplier = left / base;
115 if (foundFirst == false && index > 0) {
116 buffer.append((char) (multiplier + 64));
117 } else {
118 buffer.append((char) (multiplier + 65));
119 }
120 left = left - (base * multiplier);
121 foundFirst = true;
122 } else if (foundFirst == true || index == 0) {
123 buffer.append('A');
124 }
125 } // for
126
127 // Return Column Name
128 return buffer.toString();
129
130 } // getColumnName()
131
132 /**
133 * findColumn
134 * @param value0 TODO
135 * @returns int
136 */
137 public int findColumn(String columnName) {
138
139 // Variables
140 int index;
141 String name;
142 int count;
143
144 // Process Columns
145 count = getColumnCount();
146 for (index = 0; index < count; index++) {
147 name = getColumnName(index);
148 if (columnName.equals(name) == true) {
149 return index;
150 } // if
151 } // for
152
153 // Unable to Locate
154 return -1;
155
156 } // findColumn()
157
158 /**
159 * getColumnClass
160 * @param value0 TODO
161 * @returns Class
162 */
163 public Class getColumnClass(int columnIndex) {
164 return Object.class;
165 } // getColumnClass()
166
167 /**
168 * isCellEditable
169 * @param value0 TODO
170 * @param value1 TODO
171 * @returns boolean
172 */
173 public boolean isCellEditable(int rowIndex, int columnIndex) {
174 return false;
175 } // isCellEditable()
176
177 /**
178 * setValueAt
179 * @param value0 TODO
180 * @param value1 TODO
181 * @param value2 TODO
182 */
183 public void setValueAt(Object value, int rowIndex, int columnIndex) {
184 // Do nothing...
185 } // setValueAt()
186
187 /**
188 * addTableModelListener
189 * @param value0 TODO
190 */
191 public void addTableModelListener(TableModelListener listener) {
192 listenerList.add(TableModelListener.class, listener);
193 } // addTableModelListener()
194
195 /**
196 * removeTableModelListener
197 * @param value0 TODO
198 */
199 public void removeTableModelListener(TableModelListener listener) {
200 listenerList.remove(TableModelListener.class, listener);
201 } // removeTableModelListener()
202
203 /**
204 * fireTableDataChanged
205 */
206 public void fireTableDataChanged() {
207 fireTableChanged(new TableModelEvent(this));
208 } // fireTableDataChanged()
209
210 /**
211 * fireTableStructureChanged
212 */
213 public void fireTableStructureChanged() {
214 fireTableChanged(new TableModelEvent(this,
215 TableModelEvent.HEADER_ROW));
216 } // fireTableStructureChanged()
217
218 /**
219 * fireTableRowsInserted
220 * @param value0 TODO
221 * @param value1 TODO
222 */
223 public void fireTableRowsInserted(int firstRow, int lastRow) {
224 fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
225 TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
226 } // fireTableRowsInserted()
227
228 /**
229 * fireTableRowsUpdated
230 * @param value0 TODO
231 * @param value1 TODO
232 */
233 public void fireTableRowsUpdated(int firstRow, int lastRow) {
234 fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
235 TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
236 } // fireTableRowsUpdated()
237
238 /**
239 * fireTableRowsDeleted
240 * @param value0 TODO
241 * @param value1 TODO
242 */
243 public void fireTableRowsDeleted(int firstRow, int lastRow) {
244 fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
245 TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
246 } // fireTableRowsDeleted()
247
248 /**
249 * fireTableCellUpdated
250 * @param value0 TODO
251 * @param value1 TODO
252 */
253 public void fireTableCellUpdated(int row, int column) {
254 fireTableChanged(new TableModelEvent(this, row, row, column));
255 } // fireTableCellUpdated()
256
257 /**
258 * fireTableChanged
259 * @param value0 TODO
260 */
261 public void fireTableChanged(TableModelEvent event) {
262
263 // Variables
264 Object[] list;
265 int index;
266 TableModelListener listener;
267
268 // Get Listener List
269 list = listenerList.getListenerList();
270
271 for (index = 0; index < list.length; index += 2) {
272
273 // Get Listener
274 listener = (TableModelListener) list[index + 1];
275
276 // Notify Listener
277 listener.tableChanged(event);
278
279 } // for: index
280
281 } // fireTableChanged()
282
283 /**
284 * getListeners
285 * @param value0 TODO
286 * @returns EventListener[]
287 */
288 public EventListener[] getListeners(Class listenerType) {
289 return listenerList.getListeners(listenerType);
290 } // getListeners()
291
292 /**
293 * getValueAt
294 * @param value0 TODO
295 * @param value1 TODO
296 * @returns Object
297 */
298 public abstract Object getValueAt(int row, int column);
299
300 /**
301 * getColumnCount
302 * @returns int
303 */
304 public abstract int getColumnCount();
305
306 /**
307 * getRowCount
308 * @returns int
309 */
310 public abstract int getRowCount();
311
312
313} // AbstractTableModel
314
Note: See TracBrowser for help on using the repository browser.