1 | /* TableColumn.java --
|
---|
2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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.
|
---|
20 |
|
---|
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.
|
---|
25 |
|
---|
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. */
|
---|
37 |
|
---|
38 | package javax.swing.table;
|
---|
39 |
|
---|
40 | // Imports
|
---|
41 | import java.beans.*;
|
---|
42 | import java.io.*;
|
---|
43 | import javax.swing.event.*;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * TableColumn
|
---|
47 | * @author Andrew Selkirk
|
---|
48 | * @version 1.0
|
---|
49 | */
|
---|
50 | public class TableColumn implements Serializable {
|
---|
51 |
|
---|
52 | //-------------------------------------------------------------
|
---|
53 | // Variables --------------------------------------------------
|
---|
54 | //-------------------------------------------------------------
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * COLUMN_WIDTH_PROPERTY
|
---|
58 | */
|
---|
59 | public static final String COLUMN_WIDTH_PROPERTY = "columWidth";
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * HEADER_VALUE_PROPERTY
|
---|
63 | */
|
---|
64 | public static final String HEADER_VALUE_PROPERTY = "headerValue";
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * HEADER_RENDERER_PROPERTY
|
---|
68 | */
|
---|
69 | public static final String HEADER_RENDERER_PROPERTY = "headerRenderer";
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * CELL_RENDERER_PROPERTY
|
---|
73 | */
|
---|
74 | public static final String CELL_RENDERER_PROPERTY = "cellRenderer";
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * modelIndex
|
---|
78 | */
|
---|
79 | protected int modelIndex;
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * identifier
|
---|
83 | */
|
---|
84 | protected Object identifier;
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * width
|
---|
88 | */
|
---|
89 | protected int width;
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * minWidth
|
---|
93 | */
|
---|
94 | protected int minWidth = 15;
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * preferredWidth
|
---|
98 | */
|
---|
99 | private int preferredWidth;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * maxWidth
|
---|
103 | */
|
---|
104 | protected int maxWidth = Integer.MAX_VALUE;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * headerRenderer
|
---|
108 | */
|
---|
109 | protected TableCellRenderer headerRenderer;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * headerValue
|
---|
113 | */
|
---|
114 | protected Object headerValue;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * cellRenderer
|
---|
118 | */
|
---|
119 | protected TableCellRenderer cellRenderer;
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * cellEditor
|
---|
123 | */
|
---|
124 | protected TableCellEditor cellEditor;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * isResizable
|
---|
128 | */
|
---|
129 | protected boolean isResizable = true;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * resizedPostingDisableCount
|
---|
133 | */
|
---|
134 | protected transient int resizedPostingDisableCount;
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * changeSupport
|
---|
138 | */
|
---|
139 | private SwingPropertyChangeSupport changeSupport = new SwingPropertyChangeSupport(this);
|
---|
140 |
|
---|
141 |
|
---|
142 | //-------------------------------------------------------------
|
---|
143 | // Initialization ---------------------------------------------
|
---|
144 | //-------------------------------------------------------------
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Constructor TableColumn
|
---|
148 | */
|
---|
149 | public TableColumn() {
|
---|
150 | this(0, 75, null, null);
|
---|
151 | } // TableColumn()
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Constructor TableColumn
|
---|
155 | * @param modelIndex TODO
|
---|
156 | */
|
---|
157 | public TableColumn(int modelIndex) {
|
---|
158 | this(modelIndex, 75, null, null);
|
---|
159 | } // TableColumn()
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Constructor TableColumn
|
---|
163 | * @param modelIndex TODO
|
---|
164 | * @param width TODO
|
---|
165 | */
|
---|
166 | public TableColumn(int modelIndex, int width) {
|
---|
167 | this(modelIndex, width, null, null);
|
---|
168 | } // TableColumn()
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Constructor TableColumn
|
---|
172 | * @param modelIndex TODO
|
---|
173 | * @param width TODO
|
---|
174 | * @param cellRenderer TODO
|
---|
175 | * @param cellEditor TODO
|
---|
176 | */
|
---|
177 | public TableColumn(int modelIndex, int width,
|
---|
178 | TableCellRenderer cellRenderer, TableCellEditor cellEditor) {
|
---|
179 | this.modelIndex = modelIndex;
|
---|
180 | this.width = width;
|
---|
181 | this.preferredWidth = width;
|
---|
182 | this.cellRenderer = cellRenderer;
|
---|
183 | this.cellEditor = cellEditor;
|
---|
184 | this.headerValue = null;
|
---|
185 | this.identifier = null;
|
---|
186 | } // TableColumn()
|
---|
187 |
|
---|
188 |
|
---|
189 | //-------------------------------------------------------------
|
---|
190 | // Methods ----------------------------------------------------
|
---|
191 | //-------------------------------------------------------------
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * firePropertyChange
|
---|
195 | * @param property TODO
|
---|
196 | * @param oldValue TODO
|
---|
197 | * @param newValue TODO
|
---|
198 | */
|
---|
199 | private void firePropertyChange(String property, Object oldValue, Object newValue) {
|
---|
200 | changeSupport.firePropertyChange(property, oldValue, newValue);
|
---|
201 | } // firePropertyChange()
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * firePropertyChange
|
---|
205 | * @param property TODO
|
---|
206 | * @param oldValue TODO
|
---|
207 | * @param newValue TODO
|
---|
208 | */
|
---|
209 | private void firePropertyChange(String property, int oldValue, int newValue) {
|
---|
210 | firePropertyChange(property, new Integer(oldValue), new Integer(newValue));
|
---|
211 | } // firePropertyChange()
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * firePropertyChange
|
---|
215 | * @param property TODO
|
---|
216 | * @param oldValue TODO
|
---|
217 | * @param newValue TODO
|
---|
218 | */
|
---|
219 | private void firePropertyChange(String property, boolean oldValue, boolean newValue) {
|
---|
220 | firePropertyChange(property, new Boolean(oldValue), new Boolean(newValue));
|
---|
221 | } // firePropertyChange()
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * setModelIndex
|
---|
225 | * @param modelIndex TODO
|
---|
226 | */
|
---|
227 | public void setModelIndex(int modelIndex) {
|
---|
228 | this.modelIndex = modelIndex;
|
---|
229 | } // setModelIndex()
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * getModelIndex
|
---|
233 | * @returns int
|
---|
234 | */
|
---|
235 | public int getModelIndex() {
|
---|
236 | return modelIndex;
|
---|
237 | } // getModelIndex()
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * setIdentifier
|
---|
241 | * @param identifier TODO
|
---|
242 | */
|
---|
243 | public void setIdentifier(Object identifier) {
|
---|
244 | this.identifier = identifier;
|
---|
245 | } // setIdentifier()
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * getIdentifier
|
---|
249 | * @returns Object
|
---|
250 | */
|
---|
251 | public Object getIdentifier() {
|
---|
252 | if (identifier == null) {
|
---|
253 | return getHeaderValue();
|
---|
254 | } // if
|
---|
255 | return identifier;
|
---|
256 | } // getIdentifier()
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * setHeaderValue
|
---|
260 | * @param headerValue TODO
|
---|
261 | */
|
---|
262 | public void setHeaderValue(Object headerValue) {
|
---|
263 |
|
---|
264 | // Variables
|
---|
265 | Object oldValue;
|
---|
266 |
|
---|
267 | // Get Old Value
|
---|
268 | oldValue = this.headerValue;
|
---|
269 |
|
---|
270 | // Set Propeprty
|
---|
271 | this.headerValue = headerValue;
|
---|
272 |
|
---|
273 | // Notify Listeners of change
|
---|
274 | firePropertyChange(HEADER_VALUE_PROPERTY,
|
---|
275 | oldValue, headerValue);
|
---|
276 |
|
---|
277 | } // setHeaderValue()
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * getHeaderValue
|
---|
281 | * @returns Object
|
---|
282 | */
|
---|
283 | public Object getHeaderValue() {
|
---|
284 | return headerValue;
|
---|
285 | } // getHeaderValue()
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * setHeaderRenderer
|
---|
289 | * @param headerRenderer TODO
|
---|
290 | */
|
---|
291 | public void setHeaderRenderer(TableCellRenderer headerRenderer) {
|
---|
292 |
|
---|
293 | // Variables
|
---|
294 | TableCellRenderer oldRenderer;
|
---|
295 |
|
---|
296 | // Get Old Renderer
|
---|
297 | oldRenderer = this.headerRenderer;
|
---|
298 |
|
---|
299 | // Set Property
|
---|
300 | this.headerRenderer = headerRenderer;
|
---|
301 |
|
---|
302 | // Notify Listeners of change
|
---|
303 | firePropertyChange(HEADER_RENDERER_PROPERTY,
|
---|
304 | oldRenderer, headerRenderer);
|
---|
305 |
|
---|
306 | } // setHeaderRenderer()
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * getHeaderRenderer
|
---|
310 | * @returns TableCellRenderer
|
---|
311 | */
|
---|
312 | public TableCellRenderer getHeaderRenderer() {
|
---|
313 | return headerRenderer;
|
---|
314 | } // getHeaderRenderer()
|
---|
315 |
|
---|
316 | /**
|
---|
317 | * setCellRenderer
|
---|
318 | * @param cellRenderer TODO
|
---|
319 | */
|
---|
320 | public void setCellRenderer(TableCellRenderer cellRenderer) {
|
---|
321 |
|
---|
322 | // Variables
|
---|
323 | TableCellRenderer oldRenderer;
|
---|
324 |
|
---|
325 | // Get Old Renderer
|
---|
326 | oldRenderer = this.cellRenderer;
|
---|
327 |
|
---|
328 | // Set Property
|
---|
329 | this.cellRenderer = cellRenderer;
|
---|
330 |
|
---|
331 | // Notify Listeners of change
|
---|
332 | firePropertyChange(CELL_RENDERER_PROPERTY,
|
---|
333 | oldRenderer, cellRenderer);
|
---|
334 |
|
---|
335 | } // setCellRenderer()
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * getCellRenderer
|
---|
339 | * @returns TableCellRenderer
|
---|
340 | */
|
---|
341 | public TableCellRenderer getCellRenderer() {
|
---|
342 | return cellRenderer;
|
---|
343 | } // getCellRenderer()
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * setCellEditor
|
---|
347 | * @param cellEditor TODO
|
---|
348 | */
|
---|
349 | public void setCellEditor(TableCellEditor cellEditor) {
|
---|
350 | this.cellEditor = cellEditor;
|
---|
351 | } // setCellEditor()
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * getCellEditor
|
---|
355 | * @returns TableCellEditor
|
---|
356 | */
|
---|
357 | public TableCellEditor getCellEditor() {
|
---|
358 | return cellEditor;
|
---|
359 | } // getCellEditor()
|
---|
360 |
|
---|
361 | /**
|
---|
362 | * setWidth
|
---|
363 | * @param width TODO
|
---|
364 | */
|
---|
365 | public void setWidth(int width) {
|
---|
366 |
|
---|
367 | // Variables
|
---|
368 | int oldWidth;
|
---|
369 |
|
---|
370 | // Get Old Width
|
---|
371 | oldWidth = this.width;
|
---|
372 |
|
---|
373 | // Adjust Width within Limits
|
---|
374 | if (width < minWidth) {
|
---|
375 | this.width = minWidth;
|
---|
376 | } else if (width > maxWidth) {
|
---|
377 | this.width = maxWidth;
|
---|
378 | } else {
|
---|
379 | this.width = width;
|
---|
380 | } // if
|
---|
381 |
|
---|
382 | // Fire Property Change
|
---|
383 | firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, this.width);
|
---|
384 |
|
---|
385 | } // setWidth()
|
---|
386 |
|
---|
387 | /**
|
---|
388 | * getWidth
|
---|
389 | * @returns int
|
---|
390 | */
|
---|
391 | public int getWidth() {
|
---|
392 | return width;
|
---|
393 | } // getWidth()
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * setPreferredWidth
|
---|
397 | * @param preferredWidth TODO
|
---|
398 | */
|
---|
399 | public void setPreferredWidth(int preferredWidth) {
|
---|
400 | if (preferredWidth < minWidth) {
|
---|
401 | this.preferredWidth = minWidth;
|
---|
402 | } else if (preferredWidth > maxWidth) {
|
---|
403 | this.preferredWidth = maxWidth;
|
---|
404 | } else {
|
---|
405 | this.preferredWidth = preferredWidth;
|
---|
406 | } // if
|
---|
407 | } // setPreferredWidth()
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * getPreferredWidth
|
---|
411 | * @returns int
|
---|
412 | */
|
---|
413 | public int getPreferredWidth() {
|
---|
414 | return preferredWidth;
|
---|
415 | } // getPreferredWidth()
|
---|
416 |
|
---|
417 | /**
|
---|
418 | * setMinWidth
|
---|
419 | * @param minWidth TODO
|
---|
420 | */
|
---|
421 | public void setMinWidth(int minWidth) {
|
---|
422 | this.minWidth = minWidth;
|
---|
423 | setWidth(getWidth());
|
---|
424 | setPreferredWidth(getPreferredWidth());
|
---|
425 | } // setMinWidth()
|
---|
426 |
|
---|
427 | /**
|
---|
428 | * getMinWidth
|
---|
429 | * @returns int
|
---|
430 | */
|
---|
431 | public int getMinWidth() {
|
---|
432 | return minWidth;
|
---|
433 | } // getMinWidth()
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * setMaxWidth
|
---|
437 | * @param maxWidth TODO
|
---|
438 | */
|
---|
439 | public void setMaxWidth(int maxWidth) {
|
---|
440 | this.maxWidth = maxWidth;
|
---|
441 | setWidth(getWidth());
|
---|
442 | setPreferredWidth(getPreferredWidth());
|
---|
443 | } // setMaxWidth()
|
---|
444 |
|
---|
445 | /**
|
---|
446 | * getMaxWidth
|
---|
447 | * @returns int
|
---|
448 | */
|
---|
449 | public int getMaxWidth() {
|
---|
450 | return maxWidth;
|
---|
451 | } // getMaxWidth()
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * setResizable
|
---|
455 | * @param isResizable TODO
|
---|
456 | */
|
---|
457 | public void setResizable(boolean isResizable) {
|
---|
458 | this.isResizable = isResizable;
|
---|
459 | } // setResizable()
|
---|
460 |
|
---|
461 | /**
|
---|
462 | * getResizable
|
---|
463 | * @returns boolean
|
---|
464 | */
|
---|
465 | public boolean getResizable() {
|
---|
466 | return isResizable;
|
---|
467 | } // getResizable()
|
---|
468 |
|
---|
469 | /**
|
---|
470 | * sizeWidthToFit
|
---|
471 | */
|
---|
472 | public void sizeWidthToFit() {
|
---|
473 | // TODO
|
---|
474 | } // sizeWidthToFit()
|
---|
475 |
|
---|
476 | /**
|
---|
477 | * disableResizedPosting
|
---|
478 | */
|
---|
479 | public void disableResizedPosting() {
|
---|
480 | // Does nothing
|
---|
481 | } // disableResizedPosting()
|
---|
482 |
|
---|
483 | /**
|
---|
484 | * enableResizedPosting
|
---|
485 | */
|
---|
486 | public void enableResizedPosting() {
|
---|
487 | // Does nothing
|
---|
488 | } // enableResizedPosting()
|
---|
489 |
|
---|
490 | /**
|
---|
491 | * addPropertyChangeListener
|
---|
492 | * @param listener TODO
|
---|
493 | */
|
---|
494 | public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
|
---|
495 | changeSupport.addPropertyChangeListener(listener);
|
---|
496 | } // addPropertyChangeListener()
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * removePropertyChangeListener
|
---|
500 | * @param listener TODO
|
---|
501 | */
|
---|
502 | public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
|
---|
503 | changeSupport.removePropertyChangeListener(listener);
|
---|
504 | } // removePropertyChangeListener()
|
---|
505 |
|
---|
506 | /**
|
---|
507 | * createDefaultHeaderRenderer
|
---|
508 | * @returns TableCellRenderer
|
---|
509 | */
|
---|
510 | protected TableCellRenderer createDefaultHeaderRenderer() {
|
---|
511 | return new DefaultTableCellRenderer();
|
---|
512 | } // createDefaultHeaderRenderer()
|
---|
513 |
|
---|
514 |
|
---|
515 | } // TableColumn
|
---|