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)
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
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
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
.beans
.PropertyChangeListener
;
42 import java
.io
.Serializable
;
43 import javax
.swing
.event
.SwingPropertyChangeSupport
;
47 * @author Andrew Selkirk
50 public class TableColumn
implements Serializable
52 static final long serialVersionUID
= -6113660025878112608L;
54 //-------------------------------------------------------------
55 // Variables --------------------------------------------------
56 //-------------------------------------------------------------
59 * COLUMN_WIDTH_PROPERTY
61 public static final String COLUMN_WIDTH_PROPERTY
= "columWidth";
64 * HEADER_VALUE_PROPERTY
66 public static final String HEADER_VALUE_PROPERTY
= "headerValue";
69 * HEADER_RENDERER_PROPERTY
71 public static final String HEADER_RENDERER_PROPERTY
= "headerRenderer";
74 * CELL_RENDERER_PROPERTY
76 public static final String CELL_RENDERER_PROPERTY
= "cellRenderer";
81 protected int modelIndex
;
86 protected Object identifier
;
96 protected int minWidth
= 15;
101 private int preferredWidth
;
106 protected int maxWidth
= Integer
.MAX_VALUE
;
111 protected TableCellRenderer headerRenderer
;
116 protected Object headerValue
;
121 protected TableCellRenderer cellRenderer
;
126 protected TableCellEditor cellEditor
;
131 protected boolean isResizable
= true;
134 * resizedPostingDisableCount
136 protected transient int resizedPostingDisableCount
;
141 private SwingPropertyChangeSupport changeSupport
= new SwingPropertyChangeSupport(this);
144 //-------------------------------------------------------------
145 // Initialization ---------------------------------------------
146 //-------------------------------------------------------------
149 * Constructor TableColumn
151 public TableColumn() {
152 this(0, 75, null, null);
156 * Constructor TableColumn
157 * @param modelIndex TODO
159 public TableColumn(int modelIndex
) {
160 this(modelIndex
, 75, null, null);
164 * Constructor TableColumn
165 * @param modelIndex TODO
168 public TableColumn(int modelIndex
, int width
) {
169 this(modelIndex
, width
, null, null);
173 * Constructor TableColumn
174 * @param modelIndex TODO
176 * @param cellRenderer TODO
177 * @param cellEditor TODO
179 public TableColumn(int modelIndex
, int width
,
180 TableCellRenderer cellRenderer
, TableCellEditor cellEditor
) {
181 this.modelIndex
= modelIndex
;
183 this.preferredWidth
= width
;
184 this.cellRenderer
= cellRenderer
;
185 this.cellEditor
= cellEditor
;
186 this.headerValue
= null;
187 this.identifier
= null;
191 //-------------------------------------------------------------
192 // Methods ----------------------------------------------------
193 //-------------------------------------------------------------
197 * @param property TODO
198 * @param oldValue TODO
199 * @param newValue TODO
201 private void firePropertyChange(String property
, Object oldValue
, Object newValue
) {
202 changeSupport
.firePropertyChange(property
, oldValue
, newValue
);
203 } // firePropertyChange()
207 * @param property TODO
208 * @param oldValue TODO
209 * @param newValue TODO
211 private void firePropertyChange(String property
, int oldValue
, int newValue
) {
212 firePropertyChange(property
, new Integer(oldValue
), new Integer(newValue
));
213 } // firePropertyChange()
217 * @param property TODO
218 * @param oldValue TODO
219 * @param newValue TODO
221 private void firePropertyChange(String property
, boolean oldValue
, boolean newValue
) {
222 firePropertyChange(property
, new Boolean(oldValue
), new Boolean(newValue
));
223 } // firePropertyChange()
227 * @param modelIndex TODO
229 public void setModelIndex(int modelIndex
) {
230 this.modelIndex
= modelIndex
;
237 public int getModelIndex() {
243 * @param identifier TODO
245 public void setIdentifier(Object identifier
) {
246 this.identifier
= identifier
;
253 public Object
getIdentifier() {
254 if (identifier
== null) {
255 return getHeaderValue();
262 * @param headerValue TODO
264 public void setHeaderValue(Object headerValue
) {
270 oldValue
= this.headerValue
;
273 this.headerValue
= headerValue
;
275 // Notify Listeners of change
276 firePropertyChange(HEADER_VALUE_PROPERTY
,
277 oldValue
, headerValue
);
279 } // setHeaderValue()
285 public Object
getHeaderValue() {
287 } // getHeaderValue()
291 * @param headerRenderer TODO
293 public void setHeaderRenderer(TableCellRenderer headerRenderer
) {
296 TableCellRenderer oldRenderer
;
299 oldRenderer
= this.headerRenderer
;
302 this.headerRenderer
= headerRenderer
;
304 // Notify Listeners of change
305 firePropertyChange(HEADER_RENDERER_PROPERTY
,
306 oldRenderer
, headerRenderer
);
308 } // setHeaderRenderer()
312 * @returns TableCellRenderer
314 public TableCellRenderer
getHeaderRenderer() {
315 return headerRenderer
;
316 } // getHeaderRenderer()
320 * @param cellRenderer TODO
322 public void setCellRenderer(TableCellRenderer cellRenderer
) {
325 TableCellRenderer oldRenderer
;
328 oldRenderer
= this.cellRenderer
;
331 this.cellRenderer
= cellRenderer
;
333 // Notify Listeners of change
334 firePropertyChange(CELL_RENDERER_PROPERTY
,
335 oldRenderer
, cellRenderer
);
337 } // setCellRenderer()
341 * @returns TableCellRenderer
343 public TableCellRenderer
getCellRenderer() {
345 } // getCellRenderer()
349 * @param cellEditor TODO
351 public void setCellEditor(TableCellEditor cellEditor
) {
352 this.cellEditor
= cellEditor
;
357 * @returns TableCellEditor
359 public TableCellEditor
getCellEditor() {
367 public void setWidth(int width
) {
373 oldWidth
= this.width
;
375 // Adjust Width within Limits
376 if (width
< minWidth
) {
377 this.width
= minWidth
;
378 } else if (width
> maxWidth
) {
379 this.width
= maxWidth
;
384 // Fire Property Change
385 firePropertyChange(COLUMN_WIDTH_PROPERTY
, oldWidth
, this.width
);
393 public int getWidth() {
399 * @param preferredWidth TODO
401 public void setPreferredWidth(int preferredWidth
) {
402 if (preferredWidth
< minWidth
) {
403 this.preferredWidth
= minWidth
;
404 } else if (preferredWidth
> maxWidth
) {
405 this.preferredWidth
= maxWidth
;
407 this.preferredWidth
= preferredWidth
;
409 } // setPreferredWidth()
415 public int getPreferredWidth() {
416 return preferredWidth
;
417 } // getPreferredWidth()
421 * @param minWidth TODO
423 public void setMinWidth(int minWidth
) {
424 this.minWidth
= minWidth
;
425 setWidth(getWidth());
426 setPreferredWidth(getPreferredWidth());
433 public int getMinWidth() {
439 * @param maxWidth TODO
441 public void setMaxWidth(int maxWidth
) {
442 this.maxWidth
= maxWidth
;
443 setWidth(getWidth());
444 setPreferredWidth(getPreferredWidth());
451 public int getMaxWidth() {
457 * @param isResizable TODO
459 public void setResizable(boolean isResizable
) {
460 this.isResizable
= isResizable
;
467 public boolean getResizable() {
474 public void sizeWidthToFit() {
476 } // sizeWidthToFit()
479 * disableResizedPosting
481 public void disableResizedPosting() {
483 } // disableResizedPosting()
486 * enableResizedPosting
488 public void enableResizedPosting() {
490 } // enableResizedPosting()
493 * addPropertyChangeListener
494 * @param listener TODO
496 public synchronized void addPropertyChangeListener(PropertyChangeListener listener
) {
497 changeSupport
.addPropertyChangeListener(listener
);
498 } // addPropertyChangeListener()
501 * removePropertyChangeListener
502 * @param listener TODO
504 public synchronized void removePropertyChangeListener(PropertyChangeListener listener
) {
505 changeSupport
.removePropertyChangeListener(listener
);
506 } // removePropertyChangeListener()
509 * createDefaultHeaderRenderer
510 * @returns TableCellRenderer
512 protected TableCellRenderer
createDefaultHeaderRenderer() {
513 return new DefaultTableCellRenderer();
514 } // createDefaultHeaderRenderer()