5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing.table;
27
28 import sun.swing.table.DefaultTableCellHeaderRenderer;
29
30 import java.util.*;
31 import java.awt.*;
32 import java.awt.event.*;
33
34 import javax.swing.*;
35 import javax.swing.event.*;
36 import javax.swing.plaf.*;
37 import javax.accessibility.*;
38
39 import java.beans.PropertyChangeListener;
40 import java.beans.Transient;
41
42 import java.io.ObjectOutputStream;
43 import java.io.ObjectInputStream;
44 import java.io.IOException;
45
46
47 /**
48 * This is the object which manages the header of the <code>JTable</code>.
49 * <p>
50 * <strong>Warning:</strong>
51 * Serialized objects of this class will not be compatible with
52 * future Swing releases. The current serialization support is
53 * appropriate for short term storage or RMI between applications running
54 * the same version of Swing. As of 1.4, support for long term storage
55 * of all JavaBeans™
56 * has been added to the <code>java.beans</code> package.
57 * Please see {@link java.beans.XMLEncoder}.
58 *
59 * @author Alan Chung
60 * @author Philip Milne
61 * @see javax.swing.JTable
62 */
63 @SuppressWarnings("serial") // Same-version serialization only
64 public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible
65 {
66 /**
150 // this method should be invoked
151
152 if (cm == null)
153 cm = createDefaultColumnModel();
154 setColumnModel(cm);
155
156 // Initialize local ivars
157 initializeLocalVars();
158
159 // Get UI going
160 updateUI();
161 }
162
163 //
164 // Local behavior attributes
165 //
166
167 /**
168 * Sets the table associated with this header.
169 * @param table the new table
170 * @beaninfo
171 * bound: true
172 * description: The table associated with this header.
173 */
174 public void setTable(JTable table) {
175 JTable old = this.table;
176 this.table = table;
177 firePropertyChange("table", old, table);
178 }
179
180 /**
181 * Returns the table associated with this header.
182 * @return the <code>table</code> property
183 */
184 public JTable getTable() {
185 return table;
186 }
187
188 /**
189 * Sets whether the user can drag column headers to reorder columns.
190 *
191 * @param reorderingAllowed true if the table view should allow
192 * reordering; otherwise false
193 * @see #getReorderingAllowed
194 * @beaninfo
195 * bound: true
196 * description: Whether the user can drag column headers to reorder columns.
197 */
198 public void setReorderingAllowed(boolean reorderingAllowed) {
199 boolean old = this.reorderingAllowed;
200 this.reorderingAllowed = reorderingAllowed;
201 firePropertyChange("reorderingAllowed", old, reorderingAllowed);
202 }
203
204 /**
205 * Returns true if the user is allowed to rearrange columns by
206 * dragging their headers, false otherwise. The default is true. You can
207 * rearrange columns programmatically regardless of this setting.
208 *
209 * @return the <code>reorderingAllowed</code> property
210 * @see #setReorderingAllowed
211 */
212 public boolean getReorderingAllowed() {
213 return reorderingAllowed;
214 }
215
216 /**
217 * Sets whether the user can resize columns by dragging between headers.
218 *
219 * @param resizingAllowed true if table view should allow
220 * resizing
221 * @see #getResizingAllowed
222 * @beaninfo
223 * bound: true
224 * description: Whether the user can resize columns by dragging between headers.
225 */
226 public void setResizingAllowed(boolean resizingAllowed) {
227 boolean old = this.resizingAllowed;
228 this.resizingAllowed = resizingAllowed;
229 firePropertyChange("resizingAllowed", old, resizingAllowed);
230 }
231
232 /**
233 * Returns true if the user is allowed to resize columns by dragging
234 * between their headers, false otherwise. The default is true. You can
235 * resize columns programmatically regardless of this setting.
236 *
237 * @return the <code>resizingAllowed</code> property
238 * @see #setResizingAllowed
239 */
240 public boolean getResizingAllowed() {
241 return resizingAllowed;
242 }
243
244 /**
245 * Returns the the dragged column, if and only if, a drag is in
493 * @see UIDefaults#getUI
494 */
495 public String getUIClassID() {
496 return uiClassID;
497 }
498
499
500 //
501 // Managing models
502 //
503
504
505 /**
506 * Sets the column model for this table to <code>newModel</code> and registers
507 * for listener notifications from the new column model.
508 *
509 * @param columnModel the new data source for this table
510 * @exception IllegalArgumentException
511 * if <code>newModel</code> is <code>null</code>
512 * @see #getColumnModel
513 * @beaninfo
514 * bound: true
515 * description: The object governing the way columns appear in the view.
516 */
517 public void setColumnModel(TableColumnModel columnModel) {
518 if (columnModel == null) {
519 throw new IllegalArgumentException("Cannot set a null ColumnModel");
520 }
521 TableColumnModel old = this.columnModel;
522 if (columnModel != old) {
523 if (old != null) {
524 old.removeColumnModelListener(this);
525 }
526 this.columnModel = columnModel;
527 columnModel.addColumnModelListener(this);
528
529 firePropertyChange("columnModel", old, columnModel);
530 resizeAndRepaint();
531 }
532 }
533
534 /**
535 * Returns the <code>TableColumnModel</code> that contains all column information
536 * of this table header.
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javax.swing.table;
26
27 import sun.swing.table.DefaultTableCellHeaderRenderer;
28
29 import java.util.*;
30 import java.awt.*;
31 import java.awt.event.*;
32
33 import javax.swing.*;
34 import javax.swing.event.*;
35 import javax.swing.plaf.*;
36 import javax.accessibility.*;
37
38 import java.beans.BeanProperty;
39 import java.beans.PropertyChangeListener;
40 import java.beans.Transient;
41
42 import java.io.ObjectOutputStream;
43 import java.io.IOException;
44
45 /**
46 * This is the object which manages the header of the <code>JTable</code>.
47 * <p>
48 * <strong>Warning:</strong>
49 * Serialized objects of this class will not be compatible with
50 * future Swing releases. The current serialization support is
51 * appropriate for short term storage or RMI between applications running
52 * the same version of Swing. As of 1.4, support for long term storage
53 * of all JavaBeans™
54 * has been added to the <code>java.beans</code> package.
55 * Please see {@link java.beans.XMLEncoder}.
56 *
57 * @author Alan Chung
58 * @author Philip Milne
59 * @see javax.swing.JTable
60 */
61 @SuppressWarnings("serial") // Same-version serialization only
62 public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible
63 {
64 /**
148 // this method should be invoked
149
150 if (cm == null)
151 cm = createDefaultColumnModel();
152 setColumnModel(cm);
153
154 // Initialize local ivars
155 initializeLocalVars();
156
157 // Get UI going
158 updateUI();
159 }
160
161 //
162 // Local behavior attributes
163 //
164
165 /**
166 * Sets the table associated with this header.
167 * @param table the new table
168 */
169 @BeanProperty(description
170 = "The table associated with this header.")
171 public void setTable(JTable table) {
172 JTable old = this.table;
173 this.table = table;
174 firePropertyChange("table", old, table);
175 }
176
177 /**
178 * Returns the table associated with this header.
179 * @return the <code>table</code> property
180 */
181 public JTable getTable() {
182 return table;
183 }
184
185 /**
186 * Sets whether the user can drag column headers to reorder columns.
187 *
188 * @param reorderingAllowed true if the table view should allow
189 * reordering; otherwise false
190 * @see #getReorderingAllowed
191 */
192 @BeanProperty(description
193 = "Whether the user can drag column headers to reorder columns.")
194 public void setReorderingAllowed(boolean reorderingAllowed) {
195 boolean old = this.reorderingAllowed;
196 this.reorderingAllowed = reorderingAllowed;
197 firePropertyChange("reorderingAllowed", old, reorderingAllowed);
198 }
199
200 /**
201 * Returns true if the user is allowed to rearrange columns by
202 * dragging their headers, false otherwise. The default is true. You can
203 * rearrange columns programmatically regardless of this setting.
204 *
205 * @return the <code>reorderingAllowed</code> property
206 * @see #setReorderingAllowed
207 */
208 public boolean getReorderingAllowed() {
209 return reorderingAllowed;
210 }
211
212 /**
213 * Sets whether the user can resize columns by dragging between headers.
214 *
215 * @param resizingAllowed true if table view should allow
216 * resizing
217 * @see #getResizingAllowed
218 */
219 @BeanProperty(description
220 = "Whether the user can resize columns by dragging between headers.")
221 public void setResizingAllowed(boolean resizingAllowed) {
222 boolean old = this.resizingAllowed;
223 this.resizingAllowed = resizingAllowed;
224 firePropertyChange("resizingAllowed", old, resizingAllowed);
225 }
226
227 /**
228 * Returns true if the user is allowed to resize columns by dragging
229 * between their headers, false otherwise. The default is true. You can
230 * resize columns programmatically regardless of this setting.
231 *
232 * @return the <code>resizingAllowed</code> property
233 * @see #setResizingAllowed
234 */
235 public boolean getResizingAllowed() {
236 return resizingAllowed;
237 }
238
239 /**
240 * Returns the the dragged column, if and only if, a drag is in
488 * @see UIDefaults#getUI
489 */
490 public String getUIClassID() {
491 return uiClassID;
492 }
493
494
495 //
496 // Managing models
497 //
498
499
500 /**
501 * Sets the column model for this table to <code>newModel</code> and registers
502 * for listener notifications from the new column model.
503 *
504 * @param columnModel the new data source for this table
505 * @exception IllegalArgumentException
506 * if <code>newModel</code> is <code>null</code>
507 * @see #getColumnModel
508 */
509 @BeanProperty(description
510 = "The object governing the way columns appear in the view.")
511 public void setColumnModel(TableColumnModel columnModel) {
512 if (columnModel == null) {
513 throw new IllegalArgumentException("Cannot set a null ColumnModel");
514 }
515 TableColumnModel old = this.columnModel;
516 if (columnModel != old) {
517 if (old != null) {
518 old.removeColumnModelListener(this);
519 }
520 this.columnModel = columnModel;
521 columnModel.addColumnModelListener(this);
522
523 firePropertyChange("columnModel", old, columnModel);
524 resizeAndRepaint();
525 }
526 }
527
528 /**
529 * Returns the <code>TableColumnModel</code> that contains all column information
530 * of this table header.
|