46 |
|
|
47 |
/** |
/** |
48 |
* AbstractTableModel |
* AbstractTableModel |
49 |
|
* |
50 |
* @author Andrew Selkirk |
* @author Andrew Selkirk |
51 |
*/ |
*/ |
52 |
public abstract class AbstractTableModel implements TableModel, Serializable |
public abstract class AbstractTableModel implements TableModel, Serializable |
53 |
{ |
{ |
54 |
static final long serialVersionUID = -5798593159423650347L; |
static final long serialVersionUID = -5798593159423650347L; |
55 |
|
|
56 |
//------------------------------------------------------------- |
/** |
57 |
// Variables -------------------------------------------------- |
* listenerList |
58 |
//------------------------------------------------------------- |
*/ |
59 |
|
protected EventListenerList listenerList = new EventListenerList(); |
60 |
/** |
|
61 |
* listenerList |
/** |
62 |
*/ |
* Constructor AbstractTableModel |
63 |
protected EventListenerList listenerList = new EventListenerList(); |
*/ |
64 |
|
public AbstractTableModel() |
65 |
|
{ |
66 |
//------------------------------------------------------------- |
// TODO |
67 |
// Initialization --------------------------------------------- |
} |
68 |
//------------------------------------------------------------- |
|
69 |
|
/** |
70 |
/** |
* getColumnName |
71 |
* Constructor AbstractTableModel |
* @param value0 TODO |
72 |
*/ |
* @return String |
73 |
public AbstractTableModel() { |
*/ |
74 |
// TODO |
public String getColumnName (int columnIndex) |
75 |
} // AbstractTableModel() |
{ |
76 |
|
// Ok, this is not the best solution in the world |
77 |
|
// and it does produce wrong answers starting 1378 |
78 |
//------------------------------------------------------------- |
// but it's a start. I sure hope there is a more |
79 |
// Methods ---------------------------------------------------- |
// simple algorithm. I started with a base 10 to |
80 |
//------------------------------------------------------------- |
// base 26 converter and later found that there |
81 |
|
// were so many are exceptions that it has morphed |
82 |
/** |
// into a pile of goop. |
|
* getColumnName |
|
|
* @param value0 TODO |
|
|
* @returns String |
|
|
*/ |
|
|
public String getColumnName(int columnIndex) { |
|
|
|
|
|
// Variables |
|
|
int index; |
|
|
int left; |
|
|
int base; |
|
|
int multiplier; |
|
|
StringBuffer buffer; |
|
|
boolean foundFirst; |
|
|
|
|
|
// Ok, this is not the best solution in the world |
|
|
// and it does produce wrong answers starting 1378 |
|
|
// but it's a start. I sure hope there is a more |
|
|
// simple algorithm. I started with a base 10 to |
|
|
// base 26 converter and later found that there |
|
|
// were so many are exceptions that it has morphed |
|
|
// into a pile of goop. |
|
83 |
|
|
84 |
// NOTE2: I have a working algorithm which is much |
// NOTE2: I have a working algorithm which is much |
85 |
// much simplier and works for all values...I'll |
// much simplier and works for all values...I'll |
86 |
// be adding it soon... |
// be adding it soon... |
87 |
|
|
88 |
// Process Exponent levels |
StringBuffer buffer = new StringBuffer(); |
89 |
buffer = new StringBuffer(); |
int left = columnIndex; |
90 |
left = columnIndex; |
boolean foundFirst = false; |
91 |
foundFirst = false; |
|
92 |
for (index = 6; index >= 0; index--) { |
// Process Exponent levels. |
93 |
base = (int) (Math.pow(26, index)); |
for (int index = 6; index >= 0; index--) |
94 |
if (index > 1) { |
{ |
95 |
base = base + (int) (Math.pow(26, index - 1)); |
int base = (int) (Math.pow (26, index)); |
96 |
} |
|
97 |
if (base <= left) { |
if (index > 1) |
98 |
multiplier = left / base; |
{ |
99 |
if (foundFirst == false && index > 0) { |
base = base + (int) (Math.pow (26, index - 1)); |
100 |
buffer.append((char) (multiplier + 64)); |
} |
101 |
} else { |
|
102 |
buffer.append((char) (multiplier + 65)); |
if (base <= left) |
103 |
} |
{ |
104 |
left = left - (base * multiplier); |
int multiplier = left / base; |
105 |
foundFirst = true; |
|
106 |
} else if (foundFirst == true || index == 0) { |
if (foundFirst == false |
107 |
buffer.append('A'); |
&& index > 0) |
108 |
} |
{ |
109 |
} // for |
buffer.append ((char) (multiplier + 64)); |
110 |
|
} |
111 |
// Return Column Name |
else |
112 |
return buffer.toString(); |
{ |
113 |
|
buffer.append ((char) (multiplier + 65)); |
114 |
} // getColumnName() |
} |
115 |
|
|
116 |
/** |
left = left - (base * multiplier); |
117 |
* findColumn |
foundFirst = true; |
118 |
* @param value0 TODO |
} |
119 |
* @returns int |
else if (foundFirst == true |
120 |
*/ |
|| index == 0) |
121 |
public int findColumn(String columnName) { |
{ |
122 |
|
buffer.append('A'); |
123 |
// Variables |
} |
124 |
int index; |
} |
125 |
String name; |
|
126 |
int count; |
// Return column name. |
127 |
|
return buffer.toString(); |
128 |
// Process Columns |
} |
129 |
count = getColumnCount(); |
|
130 |
for (index = 0; index < count; index++) { |
/** |
131 |
name = getColumnName(index); |
* findColumn |
132 |
if (columnName.equals(name) == true) { |
* @param value0 TODO |
133 |
return index; |
* @return int |
134 |
} // if |
*/ |
135 |
} // for |
public int findColumn (String columnName) |
136 |
|
{ |
137 |
// Unable to Locate |
int count = getColumnCount(); |
138 |
return -1; |
|
139 |
|
for (int index = 0; index < count; index++) |
140 |
} // findColumn() |
{ |
141 |
|
String name = getColumnName (index); |
142 |
/** |
|
143 |
* getColumnClass |
if (columnName.equals (name)) |
144 |
* @param value0 TODO |
return index; |
145 |
* @returns Class |
} |
146 |
*/ |
|
147 |
public Class getColumnClass(int columnIndex) { |
// Unable to locate. |
148 |
return Object.class; |
return -1; |
149 |
} // getColumnClass() |
} |
150 |
|
|
151 |
/** |
/** |
152 |
* isCellEditable |
* getColumnClass |
153 |
* @param value0 TODO |
* @param value0 TODO |
154 |
* @param value1 TODO |
* @return Class |
155 |
* @returns boolean |
*/ |
156 |
*/ |
public Class getColumnClass (int columnIndex) |
157 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
{ |
158 |
return false; |
return Object.class; |
159 |
} // isCellEditable() |
} |
160 |
|
|
161 |
/** |
/** |
162 |
* setValueAt |
* isCellEditable |
163 |
* @param value0 TODO |
* @param value0 TODO |
164 |
* @param value1 TODO |
* @param value1 TODO |
165 |
* @param value2 TODO |
* @return boolean |
166 |
*/ |
*/ |
167 |
public void setValueAt(Object value, int rowIndex, int columnIndex) { |
public boolean isCellEditable (int rowIndex, int columnIndex) |
168 |
// Do nothing... |
{ |
169 |
} // setValueAt() |
return false; |
170 |
|
} |
171 |
/** |
|
172 |
* addTableModelListener |
/** |
173 |
* @param value0 TODO |
* setValueAt |
174 |
*/ |
* @param value0 TODO |
175 |
public void addTableModelListener(TableModelListener listener) { |
* @param value1 TODO |
176 |
listenerList.add(TableModelListener.class, listener); |
* @param value2 TODO |
177 |
} // addTableModelListener() |
*/ |
178 |
|
public void setValueAt (Object value, int rowIndex, int columnIndex) |
179 |
/** |
{ |
180 |
* removeTableModelListener |
// Do nothing... |
181 |
* @param value0 TODO |
} |
182 |
*/ |
|
183 |
public void removeTableModelListener(TableModelListener listener) { |
/** |
184 |
listenerList.remove(TableModelListener.class, listener); |
* addTableModelListener |
185 |
} // removeTableModelListener() |
* @param value0 TODO |
186 |
|
*/ |
187 |
/** |
public void addTableModelListener (TableModelListener listener) |
188 |
* fireTableDataChanged |
{ |
189 |
*/ |
listenerList.add (TableModelListener.class, listener); |
190 |
public void fireTableDataChanged() { |
} |
191 |
fireTableChanged(new TableModelEvent(this)); |
|
192 |
} // fireTableDataChanged() |
/** |
193 |
|
* removeTableModelListener |
194 |
/** |
* @param value0 TODO |
195 |
* fireTableStructureChanged |
*/ |
196 |
*/ |
public void removeTableModelListener (TableModelListener listener) |
197 |
public void fireTableStructureChanged() { |
{ |
198 |
fireTableChanged(new TableModelEvent(this, |
listenerList.remove (TableModelListener.class, listener); |
199 |
TableModelEvent.HEADER_ROW)); |
} |
200 |
} // fireTableStructureChanged() |
|
201 |
|
/** |
202 |
/** |
* fireTableDataChanged |
203 |
* fireTableRowsInserted |
*/ |
204 |
* @param value0 TODO |
public void fireTableDataChanged() |
205 |
* @param value1 TODO |
{ |
206 |
*/ |
fireTableChanged (new TableModelEvent (this)); |
207 |
public void fireTableRowsInserted(int firstRow, int lastRow) { |
} |
208 |
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, |
|
209 |
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); |
/** |
210 |
} // fireTableRowsInserted() |
* fireTableStructureChanged |
211 |
|
*/ |
212 |
/** |
public void fireTableStructureChanged() |
213 |
* fireTableRowsUpdated |
{ |
214 |
* @param value0 TODO |
fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW)); |
215 |
* @param value1 TODO |
} |
216 |
*/ |
|
217 |
public void fireTableRowsUpdated(int firstRow, int lastRow) { |
/** |
218 |
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, |
* fireTableRowsInserted |
219 |
TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); |
* @param value0 TODO |
220 |
} // fireTableRowsUpdated() |
* @param value1 TODO |
221 |
|
*/ |
222 |
/** |
public void fireTableRowsInserted (int firstRow, int lastRow) |
223 |
* fireTableRowsDeleted |
{ |
224 |
* @param value0 TODO |
fireTableChanged (new TableModelEvent (this, firstRow, lastRow, |
225 |
* @param value1 TODO |
TableModelEvent.ALL_COLUMNS, |
226 |
*/ |
TableModelEvent.INSERT)); |
227 |
public void fireTableRowsDeleted(int firstRow, int lastRow) { |
} |
228 |
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, |
|
229 |
TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); |
/** |
230 |
} // fireTableRowsDeleted() |
* fireTableRowsUpdated |
231 |
|
* @param value0 TODO |
232 |
/** |
* @param value1 TODO |
233 |
* fireTableCellUpdated |
*/ |
234 |
* @param value0 TODO |
public void fireTableRowsUpdated (int firstRow, int lastRow) |
235 |
* @param value1 TODO |
{ |
236 |
*/ |
fireTableChanged (new TableModelEvent (this, firstRow, lastRow, |
237 |
public void fireTableCellUpdated(int row, int column) { |
TableModelEvent.ALL_COLUMNS, |
238 |
fireTableChanged(new TableModelEvent(this, row, row, column)); |
TableModelEvent.UPDATE)); |
239 |
} // fireTableCellUpdated() |
} |
240 |
|
|
241 |
/** |
/** |
242 |
* fireTableChanged |
* fireTableRowsDeleted |
243 |
* @param value0 TODO |
* @param value0 TODO |
244 |
*/ |
* @param value1 TODO |
245 |
public void fireTableChanged(TableModelEvent event) { |
*/ |
246 |
|
public void fireTableRowsDeleted(int firstRow, int lastRow) |
247 |
// Variables |
{ |
248 |
Object[] list; |
fireTableChanged (new TableModelEvent (this, firstRow, lastRow, |
249 |
int index; |
TableModelEvent.ALL_COLUMNS, |
250 |
TableModelListener listener; |
TableModelEvent.DELETE)); |
251 |
|
} |
252 |
|
|
253 |
|
/** |
254 |
|
* fireTableCellUpdated |
255 |
|
* @param value0 TODO |
256 |
|
* @param value1 TODO |
257 |
|
*/ |
258 |
|
public void fireTableCellUpdated (int row, int column) |
259 |
|
{ |
260 |
|
fireTableChanged (new TableModelEvent (this, row, row, column)); |
261 |
|
} |
262 |
|
|
263 |
|
/** |
264 |
|
* fireTableChanged |
265 |
|
* @param value0 TODO |
266 |
|
*/ |
267 |
|
public void fireTableChanged (TableModelEvent event) |
268 |
|
{ |
269 |
|
int index; |
270 |
|
TableModelListener listener; |
271 |
|
Object[] list = listenerList.getListenerList(); |
272 |
|
|
273 |
// Get Listener List |
for (index = 0; index < list.length; index += 2) |
274 |
list = listenerList.getListenerList(); |
{ |
275 |
|
listener = (TableModelListener) list [index + 1]; |
276 |
for (index = 0; index < list.length; index += 2) { |
listener.tableChanged (event); |
277 |
|
} |
278 |
// Get Listener |
} |
279 |
listener = (TableModelListener) list[index + 1]; |
|
280 |
|
/** |
281 |
// Notify Listener |
* getListeners |
282 |
listener.tableChanged(event); |
* @param value0 TODO |
283 |
|
* @return EventListener[] |
284 |
} // for: index |
*/ |
285 |
|
public EventListener[] getListeners (Class listenerType) |
286 |
} // fireTableChanged() |
{ |
287 |
|
return listenerList.getListeners (listenerType); |
288 |
/** |
} |
289 |
* getListeners |
|
290 |
* @param value0 TODO |
/** |
291 |
* @returns EventListener[] |
* getValueAt |
292 |
*/ |
* @param value0 TODO |
293 |
public EventListener[] getListeners(Class listenerType) { |
* @param value1 TODO |
294 |
return listenerList.getListeners(listenerType); |
* @return Object |
295 |
} // getListeners() |
*/ |
296 |
|
public abstract Object getValueAt (int row, int column); |
297 |
/** |
|
298 |
* getValueAt |
/** |
299 |
* @param value0 TODO |
* getColumnCount |
300 |
* @param value1 TODO |
* @return int |
301 |
* @returns Object |
*/ |
302 |
*/ |
public abstract int getColumnCount(); |
303 |
public abstract Object getValueAt(int row, int column); |
|
304 |
|
/** |
305 |
/** |
* getRowCount |
306 |
* getColumnCount |
* @return int |
307 |
* @returns int |
*/ |
308 |
*/ |
public abstract int getRowCount(); |
|
public abstract int getColumnCount(); |
|
|
|
|
|
/** |
|
|
* getRowCount |
|
|
* @returns int |
|
|
*/ |
|
|
public abstract int getRowCount(); |
|
|
|
|
309 |
|
|
310 |
} // AbstractTableModel |
} // AbstractTableModel |
|
|
|