2 Copyright (C) 2002, 2004 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
;
44 import javax
.swing
.event
.SwingPropertyChangeSupport
;
48 * @author Andrew Selkirk
51 public class TableColumn
52 implements Serializable
54 static final long serialVersionUID
= -6113660025878112608L;
57 * COLUMN_WIDTH_PROPERTY
59 public static final String COLUMN_WIDTH_PROPERTY
= "columWidth";
62 * HEADER_VALUE_PROPERTY
64 public static final String HEADER_VALUE_PROPERTY
= "headerValue";
67 * HEADER_RENDERER_PROPERTY
69 public static final String HEADER_RENDERER_PROPERTY
= "headerRenderer";
72 * CELL_RENDERER_PROPERTY
74 public static final String CELL_RENDERER_PROPERTY
= "cellRenderer";
79 protected int modelIndex
;
84 protected Object identifier
;
94 protected int minWidth
= 15;
99 private int preferredWidth
;
104 protected int maxWidth
= Integer
.MAX_VALUE
;
109 protected TableCellRenderer headerRenderer
;
114 protected Object headerValue
;
119 protected TableCellRenderer cellRenderer
;
124 protected TableCellEditor cellEditor
;
129 protected boolean isResizable
= true;
132 * resizedPostingDisableCount
136 protected transient int resizedPostingDisableCount
;
141 private SwingPropertyChangeSupport changeSupport
=
142 new SwingPropertyChangeSupport(this);
145 * Constructor TableColumn
149 this(0, 75, null, null);
153 * Constructor TableColumn
154 * @param modelIndex TODO
156 public TableColumn(int modelIndex
)
158 this(modelIndex
, 75, null, null);
162 * Constructor TableColumn
163 * @param modelIndex TODO
166 public TableColumn(int modelIndex
, int width
)
168 this(modelIndex
, width
, null, null);
172 * Constructor TableColumn
173 * @param modelIndex TODO
175 * @param cellRenderer TODO
176 * @param cellEditor TODO
178 public TableColumn(int modelIndex
, int width
,
179 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;
192 * @param property TODO
193 * @param oldValue TODO
194 * @param newValue TODO
196 private void firePropertyChange(String property
, Object oldValue
,
199 changeSupport
.firePropertyChange(property
, oldValue
, newValue
);
204 * @param property TODO
205 * @param oldValue TODO
206 * @param newValue TODO
208 private void firePropertyChange(String property
, int oldValue
, int newValue
)
210 firePropertyChange(property
, new Integer(oldValue
), new Integer(newValue
));
215 * @param property TODO
216 * @param oldValue TODO
217 * @param newValue TODO
219 private void firePropertyChange(String property
, boolean oldValue
,
222 firePropertyChange(property
, Boolean
.valueOf(oldValue
),
223 Boolean
.valueOf(newValue
));
228 * @param modelIndex TODO
230 public void setModelIndex(int modelIndex
)
232 this.modelIndex
= modelIndex
;
239 public int getModelIndex()
246 * @param identifier TODO
248 public void setIdentifier(Object identifier
)
250 this.identifier
= identifier
;
257 public Object
getIdentifier()
259 if (identifier
== null)
260 return getHeaderValue();
266 * @param headerValue TODO
268 public void setHeaderValue(Object headerValue
)
274 oldValue
= this.headerValue
;
277 this.headerValue
= headerValue
;
279 // Notify Listeners of change
280 firePropertyChange(HEADER_VALUE_PROPERTY
, oldValue
, headerValue
);
287 public Object
getHeaderValue()
294 * @param headerRenderer TODO
296 public void setHeaderRenderer(TableCellRenderer renderer
)
298 if (headerRenderer
== renderer
)
301 TableCellRenderer oldRenderer
= headerRenderer
;
302 headerRenderer
= renderer
;
303 firePropertyChange(HEADER_RENDERER_PROPERTY
,
304 oldRenderer
, headerRenderer
);
309 * @return TableCellRenderer
311 public TableCellRenderer
getHeaderRenderer()
313 return headerRenderer
;
318 * @param cellRenderer TODO
320 public void setCellRenderer(TableCellRenderer renderer
)
322 if (cellRenderer
== renderer
)
325 TableCellRenderer oldRenderer
= cellRenderer
;
326 cellRenderer
= renderer
;
327 firePropertyChange(CELL_RENDERER_PROPERTY
,
328 oldRenderer
, cellRenderer
);
333 * @return TableCellRenderer
335 public TableCellRenderer
getCellRenderer()
342 * @param cellEditor TODO
344 public void setCellEditor(TableCellEditor cellEditor
)
346 this.cellEditor
= cellEditor
;
351 * @return TableCellEditor
353 public TableCellEditor
getCellEditor()
360 * @param newWidth TODO
362 public void setWidth(int newWidth
)
364 int oldWidth
= width
;
366 if (newWidth
< minWidth
)
368 else if (newWidth
> maxWidth
)
373 if (width
== oldWidth
)
376 firePropertyChange(COLUMN_WIDTH_PROPERTY
, oldWidth
, width
);
383 public int getWidth()
390 * @param preferredWidth TODO
392 public void setPreferredWidth(int preferredWidth
)
394 if (preferredWidth
< minWidth
)
395 this.preferredWidth
= minWidth
;
396 else if (preferredWidth
> maxWidth
)
397 this.preferredWidth
= maxWidth
;
399 this.preferredWidth
= preferredWidth
;
406 public int getPreferredWidth()
408 return preferredWidth
;
413 * @param minWidth TODO
415 public void setMinWidth(int minWidth
)
417 this.minWidth
= minWidth
;
418 setWidth(getWidth());
419 setPreferredWidth(getPreferredWidth());
426 public int getMinWidth()
433 * @param maxWidth TODO
435 public void setMaxWidth(int maxWidth
)
437 this.maxWidth
= maxWidth
;
438 setWidth(getWidth());
439 setPreferredWidth(getPreferredWidth());
446 public int getMaxWidth()
453 * @param isResizable TODO
455 public void setResizable(boolean isResizable
)
457 this.isResizable
= isResizable
;
464 public boolean getResizable()
472 public void sizeWidthToFit()
478 * disableResizedPosting
482 public void disableResizedPosting()
488 * enableResizedPosting
492 public void enableResizedPosting()
498 * addPropertyChangeListener
499 * @param listener the listener to all
501 public synchronized void addPropertyChangeListener(PropertyChangeListener listener
)
503 changeSupport
.addPropertyChangeListener(listener
);
507 * removePropertyChangeListener
508 * @param listener the listener to remove
510 public synchronized void removePropertyChangeListener(PropertyChangeListener listener
)
512 changeSupport
.removePropertyChangeListener(listener
);
518 public PropertyChangeListener
[] getPropertyChangeListeners()
520 return changeSupport
.getPropertyChangeListeners();
524 * createDefaultHeaderRenderer
525 * @return TableCellRenderer
527 protected TableCellRenderer
createDefaultHeaderRenderer()
529 return new DefaultTableCellRenderer();