jdk/src/java.desktop/share/classes/javax/swing/table/DefaultTableModel.java
author darcy
Fri, 03 Apr 2015 10:41:34 -0700
changeset 29894 3e16b51732f5
parent 26353 b5e3b7fbf56d
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: 26353
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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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 java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.TableModelEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This is an implementation of <code>TableModel</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * uses a <code>Vector</code> of <code>Vectors</code> to store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * cell value objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <strong>Warning:</strong> <code>DefaultTableModel</code> returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * column class of <code>Object</code>.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>DefaultTableModel</code> is used with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>TableRowSorter</code> this will result in extensive use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>toString</code>, which for non-<code>String</code> data types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * is expensive.  If you use <code>DefaultTableModel</code> with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>TableRowSorter</code> you are strongly encouraged to override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>getColumnClass</code> to return the appropriate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * 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: 20428
diff changeset
    53
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see TableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see #getDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
    62
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class DefaultTableModel extends AbstractTableModel implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * The <code>Vector</code> of <code>Vectors</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <code>Object</code> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    73
    @SuppressWarnings("rawtypes")
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    74
    protected Vector<Vector>    dataVector;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /** The <code>Vector</code> of column identifiers. */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    77
    @SuppressWarnings("rawtypes")
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    78
    protected Vector    columnIdentifiers;
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    79
    // Unfortunately, for greater source compatibility the inner-most
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    80
    // Vector in the two fields above is being left raw. The Vector is
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    81
    // read as well as written so using Vector<?> is not suitable and
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    82
    // using Vector<Object> (without adding copying of input Vectors),
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    83
    // would disallow existing code that used, say, a Vector<String>
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
    84
    // as an input parameter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *  Constructs a default <code>DefaultTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *  which is a table of zero columns and zero rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public DefaultTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
    98
    private static <E> Vector<E> newVector(int size) {
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
    99
        Vector<E> v = new Vector<>(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        v.setSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *  Constructs a <code>DefaultTableModel</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *  <code>rowCount</code> and <code>columnCount</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *  <code>null</code> object values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param rowCount           the number of rows the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param columnCount        the number of columns the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public DefaultTableModel(int rowCount, int columnCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this(newVector(columnCount), rowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *  Constructs a <code>DefaultTableModel</code> with as many columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *  as there are elements in <code>columnNames</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  and <code>rowCount</code> of <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  object values.  Each column's name will be taken from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *  the <code>columnNames</code> vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param columnNames       <code>vector</code> containing the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *                          of the new columns; if this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *                          <code>null</code> then the model has no columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param rowCount           the number of rows the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #setDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   132
    public DefaultTableModel(Vector<?> columnNames, int rowCount) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        setDataVector(newVector(rowCount), columnNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *  Constructs a <code>DefaultTableModel</code> with as many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *  columns as there are elements in <code>columnNames</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *  and <code>rowCount</code> of <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *  object values.  Each column's name will be taken from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *  the <code>columnNames</code> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param columnNames       <code>array</code> containing the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *                          of the new columns; if this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *                          <code>null</code> then the model has no columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param rowCount           the number of rows the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #setDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public DefaultTableModel(Object[] columnNames, int rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this(convertToVector(columnNames), rowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *  Constructs a <code>DefaultTableModel</code> and initializes the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *  by passing <code>data</code> and <code>columnNames</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *  to the <code>setDataVector</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param data              the data of the table, a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *                          of <code>Vector</code>s of <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *                          values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param columnNames       <code>vector</code> containing the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *                          of the new columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #getDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see #setDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   167
    @SuppressWarnings("rawtypes")
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   168
    public DefaultTableModel(Vector<? extends Vector> data, Vector<?> columnNames) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        setDataVector(data, columnNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *  Constructs a <code>DefaultTableModel</code> and initializes the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *  by passing <code>data</code> and <code>columnNames</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *  to the <code>setDataVector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *  method. The first index in the <code>Object[][]</code> array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *  the row index and the second is the column index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param data              the data of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param columnNames       the names of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see #getDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see #setDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public DefaultTableModel(Object[][] data, Object[] columnNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        setDataVector(data, columnNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *  Returns the <code>Vector</code> of <code>Vectors</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *  that contains the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *  data values.  The vectors contained in the outer vector are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *  each a single row of values.  In other words, to get to the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *  at row 1, column 5: <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   195
     *  <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return  the vector of vectors containing the tables data values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #newDataAvailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #newRowsAdded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #setDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   203
    @SuppressWarnings("rawtypes")
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   204
    public Vector<Vector> getDataVector() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return dataVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   208
    private static <E> Vector<E> nonNullVector(Vector<E> v) {
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   209
        return (v != null) ? v : new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *  Replaces the current <code>dataVector</code> instance variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *  with the new <code>Vector</code> of rows, <code>dataVector</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *  Each row is represented in <code>dataVector</code> as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *  <code>Vector</code> of <code>Object</code> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *  <code>columnIdentifiers</code> are the names of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *  columns.  The first name in <code>columnIdentifiers</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *  mapped to column 0 in <code>dataVector</code>. Each row in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *  <code>dataVector</code> is adjusted to match the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *  columns in <code>columnIdentifiers</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *  either by truncating the <code>Vector</code> if it is too long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *  or adding <code>null</code> values if it is too short.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *  <p>Note that passing in a <code>null</code> value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *  <code>dataVector</code> results in unspecified behavior,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *  an possibly an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param   dataVector         the new data vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param   columnIdentifiers     the names of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #getDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   232
    @SuppressWarnings({"rawtypes", "unchecked"})
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   233
    public void setDataVector(Vector<? extends Vector> dataVector,
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   234
                              Vector<?> columnIdentifiers) {
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   235
        this.dataVector = nonNullVector((Vector<Vector>)dataVector);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        this.columnIdentifiers = nonNullVector(columnIdentifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        justifyRows(0, getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        fireTableStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *  Replaces the value in the <code>dataVector</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *  variable with the values in the array <code>dataVector</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *  The first index in the <code>Object[][]</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *  array is the row index and the second is the column index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *  <code>columnIdentifiers</code> are the names of the new columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param dataVector                the new data vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param columnIdentifiers the names of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #setDataVector(Vector, Vector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void setDataVector(Object[][] dataVector, Object[] columnIdentifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        setDataVector(convertToVector(dataVector), convertToVector(columnIdentifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *  Equivalent to <code>fireTableChanged</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param event  the change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void newDataAvailable(TableModelEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        fireTableChanged(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
// Manipulating rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private void justifyRows(int from, int to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // Sometimes the DefaultTableModel is subclassed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // instead of the AbstractTableModel by mistake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        // Set the number of rows for the case when getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // is overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        dataVector.setSize(getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        for (int i = from; i < to; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (dataVector.elementAt(i) == null) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   279
                dataVector.setElementAt(new Vector<>(), i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   281
            dataVector.elementAt(i).setSize(getColumnCount());
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *  Ensures that the new rows have the correct number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *  This is accomplished by  using the <code>setSize</code> method in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *  <code>Vector</code> which truncates vectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *  which are too long, and appends <code>null</code>s if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *  are too short.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *  This method also sends out a <code>tableChanged</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *  notification message to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param e         this <code>TableModelEvent</code> describes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *                           where the rows were added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *                           If <code>null</code> it assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *                           all the rows were newly added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #getDataVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public void newRowsAdded(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        justifyRows(e.getFirstRow(), e.getLastRow() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        fireTableChanged(e);
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
     *  Equivalent to <code>fireTableChanged</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *  @param event the change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void rowsRemoved(TableModelEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        fireTableChanged(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Obsolete as of Java 2 platform v1.3.  Please use <code>setRowCount</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param   rowCount   the new number of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void setNumRows(int rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int old = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (old == rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        dataVector.setSize(rowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (rowCount <= old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            fireTableRowsDeleted(rowCount, old-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            justifyRows(old, rowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            fireTableRowsInserted(old, rowCount-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *  Sets the number of rows in the model.  If the new size is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *  than the current size, new rows are added to the end of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *  If the new size is less than the current size, all
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   338
     *  rows at index <code>rowCount</code> and greater are discarded.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *  @see #setColumnCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @since 1.3
25172
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   342
     *
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   343
     * @param rowCount  number of rows in the model
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public void setRowCount(int rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        setNumRows(rowCount);
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
     *  Adds a row to the end of the model.  The new row will contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *  <code>null</code> values unless <code>rowData</code> is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *  Notification of the row being added will be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param   rowData          optional data of the row being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   356
    public void addRow(Vector<?> rowData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        insertRow(getRowCount(), rowData);
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
     *  Adds a row to the end of the model.  The new row will contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  <code>null</code> values unless <code>rowData</code> is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *  Notification of the row being added will be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param   rowData          optional data of the row being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public void addRow(Object[] rowData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        addRow(convertToVector(rowData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *  Inserts a row at <code>row</code> in the model.  The new row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *  will contain <code>null</code> values unless <code>rowData</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *  is specified.  Notification of the row being added will be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @param   row             the row index of the row to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @param   rowData         optional data of the row being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   380
    public void insertRow(int row, Vector<?> rowData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        dataVector.insertElementAt(rowData, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        justifyRows(row, row+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        fireTableRowsInserted(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *  Inserts a row at <code>row</code> in the model.  The new row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *  will contain <code>null</code> values unless <code>rowData</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *  is specified.  Notification of the row being added will be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param   row      the row index of the row to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param   rowData          optional data of the row being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public void insertRow(int row, Object[] rowData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        insertRow(row, convertToVector(rowData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    private static int gcd(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return (j == 0) ? i : gcd(j, i%j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   403
    private static <E> void rotate(Vector<E> v, int a, int b, int shift) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        int size = b - a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        int r = size - shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        int g = gcd(size, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        for(int i = 0; i < g; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            int to = i;
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   409
            E tmp = v.elementAt(a + to);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            for(int from = (to + r) % size; from != i; from = (to + r) % size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                v.setElementAt(v.elementAt(a + from), a + to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                to = from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            v.setElementAt(tmp, a + to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *  Moves one or more rows from the inclusive range <code>start</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *  <code>end</code> to the <code>to</code> position in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *  After the move, the row that was at index <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *  will be at index <code>to</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *  This method will send a <code>tableChanged</code> notification
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   424
       message to all the listeners.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *  Examples of moves:
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 5506
diff changeset
   428
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *  1. moveRow(1,3,5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *          a|B|C|D|e|f|g|h|i|j|k   - before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *          a|e|f|g|h|B|C|D|i|j|k   - after
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 5506
diff changeset
   432
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *  2. moveRow(6,7,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          a|b|c|d|e|f|G|H|i|j|k   - before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *          a|G|H|b|c|d|e|f|i|j|k   - after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param   start       the starting row index to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param   end         the ending row index to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @param   to          the destination of the rows to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @exception  ArrayIndexOutOfBoundsException  if any of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * would be moved out of the table's range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public void moveRow(int start, int end, int to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        int shift = to - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        int first, last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (shift < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            first = to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            last = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            first = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            last = to + end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        rotate(dataVector, first, last + 1, shift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        fireTableRowsUpdated(first, last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *  Removes the row at <code>row</code> from the model.  Notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *  of the row being removed will be sent to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @param   row      the row index of the row to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @exception  ArrayIndexOutOfBoundsException  if the row was invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public void removeRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        dataVector.removeElementAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        fireTableRowsDeleted(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
// Manipulating columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Replaces the column identifiers in the model.  If the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <code>newIdentifier</code>s is greater than the current number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * of columns, new columns are added to the end of each row in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * If the number of <code>newIdentifier</code>s is less than the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * number of columns, all the extra columns at the end of a row are
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   483
     * discarded.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @param   columnIdentifiers  vector of column identifiers.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *                          <code>null</code>, set the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *                          to zero columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @see #setNumRows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   490
    public void setColumnIdentifiers(Vector<?> columnIdentifiers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        setDataVector(dataVector, columnIdentifiers);
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
     * Replaces the column identifiers in the model.  If the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <code>newIdentifier</code>s is greater than the current number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * of columns, new columns are added to the end of each row in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * If the number of <code>newIdentifier</code>s is less than the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * number of columns, all the extra columns at the end of a row are
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   500
     * discarded.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param   newIdentifiers  array of column identifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *                          If <code>null</code>, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *                          the model to zero columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see #setNumRows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public void setColumnIdentifiers(Object[] newIdentifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        setColumnIdentifiers(convertToVector(newIdentifiers));
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
     *  Sets the number of columns in the model.  If the new size is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *  than the current size, new columns are added to the end of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *  with <code>null</code> cell values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *  If the new size is less than the current size, all columns at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *  <code>columnCount</code> and greater are discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *  @param columnCount  the new number of columns in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *  @see #setColumnCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public void setColumnCount(int columnCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        columnIdentifiers.setSize(columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        justifyRows(0, getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        fireTableStructureChanged();
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
     *  Adds a column to the model.  The new column will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *  identifier <code>columnName</code>, which may be null.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *  will send a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *  <code>tableChanged</code> notification message to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *  This method is a cover for <code>addColumn(Object, Vector)</code> which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *  uses <code>null</code> as the data vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @param   columnName the identifier of the column being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public void addColumn(Object columnName) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   540
        addColumn(columnName, (Vector<Object>)null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *  Adds a column to the model.  The new column will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *  identifier <code>columnName</code>, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *  <code>columnData</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *  optional vector of data for the column.  If it is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *  the column is filled with <code>null</code> values.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *  the new data will be added to model starting with the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *  element going to row 0, etc.  This method will send a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *  <code>tableChanged</code> notification message to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param   columnName the identifier of the column being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @param   columnData       optional data of the column being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   556
    @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   557
    public void addColumn(Object columnName, Vector<?> columnData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        columnIdentifiers.addElement(columnName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (columnData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            int columnSize = columnData.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (columnSize > getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                dataVector.setSize(columnSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            justifyRows(0, getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            int newColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            for(int i = 0; i < columnSize; i++) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   567
                  Vector<Object> row = dataVector.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                  row.setElementAt(columnData.elementAt(i), newColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            justifyRows(0, getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        fireTableStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *  Adds a column to the model.  The new column will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *  identifier <code>columnName</code>.  <code>columnData</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *  optional array of data for the column.  If it is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *  the column is filled with <code>null</code> values.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *  the new data will be added to model starting with the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *  element going to row 0, etc.  This method will send a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *  <code>tableChanged</code> notification message to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *
25172
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   587
     * @param columnName  identifier of the newly created column
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   588
     * @param columnData  new data to be added to the column
b345c47c02b3 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table
yan
parents: 22574
diff changeset
   589
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @see #addColumn(Object, Vector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public void addColumn(Object columnName, Object[] columnData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        addColumn(columnName, convertToVector(columnData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
// Implementing the TableModel interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns the number of rows in this data table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @return the number of rows in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return dataVector.size();
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 number of columns in this data table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @return the number of columns in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return columnIdentifiers.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Returns the column name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @return a name for this column using the string value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * appropriate member in <code>columnIdentifiers</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * If <code>columnIdentifiers</code> does not have an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * for this index, returns the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * name provided by the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        Object id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // This test is to cover the case when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        // getColumnCount has been subclassed by mistake ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (column < columnIdentifiers.size() && (column >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            id = columnIdentifiers.elementAt(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return (id == null) ? super.getColumnName(column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                            : id.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Returns true regardless of parameter values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @param   row             the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param   column          the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @return                  true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public boolean isCellEditable(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Returns an attribute value for the cell at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param   row             the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param   column          the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return                  the value Object at the specified cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *               column was given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public Object getValueAt(int row, int column) {
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   659
        @SuppressWarnings("unchecked")
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   660
        Vector<Object> rowVector = dataVector.elementAt(row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return rowVector.elementAt(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Sets the object value for the cell at <code>column</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * <code>row</code>.  <code>aValue</code> is the new value.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * will generate a <code>tableChanged</code> notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @param   aValue          the new value; this can be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @param   row             the row whose value is to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @param   column          the column whose value is to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *               column was given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public void setValueAt(Object aValue, int row, int column) {
26351
4050cc242edf 8054360: Refine generification of javax.swing
darcy
parents: 25568
diff changeset
   676
        @SuppressWarnings("unchecked")
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   677
        Vector<Object> rowVector = dataVector.elementAt(row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        rowVector.setElementAt(aValue, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        fireTableCellUpdated(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Returns a vector that contains the same objects as the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @param anArray  the array to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @return  the new vector; if <code>anArray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *                          returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   692
    protected static Vector<Object> convertToVector(Object[] anArray) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        if (anArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   696
        Vector<Object> v = new Vector<>(anArray.length);
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   697
        for (Object o : anArray) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   698
            v.addElement(o);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Returns a vector of vectors that contains the same objects as the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param anArray  the double array to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @return the new vector of vectors; if <code>anArray</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *                          <code>null</code>, returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   709
    protected static Vector<Vector<Object>> convertToVector(Object[][] anArray) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (anArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25172
diff changeset
   713
        Vector<Vector<Object>> v = new Vector<>(anArray.length);
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   714
        for (Object[] o : anArray) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   715
            v.addElement(convertToVector(o));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
} // End of class DefaultTableModel