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