jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java
author darcy
Fri, 03 Apr 2015 10:41:34 -0700
changeset 29894 3e16b51732f5
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}} Reviewed-by: alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29894
3e16b51732f5 8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 1843
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: 1843
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: 1843
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
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.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The standard column-handler for a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * 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
    47
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Alan Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
    55
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class DefaultTableColumnModel implements TableColumnModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                        PropertyChangeListener, ListSelectionListener, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /** Array of TableColumn objects in this model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected Vector<TableColumn> tableColumns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /** Model for keeping track of column selections */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected ListSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /** Width margin between each column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected int columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /** List of TableColumnModelListener */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /** Change event (only one needed) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    transient protected ChangeEvent changeEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /** Column selection allowed in this column model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected boolean columnSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /** A local cache of the combined width of all columns */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected int totalColumnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Creates a default table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public DefaultTableColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // Initialize local ivars to default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        tableColumns = new Vector<TableColumn>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        setSelectionModel(createSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        setColumnMargin(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        invalidateWidthCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        setColumnSelectionAllowed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
// Modifying the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *  Appends <code>aColumn</code> to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *  <code>tableColumns</code> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *  This method also posts the <code>columnAdded</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *  event to its listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param   aColumn         the <code>TableColumn</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @exception IllegalArgumentException      if <code>aColumn</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *                          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see     #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void addColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (aColumn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new IllegalArgumentException("Object is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        tableColumns.addElement(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        aColumn.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        invalidateWidthCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // Post columnAdded event notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        fireColumnAdded(new TableColumnModelEvent(this, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                                  getColumnCount() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *  Deletes the <code>column</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *  <code>tableColumns</code> array.  This method will do nothing if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  <code>column</code> is not in the table's columns list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *  <code>tile</code> is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *  to resize both the header and table views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *  This method also posts a <code>columnRemoved</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *  event to its listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param   column          the <code>TableColumn</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see     #addColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void removeColumn(TableColumn column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        int columnIndex = tableColumns.indexOf(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (columnIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // Adjust for the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (selectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                selectionModel.removeIndexInterval(columnIndex,columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            column.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            tableColumns.removeElementAt(columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            invalidateWidthCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            // Post columnAdded event notification.  (JTable and JTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // listens so they can adjust size and redraw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            fireColumnRemoved(new TableColumnModelEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                           columnIndex, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Moves the column and heading at <code>columnIndex</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <code>newIndex</code>.  The old column at <code>columnIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * will now be found at <code>newIndex</code>.  The column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * that used to be at <code>newIndex</code> is shifted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * left or right to make room.  This will not move any columns if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <code>columnIndex</code> equals <code>newIndex</code>.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * also posts a <code>columnMoved</code> event to its listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param   columnIndex                     the index of column to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param   newIndex                        new index to move the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception IllegalArgumentException      if <code>column</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *                                          <code>newIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *                                          are not in the valid range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void moveColumn(int columnIndex, int newIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if ((columnIndex < 0) || (columnIndex >= getColumnCount()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            (newIndex < 0) || (newIndex >= getColumnCount()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new IllegalArgumentException("moveColumn() - Index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        TableColumn aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // If the column has not yet moved far enough to change positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // post the event anyway, the "draggedDistance" property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // tableHeader will say how far the column has been dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // Here we are really trying to get the best out of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // API that could do with some rethinking. We preserve backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // compatibility by slightly bending the meaning of these methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (columnIndex == newIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   194
        aColumn = tableColumns.elementAt(columnIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        tableColumns.removeElementAt(columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        boolean selected = selectionModel.isSelectedIndex(columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        selectionModel.removeIndexInterval(columnIndex,columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        tableColumns.insertElementAt(aColumn, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        selectionModel.insertIndexInterval(newIndex, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            selectionModel.addSelectionInterval(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            selectionModel.removeSelectionInterval(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        fireColumnMoved(new TableColumnModelEvent(this, columnIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                                               newIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Sets the column margin to <code>newMargin</code>.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * also posts a <code>columnMarginChanged</code> event to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param   newMargin               the new margin width, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see     #getColumnMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see     #getTotalColumnWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public void setColumnMargin(int newMargin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (newMargin != columnMargin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            columnMargin = newMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // Post columnMarginChanged event notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            fireColumnMarginChanged();
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
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
// Querying the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Returns the number of columns in the <code>tableColumns</code> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return  the number of columns in the <code>tableColumns</code> array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see     #getColumns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return tableColumns.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns an <code>Enumeration</code> of all the columns in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return an <code>Enumeration</code> of the columns in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public Enumeration<TableColumn> getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return tableColumns.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns the index of the first column in the <code>tableColumns</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * array whose identifier is equal to <code>identifier</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * when compared using <code>equals</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param           identifier              the identifier object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return          the index of the first column in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *                  <code>tableColumns</code> array whose identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *                  is equal to <code>identifier</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @exception       IllegalArgumentException  if <code>identifier</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *                          is <code>null</code>, or if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *                          <code>TableColumn</code> has this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *                          <code>identifier</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see             #getColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public int getColumnIndex(Object identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (identifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            throw new IllegalArgumentException("Identifier is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   272
        Enumeration<TableColumn> enumeration = getColumns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        TableColumn aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        while (enumeration.hasMoreElements()) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   277
            aColumn = enumeration.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            // Compare them this way in case the column's identifier is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (identifier.equals(aColumn.getIdentifier()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        throw new IllegalArgumentException("Identifier not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Returns the <code>TableColumn</code> object for the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * at <code>columnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param   columnIndex     the index of the column desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return  the <code>TableColumn</code> object for the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *                          at <code>columnIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public TableColumn getColumn(int columnIndex) {
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   295
        return tableColumns.elementAt(columnIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Returns the width margin for <code>TableColumn</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * The default <code>columnMargin</code> is 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return  the maximum width for the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @see     #setColumnMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public int getColumnMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns the index of the column that lies at position <code>x</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * or -1 if no column covers this point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * In keeping with Swing's separable model architecture, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * TableColumnModel does not know how the table columns actually appear on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * screen.  The visual presentation of the columns is the responsibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * of the view/controller object using this model (typically JTable).  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * view/controller need not display the columns sequentially from left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * right.  For example, columns could be displayed from right to left to
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   319
     * accommodate a locale preference or some columns might be hidden at the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * request of the user.  Because the model does not know how the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * are laid out on screen, the given <code>xPosition</code> should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * considered to be a coordinate in 2D graphics space.  Instead, it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * be considered to be a width from the start of the first column in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * model.  If the column index for a given X coordinate in 2D space is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * required, <code>JTable.columnAtPoint</code> can be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param  x  the horizontal location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @return  the index of the column or -1 if no column is found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see javax.swing.JTable#columnAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public int getColumnIndexAtX(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        int cc = getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        for(int column = 0; column < cc; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            x = x - getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Returns the total combined width of all columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return the <code>totalColumnWidth</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public int getTotalColumnWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (totalColumnWidth == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            recalcWidthCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return totalColumnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
// Selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *  Sets the selection model for this <code>TableColumnModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  to <code>newModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *  and registers for listener notifications from the new selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *  model.  If <code>newModel</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *  an exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param   newModel        the new selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @exception IllegalArgumentException      if <code>newModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *                                          is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see     #getSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public void setSelectionModel(ListSelectionModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (newModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            throw new IllegalArgumentException("Cannot set a null SelectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        ListSelectionModel oldModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                oldModel.removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            selectionModel= newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            newModel.addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns the <code>ListSelectionModel</code> that is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * maintain column selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @return  the object that provides column selection state.  Or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *          <code>null</code> if row selection is not allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see     #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public ListSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Sets whether column selection is allowed.  The default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @param  flag true if column selection will be allowed, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public void setColumnSelectionAllowed(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        columnSelectionAllowed = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Returns true if column selection is allowed, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * The default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return the <code>columnSelectionAllowed</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public boolean getColumnSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return columnSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Returns an array of selected columns.  If <code>selectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * is <code>null</code>, returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return an array of selected columns or an empty array if nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *                  is selected or the <code>selectionModel</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *                  <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public int[] getSelectedColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (selectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if ((iMin == -1) || (iMax == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            int[] rvTmp = new int[1+ (iMax - iMin)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    rvTmp[n++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            int[] rv = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            System.arraycopy(rvTmp, 0, rv, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return  new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Returns the number of columns selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return the number of columns selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public int getSelectedColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (selectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
// Listener Support Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Adds a listener for table column model events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @param x  a <code>TableColumnModelListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public void addColumnModelListener(TableColumnModelListener x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        listenerList.add(TableColumnModelListener.class, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    // implements javax.swing.table.TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Removes a listener for table column model events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param x  a <code>TableColumnModelListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void removeColumnModelListener(TableColumnModelListener x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        listenerList.remove(TableColumnModelListener.class, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Returns an array of all the column model listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * registered on this model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return all of this default table column model's <code>ColumnModelListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *         array if no column model listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #addColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see #removeColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public TableColumnModelListener[] getColumnModelListeners() {
1843
267cc4de4221 6776095: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   508
        return listenerList.getListeners(TableColumnModelListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
//   Event firing methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * is lazily created using the parameters passed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * the fire method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    protected void fireColumnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (listeners[i]==TableColumnModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                //  e = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                ((TableColumnModelListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    columnAdded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * is lazily created using the parameters passed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * the fire method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    protected void fireColumnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (listeners[i]==TableColumnModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                //  e = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                ((TableColumnModelListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    columnRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * is lazily created using the parameters passed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * the fire method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @param  e the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    protected void fireColumnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (listeners[i]==TableColumnModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                //  e = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                ((TableColumnModelListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    columnMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * is lazily created using the parameters passed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the fire method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param e the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    protected void fireColumnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (listeners[i]==TableColumnModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                //  e = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                ((TableColumnModelListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    columnSelectionChanged(e);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * is lazily created using the parameters passed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * the fire method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    protected void fireColumnMarginChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            if (listeners[i]==TableColumnModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                ((TableColumnModelListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    columnMarginChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * upon this model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * with a class literal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * <code>DefaultTableColumnModel</code> <code>m</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * for its column model listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * <pre>ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
29894
3e16b51732f5 8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents: 25859
diff changeset
   655
     * @param <T> the listener type
3e16b51732f5 8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents: 25859
diff changeset
   656
     * @param listenerType the type of listeners requested
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *          <code><em>Foo</em>Listener</code>s on this model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @see #getColumnModelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        return listenerList.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
// Implementing the PropertyChangeListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    // PENDING(alan)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    // implements java.beans.PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Property Change Listener change method.  Used to track changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * to the column width or preferred column width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param  evt  <code>PropertyChangeEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        String name = evt.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (name == "width" || name == "preferredWidth") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            invalidateWidthCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            // This is a misnomer, we're using this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            // simply to cause a relayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            fireColumnMarginChanged();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
// Implementing ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    // implements javax.swing.event.ListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * A <code>ListSelectionListener</code> that forwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <code>ListSelectionEvents</code> when there is a column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * selection change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param e  the change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        fireColumnSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Creates a new default list selection model.
25172
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   718
     *
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   719
     * @return a newly created default list selection model.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    protected ListSelectionModel createSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        return new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Recalculates the total combined width of all columns.  Updates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <code>totalColumnWidth</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    protected void recalcWidthCache() {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   730
        Enumeration<TableColumn> enumeration = getColumns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        totalColumnWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        while (enumeration.hasMoreElements()) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   733
            totalColumnWidth += enumeration.nextElement().getWidth();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    private void invalidateWidthCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        totalColumnWidth = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
} // End of class DefaultTableColumnModel