jdk/src/share/classes/javax/swing/table/TableColumn.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.SwingPropertyChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  A <code>TableColumn</code> represents all the attributes of a column in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  <code>JTable</code>, such as width, resizibility, minimum and maximum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  In addition, the <code>TableColumn</code> provides slots for a renderer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  an editor that can be used to display and edit the values in this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  It is also possible to specify renderers and editors on a per type basis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  rather than a per column basis - see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  <code>setDefaultRenderer</code> method in the <code>JTable</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *  This default mechanism is only used when the renderer (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *  editor) in the <code>TableColumn</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *  The <code>TableColumn</code> stores the link between the columns in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *  <code>JTable</code> and the columns in the <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *  The <code>modelIndex</code> is the column in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *  <code>TableModel</code>, which will be queried for the data values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *  cells in this column. As the column moves around in the view this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *  <code>modelIndex</code> does not change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <b>Note:</b> Some implementations may assume that all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *    <code>TableColumnModel</code>s are unique, therefore we would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *    recommend that the same <code>TableColumn</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *    not be added more than once to a <code>TableColumnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *    To show <code>TableColumn</code>s with the same column of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *    data from the model, create a new instance with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    <code>modelIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @author Alan Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see javax.swing.table.DefaultTableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see javax.swing.table.JTableHeader#getDefaultRenderer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see JTable#getDefaultRenderer(Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see JTable#getDefaultEditor(Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see JTable#getCellRenderer(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see JTable#getCellEditor(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class TableColumn extends Object implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Obsolete as of Java 2 platform v1.3.  Please use string literals to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Warning: The value of this constant, "columWidth" is wrong as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * name of the property is "columnWidth".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public final static String COLUMN_WIDTH_PROPERTY = "columWidth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Obsolete as of Java 2 platform v1.3.  Please use string literals to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public final static String HEADER_VALUE_PROPERTY = "headerValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Obsolete as of Java 2 platform v1.3.  Please use string literals to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public final static String HEADER_RENDERER_PROPERTY = "headerRenderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Obsolete as of Java 2 platform v1.3.  Please use string literals to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public final static String CELL_RENDERER_PROPERTY = "cellRenderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
//  Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      * The index of the column in the model which is to be displayed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      * this <code>TableColumn</code>. As columns are moved around in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      * view <code>modelIndex</code> remains constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected int       modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *  This object is not used internally by the drawing machinery of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *  the <code>JTable</code>; identifiers may be set in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *  <code>TableColumn</code> as as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *  optional way to tag and locate table columns. The table package does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *  not modify or invoke any methods in these identifier objects other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *  than the <code>equals</code> method which is used in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  <code>getColumnIndex()</code> method in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *  <code>DefaultTableColumnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected Object    identifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /** The width of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected int       width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /** The minimum width of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected int       minWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /** The preferred width of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private int         preferredWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /** The maximum width of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    protected int       maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /** The renderer used to draw the header of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected TableCellRenderer headerRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /** The header value of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected Object            headerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /** The renderer used to draw the data cells of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    protected TableCellRenderer cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /** The editor used to edit the data cells of the column. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected TableCellEditor   cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /** If true, the user is allowed to resize the column; the default is true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    protected boolean   isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * This field was not used in previous releases and there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * currently no plans to support it in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @deprecated as of Java 2 platform v1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *  Counter used to disable posting of resizing notifications until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *  end of the resize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    transient protected int     resizedPostingDisableCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * If any <code>PropertyChangeListeners</code> have been registered, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>changeSupport</code> field describes them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private SwingPropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *  Cover method, using a default model index of 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *  default width of 75, a <code>null</code> renderer and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *  <code>null</code> editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *  This method is intended for serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *  @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public TableColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *  Cover method, using a default width of 75, a <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *  renderer and a <code>null</code> editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *  @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public TableColumn(int modelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this(modelIndex, 75, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *  Cover method, using a <code>null</code> renderer and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *  <code>null</code> editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *  @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public TableColumn(int modelIndex, int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this(modelIndex, width, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *  Creates and initializes an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *  <code>TableColumn</code> with the specified model index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *  width, cell renderer, and cell editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *  all <code>TableColumn</code> constructors delegate to this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *  The value of <code>width</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *  for both the initial and preferred width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *  if <code>width</code> is negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *  they're set to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *  The minimum width is set to 15 unless the initial width is less,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *  in which case the minimum width is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *  the initial width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *  When the <code>cellRenderer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *  or <code>cellEditor</code> parameter is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *  a default value provided by the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *  <code>getDefaultRenderer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *  or <code>getDefaultEditor</code> method, respectively,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *  is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *  provide defaults based on the type of the data in this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *  This column-centric rendering strategy can be circumvented by overriding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param modelIndex the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *  in the model that supplies the data for this column in the table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *  the model index remains the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *  even when columns are reordered in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param width this column's preferred width and initial width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @param cellRenderer the object used to render values in this column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param cellEditor the object used to edit values in this column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see #getMinWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see JTable#getDefaultRenderer(Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see JTable#getDefaultEditor(Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see JTable#getCellRenderer(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see JTable#getCellEditor(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public TableColumn(int modelIndex, int width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                 TableCellRenderer cellRenderer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                 TableCellEditor cellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        this.modelIndex = modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        preferredWidth = this.width = Math.max(width, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        this.cellRenderer = cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        this.cellEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // Set other instance variables to default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        minWidth = Math.min(15, this.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        maxWidth = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        isResizable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        resizedPostingDisableCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        headerValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
// Modifying and Querying attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private void firePropertyChange(String propertyName, int oldValue, int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (oldValue != newValue) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   284
            firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (oldValue != newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Sets the model index for this column. The model index is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * index of the column in the model that will be displayed by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <code>TableColumn</code>. As the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * is moved around in the view the model index remains constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param  modelIndex  the new modelIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *  description: The model index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void setModelIndex(int modelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        int old = this.modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        this.modelIndex = modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        firePropertyChange("modelIndex", old, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns the model index for this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return the <code>modelIndex</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public int getModelIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Sets the <code>TableColumn</code>'s identifier to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <code>anIdentifier</code>. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Note: identifiers are not used by the <code>JTable</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * they are purely a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * convenience for the external tagging and location of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param      identifier           an identifier for this column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see        #getIdentifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *  description: A unique identifier for this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public void setIdentifier(Object identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        Object old = this.identifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        this.identifier = identifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        firePropertyChange("identifier", old, identifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *  Returns the <code>identifier</code> object for this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *  Note identifiers are not used by <code>JTable</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *  they are purely a convenience for external use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *  If the <code>identifier</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *  <code>getIdentifier()</code> returns <code>getHeaderValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *  as a default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @return  the <code>identifier</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see     #setIdentifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public Object getIdentifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return (identifier != null) ? identifier : getHeaderValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Sets the <code>Object</code> whose string representation will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * used as the value for the <code>headerRenderer</code>.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <code>TableColumn</code> is created, the default <code>headerValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param headerValue  the new headerValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see       #getHeaderValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *  description: The text to be used by the header renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public void setHeaderValue(Object headerValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        Object old = this.headerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        this.headerValue = headerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        firePropertyChange("headerValue", old, headerValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Returns the <code>Object</code> used as the value for the header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @return  the <code>headerValue</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see     #setHeaderValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public Object getHeaderValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return headerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // Renderers and Editors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Sets the <code>TableCellRenderer</code> used to draw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <code>TableColumn</code>'s header to <code>headerRenderer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * It is the header renderers responsibility to render the sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * indicator.  If you are using sorting and specify a renderer your
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * renderer must render the sorting indication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param headerRenderer  the new headerRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see       #getHeaderRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *  description: The header renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public void setHeaderRenderer(TableCellRenderer headerRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        TableCellRenderer old = this.headerRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        this.headerRenderer = headerRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        firePropertyChange("headerRenderer", old, headerRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Returns the <code>TableCellRenderer</code> used to draw the header of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <code>TableColumn</code>. When the <code>headerRenderer</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <code>null</code>, the <code>JTableHeader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * uses its <code>defaultRenderer</code>. The default value for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <code>headerRenderer</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return  the <code>headerRenderer</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see     #setHeaderRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see     #setHeaderValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see     javax.swing.table.JTableHeader#getDefaultRenderer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public TableCellRenderer getHeaderRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return headerRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Sets the <code>TableCellRenderer</code> used by <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * to draw individual values for this column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param cellRenderer  the new cellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see     #getCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *  description: The renderer to use for cell values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public void setCellRenderer(TableCellRenderer cellRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        TableCellRenderer old = this.cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        this.cellRenderer = cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        firePropertyChange("cellRenderer", old, cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Returns the <code>TableCellRenderer</code> used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * <code>JTable</code> to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * values for this column.  The <code>cellRenderer</code> of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * not only controls the visual look for the column, but is also used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * interpret the value object supplied by the <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * When the <code>cellRenderer</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * the <code>JTable</code> uses a default renderer based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * class of the cells in that column. The default value for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * <code>cellRenderer</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @return  the <code>cellRenderer</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see     #setCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see     JTable#setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public TableCellRenderer getCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Sets the editor to used by when a cell in this column is edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param cellEditor  the new cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see     #getCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *  description: The editor to use for cell values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public void setCellEditor(TableCellEditor cellEditor){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        TableCellEditor old = this.cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        this.cellEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        firePropertyChange("cellEditor", old, cellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Returns the <code>TableCellEditor</code> used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <code>JTable</code> to edit values for this column.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <code>cellEditor</code> is <code>null</code>, the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * uses a default editor based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * class of the cells in that column. The default value for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <code>cellEditor</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @return  the <code>cellEditor</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @see     #setCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @see     JTable#setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public TableCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * This method should not be used to set the widths of columns in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <code>JTable</code>, use <code>setPreferredWidth</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Like a layout manager in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * AWT, the <code>JTable</code> adjusts a column's width automatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * whenever the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * table itself changes size, or a column's preferred width is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Setting widths programmatically therefore has no long term effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * This method sets this column's width to <code>width</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * If <code>width</code> exceeds the minimum or maximum width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * it is adjusted to the appropriate limiting value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @param  width  the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see     #getWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see     #setMinWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see     #setMaxWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see     #setPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see     JTable#doLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *  description: The width of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public void setWidth(int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        int old = this.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        this.width = Math.min(Math.max(width, minWidth), maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        firePropertyChange("width", old, this.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the width of the <code>TableColumn</code>. The default width is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * 75.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @return  the <code>width</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see     #setWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Sets this column's preferred width to <code>preferredWidth</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * If <code>preferredWidth</code> exceeds the minimum or maximum width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * it is adjusted to the appropriate limiting value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * For details on how the widths of columns in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * (and <code>JTableHeader</code>) are calculated from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <code>preferredWidth</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * see the <code>doLayout</code> method in <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @param  preferredWidth the new preferred width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see     #getPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @see     JTable#doLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *  description: The preferred width of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void setPreferredWidth(int preferredWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        int old = this.preferredWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        firePropertyChange("preferredWidth", old, this.preferredWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Returns the preferred width of the <code>TableColumn</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * The default preferred width is 75.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @return  the <code>preferredWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see     #setPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public int getPreferredWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return preferredWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Sets the <code>TableColumn</code>'s minimum width to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <code>minWidth</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * adjusting the new minimum width if necessary to ensure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * 0 &lt;= <code>minWidth</code> &lt;= <code>maxWidth</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * For example, if the <code>minWidth</code> argument is negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * this method sets the <code>minWidth</code> property to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * If the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * <code>width</code> or <code>preferredWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * is less than the new minimum width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * this method sets that property to the new minimum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param minWidth  the new minimum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see     #getMinWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @see     #setPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @see     #setMaxWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *  description: The minimum width of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    public void setMinWidth(int minWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        int old = this.minWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (width < this.minWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            setWidth(this.minWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (preferredWidth < this.minWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            setPreferredWidth(this.minWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        firePropertyChange("minWidth", old, this.minWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Returns the minimum width for the <code>TableColumn</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <code>TableColumn</code>'s width can't be made less than this either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * by the user or programmatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @return  the <code>minWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see     #setMinWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see     #TableColumn(int, int, TableCellRenderer, TableCellEditor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public int getMinWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        return minWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Sets the <code>TableColumn</code>'s maximum width to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <code>maxWidth</code> or,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * if <code>maxWidth</code> is less than the minimum width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * to the minimum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * If the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <code>width</code> or <code>preferredWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * is more than the new maximum width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * this method sets that property to the new maximum width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @param maxWidth  the new maximum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see     #getMaxWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @see     #setPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see     #setMinWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *  description: The maximum width of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public void setMaxWidth(int maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        int old = this.maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        this.maxWidth = Math.max(minWidth, maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (width > this.maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            setWidth(this.maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if (preferredWidth > this.maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            setPreferredWidth(this.maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        firePropertyChange("maxWidth", old, this.maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Returns the maximum width for the <code>TableColumn</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <code>TableColumn</code>'s width can't be made larger than this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * either by the user or programmatically.  The default maxWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * is Integer.MAX_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @return  the <code>maxWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see     #setMaxWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public int getMaxWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        return maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Sets whether this column can be resized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @param isResizable  if true, resizing is allowed; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @see     #getResizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *  description: Whether or not this column can be resized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public void setResizable(boolean isResizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        boolean old = this.isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        this.isResizable = isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        firePropertyChange("isResizable", old, this.isResizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * Returns true if the user is allowed to resize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <code>TableColumn</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * width, false otherwise. You can change the width programmatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * regardless of this setting.  The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @return  the <code>isResizable</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @see     #setResizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public boolean getResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * Resizes the <code>TableColumn</code> to fit the width of its header cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * This method does nothing if the header renderer is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * (the default case). Otherwise, it sets the minimum, maximum and preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * widths of this column to the widths of the minimum, maximum and preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * sizes of the Component delivered by the header renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * The transient "width" property of this TableColumn is also set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * preferred width. Note this method is not used internally by the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @see     #setPreferredWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public void sizeWidthToFit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        if (headerRenderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        Component c = headerRenderer.getTableCellRendererComponent(null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                                getHeaderValue(), false, false, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        setMinWidth(c.getMinimumSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        setMaxWidth(c.getMaximumSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        setPreferredWidth(c.getPreferredSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        setWidth(getPreferredWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * This field was not used in previous releases and there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * currently no plans to support it in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @deprecated as of Java 2 platform v1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    public void disableResizedPosting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        resizedPostingDisableCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * This field was not used in previous releases and there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * currently no plans to support it in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @deprecated as of Java 2 platform v1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public void enableResizedPosting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        resizedPostingDisableCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
// Property Change Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * A <code>PropertyChangeEvent</code> will get fired in response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * explicit call to <code>setFont</code>, <code>setBackground</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * or <code>setForeground</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * current component.  Note that if the current component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * inheriting its foreground, background, or font from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * container, then no event will be fired in response to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @param listener  the listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public synchronized void addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            changeSupport = new SwingPropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        changeSupport.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Removes a <code>PropertyChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * The <code>PropertyChangeListener</code> to be removed was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @param listener  the listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public synchronized void removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            changeSupport.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Returns an array of all the <code>PropertyChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * to this TableColumn with addPropertyChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @return all of the <code>PropertyChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            return new PropertyChangeListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return changeSupport.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * As of Java 2 platform v1.3, this method is not called by the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * constructor.  Previously this method was used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * <code>TableColumn</code> to create a default header renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * As of Java 2 platform v1.3, the default header renderer is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * <code>JTableHeader</code> now provides its own shared default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * renderer, just as the <code>JTable</code> does for its cell renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @return the default header renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @see javax.swing.table.JTableHeader#createDefaultRenderer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    protected TableCellRenderer createDefaultHeaderRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        DefaultTableCellRenderer label = new DefaultTableCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                         boolean isSelected, boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                if (table != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    JTableHeader header = table.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    if (header != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                        setForeground(header.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                        setBackground(header.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                        setFont(header.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                setText((value == null) ? "" : value.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        label.setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
} // End of class TableColumn