Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / table / TableColumn.java
blob9f06c5b7fccd85497c472577d9c8f0c23cc686eb
1 /* TableColumn.java --
2 Copyright (C) 2002, 2004, 2005 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)
9 any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
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.
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.PropertyChangeEvent;
42 import java.beans.PropertyChangeListener;
43 import java.io.Serializable;
45 import javax.swing.event.SwingPropertyChangeSupport;
47 /**
48 * Represents the attributes of a column in a table, including the column index,
49 * width, minimum width, preferred width and maximum width.
51 * @author Andrew Selkirk
52 * @version 1.0
54 public class TableColumn
55 implements Serializable
57 static final long serialVersionUID = -6113660025878112608L;
59 /**
60 * The name for the <code>columnWidth</code> property. Note that the typo
61 * in the name value is deliberate, to match the specification.
63 public static final String COLUMN_WIDTH_PROPERTY = "columWidth";
65 /**
66 * The name for the <code>headerValue</code> property.
68 public static final String HEADER_VALUE_PROPERTY = "headerValue";
70 /**
71 * The name for the <code>headerRenderer</code> property.
73 public static final String HEADER_RENDERER_PROPERTY = "headerRenderer";
75 /**
76 * The name for the <code>cellRenderer</code> property.
78 public static final String CELL_RENDERER_PROPERTY = "cellRenderer";
80 /**
81 * The index of the corresponding column in the table model.
83 protected int modelIndex;
85 /**
86 * The identifier for the column.
88 protected Object identifier;
90 /**
91 * The width.
93 protected int width;
95 /**
96 * The minimum width.
98 protected int minWidth = 15;
101 * The preferred width.
103 private int preferredWidth;
106 * The maximum width.
108 protected int maxWidth = Integer.MAX_VALUE;
111 * headerRenderer
113 protected TableCellRenderer headerRenderer;
116 * The header value.
118 protected Object headerValue;
121 * cellRenderer
123 protected TableCellRenderer cellRenderer;
126 * cellEditor
128 protected TableCellEditor cellEditor;
131 * isResizable
133 protected boolean isResizable = true;
136 * resizedPostingDisableCount
138 * @deprecated 1.3
140 protected transient int resizedPostingDisableCount;
143 * changeSupport
145 private SwingPropertyChangeSupport changeSupport =
146 new SwingPropertyChangeSupport(this);
149 * Creates a new <code>TableColumn</code> that maps to column 0 in the
150 * related table model. The default width is <code>75</code> units.
152 public TableColumn()
154 this(0, 75, null, null);
158 * Creates a new <code>TableColumn</code> that maps to the specified column
159 * in the related table model. The default width is <code>75</code> units.
161 * @param modelIndex the index of the column in the model
163 public TableColumn(int modelIndex)
165 this(modelIndex, 75, null, null);
169 * Creates a new <code>TableColumn</code> that maps to the specified column
170 * in the related table model, and has the specified <code>width</code>.
172 * @param modelIndex the index of the column in the model
173 * @param width the width
175 public TableColumn(int modelIndex, int width)
177 this(modelIndex, width, null, null);
181 * Creates a new <code>TableColumn</code> that maps to the specified column
182 * in the related table model, and has the specified <code>width</code>,
183 * <code>cellRenderer</code> and <code>cellEditor</code>.
185 * @param modelIndex the index of the column in the model
186 * @param width the width
187 * @param cellRenderer the cell renderer (<code>null</code> permitted).
188 * @param cellEditor the cell editor (<code>null</code> permitted).
190 public TableColumn(int modelIndex, int width,
191 TableCellRenderer cellRenderer, TableCellEditor cellEditor)
193 this.modelIndex = modelIndex;
194 this.width = width;
195 this.preferredWidth = width;
196 this.cellRenderer = cellRenderer;
197 this.cellEditor = cellEditor;
198 this.headerValue = null;
199 this.identifier = null;
203 * firePropertyChange
205 * @param property the name of the property
206 * @param oldValue the old value
207 * @param newValue the new value
209 private void firePropertyChange(String property, Object oldValue,
210 Object newValue)
212 changeSupport.firePropertyChange(property, oldValue, newValue);
216 * firePropertyChange
218 * @param property the name of the property
219 * @param oldValue the old value
220 * @param newValue the new value
222 private void firePropertyChange(String property, int oldValue, int newValue)
224 firePropertyChange(property, new Integer(oldValue), new Integer(newValue));
228 * firePropertyChange
230 * @param property the name of the property
231 * @param oldValue the old value
232 * @param newValue the new value
234 private void firePropertyChange(String property, boolean oldValue,
235 boolean newValue)
237 firePropertyChange(property, Boolean.valueOf(oldValue),
238 Boolean.valueOf(newValue));
242 * Sets the index of the column in the related {@link TableModel} that this
243 * <code>TableColumn</code> maps to.
245 * @param modelIndex the column index in the model.
247 public void setModelIndex(int modelIndex)
249 this.modelIndex = modelIndex;
253 * Returns the index of the column in the related {@link TableModel} that
254 * this <code>TableColumn</code> maps to.
256 * @return the model index
258 public int getModelIndex()
260 return modelIndex;
264 * Sets the identifier for the column.
266 * @param identifier the identifier
268 public void setIdentifier(Object identifier)
270 this.identifier = identifier;
274 * Returns the identifier for the column, or {@link #getHeaderValue()} if the
275 * identifier is <code>null</code>.
277 * @return The identifier (or {@link #getHeaderValue()} if the identifier is
278 * <code>null</code>).
280 public Object getIdentifier()
282 if (identifier == null)
283 return getHeaderValue();
284 return identifier;
288 * Sets the header value and sends a {@link PropertyChangeEvent} to all
289 * registered listeners. The header value property uses the name
290 * {@link #HEADER_VALUE_PROPERTY}.
292 * @param headerValue the value of the header
294 public void setHeaderValue(Object headerValue)
296 if (this.headerValue == headerValue)
297 return;
299 Object oldValue = this.headerValue;
300 this.headerValue = headerValue;
301 firePropertyChange(HEADER_VALUE_PROPERTY, oldValue, headerValue);
305 * Returns the header value.
307 * @return the value of the header
309 public Object getHeaderValue()
311 return headerValue;
315 * setHeaderRenderer
317 * @param renderer the renderer to use
319 public void setHeaderRenderer(TableCellRenderer renderer)
321 if (headerRenderer == renderer)
322 return;
324 TableCellRenderer oldRenderer = headerRenderer;
325 headerRenderer = renderer;
326 firePropertyChange(HEADER_RENDERER_PROPERTY,
327 oldRenderer, headerRenderer);
331 * getHeaderRenderer
332 * @return TableCellRenderer
334 public TableCellRenderer getHeaderRenderer()
336 return headerRenderer;
340 * Sets the renderer for cells in this column and sends a
341 * {@link PropertyChangeEvent} to all registered listeners.
343 * @param renderer the cell renderer (<code>null</code> permitted).
345 public void setCellRenderer(TableCellRenderer renderer)
347 if (cellRenderer == renderer)
348 return;
350 TableCellRenderer oldRenderer = cellRenderer;
351 cellRenderer = renderer;
352 firePropertyChange(CELL_RENDERER_PROPERTY,
353 oldRenderer, cellRenderer);
357 * Returns the renderer for the table cells in this column.
359 * @return The cell renderer.
361 public TableCellRenderer getCellRenderer()
363 return cellRenderer;
367 * setCellEditor
369 * @param cellEditor the cell editor
371 public void setCellEditor(TableCellEditor cellEditor)
373 this.cellEditor = cellEditor;
377 * getCellEditor
379 * @return the cell editor
381 public TableCellEditor getCellEditor()
383 return cellEditor;
387 * setWidth
389 * @param newWidth the width
391 public void setWidth(int newWidth)
393 int oldWidth = width;
395 if (newWidth < minWidth)
396 width = minWidth;
397 else if (newWidth > maxWidth)
398 width = maxWidth;
399 else
400 width = newWidth;
402 if (width == oldWidth)
403 return;
405 // We do have a constant field COLUMN_WIDTH_PROPERTY,
406 // however, tests show that the actual fired property name is 'width'
407 // and even Sun's API docs say that this constant field is obsolete and
408 // not used.
409 firePropertyChange("width", oldWidth, width);
413 * getWidth
415 * @return int
417 public int getWidth()
419 return width;
423 * setPreferredWidth
425 * @param preferredWidth the preferred width
427 public void setPreferredWidth(int preferredWidth)
429 int oldPrefWidth = this.preferredWidth;
431 if (preferredWidth < minWidth)
432 this.preferredWidth = minWidth;
433 else if (preferredWidth > maxWidth)
434 this.preferredWidth = maxWidth;
435 else
436 this.preferredWidth = preferredWidth;
438 firePropertyChange("preferredWidth", oldPrefWidth, this.preferredWidth);
442 * getPreferredWidth
444 * @return the preferred width
446 public int getPreferredWidth()
448 return preferredWidth;
452 * Sets the minimum width for the column and, if necessary, updates the
453 * <code>width</code> and <code>preferredWidth</code>.
455 * @param minWidth the minimum width
457 public void setMinWidth(int minWidth)
459 this.minWidth = minWidth;
460 setWidth(getWidth());
461 setPreferredWidth(getPreferredWidth());
465 * Returns the <code>TableColumn</code>'s minimum width.
467 * @return The minimum width.
469 public int getMinWidth()
471 return minWidth;
475 * Sets the maximum width and, if necessary, updates the <code>width</code>
476 * and <code>preferredWidth</code>.
478 * @param maxWidth the maximum width
480 public void setMaxWidth(int maxWidth)
482 this.maxWidth = maxWidth;
483 setWidth(getWidth());
484 setPreferredWidth(getPreferredWidth());
488 * Returns the maximum width.
490 * @return The maximum width.
492 public int getMaxWidth()
494 return maxWidth;
498 * setResizable
500 * @param isResizable <code>true</code> if this column is resizable,
501 * <code>false</code> otherwise
503 public void setResizable(boolean isResizable)
505 this.isResizable = isResizable;
509 * getResizable
511 * @return <code>true</code> if this column is resizable,
512 * <code>false</code> otherwise
514 public boolean getResizable()
516 return isResizable;
520 * sizeWidthToFit
522 public void sizeWidthToFit()
524 // TODO
528 * This method is empty, unused and deprecated.
529 * @deprecated 1.3
531 public void disableResizedPosting()
533 // Does nothing
537 * This method is empty, unused and deprecated.
538 * @deprecated 1.3
540 public void enableResizedPosting()
542 // Does nothing
546 * Adds a property change listener.
548 * @param listener the listener to add
550 public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
552 changeSupport.addPropertyChangeListener(listener);
556 * removePropertyChangeListener
557 * @param listener the listener to remove
559 public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
561 changeSupport.removePropertyChangeListener(listener);
565 * Returns the property change listeners for this <code>TableColumn</code>.
566 * @since 1.4
568 public PropertyChangeListener[] getPropertyChangeListeners()
570 return changeSupport.getPropertyChangeListeners();
574 * createDefaultHeaderRenderer
575 * @return TableCellRenderer
577 protected TableCellRenderer createDefaultHeaderRenderer()
579 return new DefaultTableCellRenderer();