jdk/src/java.desktop/share/classes/javax/swing/table/AbstractTableModel.java
author darcy
Fri, 03 Apr 2015 10:41:34 -0700
changeset 29894 3e16b51732f5
parent 25859 3317bb8137f4
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: 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 javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  This abstract class provides default implementations for most of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  the methods in the <code>TableModel</code> interface. It takes care of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  the management of listeners and provides some conveniences for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  <code>TableModelEvents</code> and dispatching them to the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  To create a concrete <code>TableModel</code> as a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  <code>AbstractTableModel</code> you need only provide implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  for the following three methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  public int getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  public int getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  public Object getValueAt(int row, int column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  </pre>
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: 5506
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 Alan Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    60
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public abstract class AbstractTableModel implements TableModel, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /** List of listeners */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
// Default Implementation of the Interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *  Returns a default name for the column using spreadsheet conventions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *  A, B, C, ... Z, AA, AB, etc.  If <code>column</code> cannot be found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *  returns an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param column  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return a string containing the default name of <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String result = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (; column >= 0; column = column / 26 - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            result = (char)((char)(column%26)+'A') + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return result;
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
     * Returns a column given its name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Implementation is naive so this should be overridden if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * this method is to be called often. This method is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * in the <code>TableModel</code> interface and is not used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param columnName string containing name of column to be located
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return the column with <code>columnName</code>, or -1 if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public int findColumn(String columnName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        for (int i = 0; i < getColumnCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (columnName.equals(getColumnName(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *  Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *  @param columnIndex  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *  @return the Object.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public Class<?> getColumnClass(int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return Object.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *  Returns false.  This is the default implementation for all cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  @param  rowIndex  the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *  @param  columnIndex the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *  @return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public boolean isCellEditable(int rowIndex, int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return false;
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
     *  This empty implementation is provided so users don't have to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *  this method if their data model is not editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *  @param  aValue   value to assign to cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *  @param  rowIndex   row of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *  @param  columnIndex  column of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
//  Managing Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Adds a listener to the list that's notified each time a change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * to the data model occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param   l               the TableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void addTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        listenerList.add(TableModelListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Removes a listener from the list that's notified each time a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * change to the data model occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param   l               the TableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void removeTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        listenerList.remove(TableModelListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Returns an array of all the table model listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * registered on this model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return all of this model's <code>TableModelListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *         array if no table model listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #addTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #removeTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public TableModelListener[] getTableModelListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   180
        return listenerList.getListeners(TableModelListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
//  Fire methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Notifies all listeners that all cell values in the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * rows may have changed. The number of rows may also have changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * and the <code>JTable</code> should redraw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * table from scratch. The structure of the table (as in the order of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * columns) is assumed to be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see javax.swing.JTable#tableChanged(TableModelEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void fireTableDataChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        fireTableChanged(new TableModelEvent(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Notifies all listeners that the table's structure has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The number of columns in the table, and the names and types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * the new columns may be different from the previous state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * If the <code>JTable</code> receives this event and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>autoCreateColumnsFromModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * flag is set it discards any table columns that it had and reallocates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * default columns in the order they appear in the model. This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * same as calling <code>setModel(TableModel)</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void fireTableStructureChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <code>[firstRow, lastRow]</code>, inclusive, have been inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param  firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param  lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void fireTableRowsInserted(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <code>[firstRow, lastRow]</code>, inclusive, have been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void fireTableRowsUpdated(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <code>[firstRow, lastRow]</code>, inclusive, have been deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public void fireTableRowsDeleted(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
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
     * Notifies all listeners that the value of the cell at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>[row, column]</code> has been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param row  row of cell which has been updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param column  column of cell which has been updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void fireTableCellUpdated(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        fireTableChanged(new TableModelEvent(this, row, row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Forwards the given notification event to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <code>TableModelListeners</code> that registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * themselves as listeners for this table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param e  the event to be forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see #addTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public void fireTableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (listeners[i]==TableModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                ((TableModelListener)listeners[i+1]).tableChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * upon this <code>AbstractTableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * with a class literal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * model <code>m</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * for its table model listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <pre>TableModelListener[] tmls = (TableModelListener[])(m.getListeners(TableModelListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
29894
3e16b51732f5 8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents: 25859
diff changeset
   323
     * @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
   324
     * @param listenerType the type of listeners requested
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see #getTableModelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return listenerList.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
} // End of class AbstractTableModel