KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > table > TableColumn


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app.table;
31
32 import java.beans.PropertyChangeListener JavaDoc;
33 import java.beans.PropertyChangeSupport JavaDoc;
34 import java.io.Serializable JavaDoc;
35
36 import nextapp.echo2.app.Extent;
37
38 /**
39  * A description of a single column of a <code>Table</code>.
40  */

41 public class TableColumn
42 implements Serializable JavaDoc {
43
44     public static final String JavaDoc CELL_RENDERER_CHANGED_PROPERTY = "cellRenderer";
45     public static final String JavaDoc HEADER_RENDERER_CHANGED_PROPERTY = "headerRenderer";
46     public static final String JavaDoc HEADER_VALUE_CHANGED_PROPERTY = "headerValue";
47     public static final String JavaDoc IDENTIFIER_CHANGED_PROPERTY = "identifier";
48     public static final String JavaDoc MODEL_INDEX_CHANGED_PROPERTY = "modelIndex";
49     public static final String JavaDoc WIDTH_CHANGED_PROPERTY = "width";
50     
51     private Extent width;
52     private TableCellRenderer cellRenderer;
53     private TableCellRenderer headerRenderer;
54     private Object JavaDoc headerValue;
55     private int modelIndex;
56     private Object JavaDoc identifier;
57     private PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
58     
59     /**
60      * Creates a <code>TableColumn</code> with the specified model index,
61      * undefined width, and undefined cell and header renderers.
62      *
63      * @param modelIndex the column index of model data visualized by this
64      * column
65      */

66     public TableColumn(int modelIndex) {
67         this(modelIndex, null, null, null);
68     }
69     
70     /**
71      * Creates a TableColumn with the specified model index and width,
72      * and undefined cell and header renderers.
73      *
74      * @param modelIndex the column index of model data visualized by this
75      * column
76      * @param width the column width
77      */

78     public TableColumn(int modelIndex, Extent width) {
79         this(modelIndex, width, null, null);
80     }
81
82     /**
83      * Creates a TableColumn with the specified model index, width,
84      * and cell and header renderers.
85      *
86      * @param modelIndex the column index of model data visualized by this
87      * column
88      * @param width the column width
89      * @param cellRenderer the renderer to use for rendering model values
90      * @param headerRenderer the renderer to use for rendering the header cell
91      */

92     public TableColumn(int modelIndex, Extent width, TableCellRenderer cellRenderer, TableCellRenderer headerRenderer) {
93         super();
94         
95         this.modelIndex = modelIndex;
96         this.width = width;
97         setCellRenderer(cellRenderer);
98         setHeaderRenderer(headerRenderer);
99     }
100     
101     /**
102      * Adds a <code>PropertyChangeListener</code> to be notified
103      * of property changes to the column.
104      *
105      * @param l the listener to add
106      */

107     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
108         pcs.addPropertyChangeListener(l);
109     }
110     
111     /**
112      * Retrieves the <code>TableCellRenderer</code> used to render values
113      * contained in the column. The value of this property may be null,
114      * in which case the table should revert to using its default cell
115      * renderer.
116      *
117      * @return the cell renderer for this column
118      */

119     public TableCellRenderer getCellRenderer() {
120         return cellRenderer;
121     }
122     
123     /**
124      * Returns the <code>TableCellRenderer</code> used to render the
125      * header cell of this column. The value of this property may be null,
126      * in which case the table should revert to using its default cell
127      * renderer.
128      *
129      * @return the header cell renderer for this column
130      */

131     public TableCellRenderer getHeaderRenderer() {
132         return headerRenderer;
133     }
134     
135     /**
136      * Returns the header value for this column. The header value is the
137      * object that will be provided to the header renderer to produce
138      * a component that will be used as the table header for this column.
139      *
140      * @return the header value for this column
141      */

142     public Object JavaDoc getHeaderValue() {
143         return headerValue;
144     }
145     
146     /**
147      * Returns the identifier for this column. Each table column may have
148      * an identifier. Identifiers are provided as a convenience to the
149      * application developer, and are neither used nor required by the
150      * <code>Table</code> component.
151      *
152      * @return the identifier for this column
153      */

154     public Object JavaDoc getIdentifier() {
155         return identifier;
156     }
157     
158     /**
159      * Returns the column index of the model which this
160      * <code>TableColumn</code> represents.
161      * This value is independent of the column's position within the column
162      * model, such that columns may be displayed in an arbitrary order.
163      *
164      * @return the index of the column in the model
165      */

166     public int getModelIndex() {
167         return modelIndex;
168     }
169     
170     /**
171      * Returns the width of the column.
172      * This property supports <code>Extent</code>s with
173      * fixed or percentile units.
174      *
175      * @return the width
176      */

177     public Extent getWidth() {
178         return width;
179     }
180     
181     /**
182      * Removes a <code>PropertyChangeListener</code> from being notified
183      * of property changes to the column.
184      *
185      * @param l the listener to remove
186      */

187     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
188         pcs.removePropertyChangeListener(l);
189     }
190     
191     /**
192      * Sets the <code>TableCellRenderer</code> used to render values
193      * contained in the column. The value of this property may be null,
194      * in which case the table should revert to using its default cell
195      * renderer.
196      *
197      * @param newValue the new cell renderer
198      */

199     public void setCellRenderer(TableCellRenderer newValue) {
200         TableCellRenderer oldValue = cellRenderer;
201         cellRenderer = newValue;
202         pcs.firePropertyChange(CELL_RENDERER_CHANGED_PROPERTY, oldValue, newValue);
203     }
204     
205     /**
206      * Sets the <code>TableCellRenderer</code> used to render the
207      * header cell of this column. The value of this property may be null,
208      * in which case the table should revert to using its default cell
209      * renderer.
210      *
211      * @param newValue the new header cell renderer
212      */

213     public void setHeaderRenderer(TableCellRenderer newValue) {
214         TableCellRenderer oldValue = headerRenderer;
215         headerRenderer = newValue;
216         pcs.firePropertyChange(HEADER_RENDERER_CHANGED_PROPERTY, oldValue, newValue);
217     }
218     
219     /**
220      * Sets the header value for this column. The header value is the
221      * object that will be provided to the header renderer to produce
222      * a component that will be used as the table header for this column.
223      *
224      * @param newValue the new header value
225      */

226     public void setHeaderValue(Object JavaDoc newValue) {
227         Object JavaDoc oldValue = headerValue;
228         headerValue = newValue;
229         pcs.firePropertyChange(HEADER_VALUE_CHANGED_PROPERTY, oldValue, newValue);
230     }
231     
232     /**
233      * Sets the identifier for this column. Each table column may have
234      * an identifier. Identifiers are provided as a convenience to the
235      * application developer, and are neither used nor required by the
236      * Table component.
237      *
238      * @param newValue The new identifier for this column.
239      */

240     public void setIdentifier(Object JavaDoc newValue) {
241         Object JavaDoc oldValue = identifier;
242         identifier = newValue;
243         pcs.firePropertyChange(IDENTIFIER_CHANGED_PROPERTY, oldValue, newValue);
244     }
245     
246     /**
247      * Sets the index of the column in the <code>TableModel</code> which
248      * this <code>TableColumn</code> object represents. This value is
249      * independent of the column's position within the column model, such that
250      * columns may be displayed in an arbitrary order.
251      *
252      * @param newValue the index of the column in the model
253      */

254     public void setModelIndex(int newValue) {
255         int oldValue = modelIndex;
256         modelIndex = newValue;
257         pcs.firePropertyChange(MODEL_INDEX_CHANGED_PROPERTY, oldValue, newValue);
258     }
259     
260     /**
261      * Sets the width of the column.
262      * This property supports <code>Extent</code>s with
263      * fixed or percentile units.
264      *
265      * @param newValue the new width
266      */

267     public void setWidth(Extent newValue) {
268         Extent oldValue = width;
269         width = newValue;
270         pcs.firePropertyChange(WIDTH_CHANGED_PROPERTY, oldValue, newValue);
271     }
272 }
273
Popular Tags