jdk/src/share/classes/javax/swing/table/AbstractTableModel.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1639 a97859015238
child 20458 f2423fb3fd19
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     2
 * Copyright (c) 1997, 2008, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public abstract class AbstractTableModel implements TableModel, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /** List of listeners */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
// Default Implementation of the Interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *  Returns a default name for the column using spreadsheet conventions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *  A, B, C, ... Z, AA, AB, etc.  If <code>column</code> cannot be found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *  returns an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param column  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return a string containing the default name of <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String result = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        for (; column >= 0; column = column / 26 - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            result = (char)((char)(column%26)+'A') + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Returns a column given its name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Implementation is naive so this should be overridden if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * this method is to be called often. This method is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * in the <code>TableModel</code> interface and is not used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param columnName string containing name of column to be located
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return the column with <code>columnName</code>, or -1 if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public int findColumn(String columnName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (int i = 0; i < getColumnCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (columnName.equals(getColumnName(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *  Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *  @param columnIndex  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *  @return the Object.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public Class<?> getColumnClass(int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return Object.class;
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
     *  Returns false.  This is the default implementation for all cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  @param  rowIndex  the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  @param  columnIndex the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *  @return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public boolean isCellEditable(int rowIndex, int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *  This empty implementation is provided so users don't have to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *  this method if their data model is not editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  @param  aValue   value to assign to cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *  @param  rowIndex   row of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *  @param  columnIndex  column of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
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
//  Managing Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Adds a listener to the list that's notified each time a change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * to the data model occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param   l               the TableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void addTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        listenerList.add(TableModelListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Removes a listener from the list that's notified each time a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * change to the data model occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param   l               the TableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void removeTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        listenerList.remove(TableModelListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns an array of all the table model listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * registered on this model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return all of this model's <code>TableModelListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *         array if no table model listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @see #addTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #removeTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public TableModelListener[] getTableModelListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   179
        return listenerList.getListeners(TableModelListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
//  Fire methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Notifies all listeners that all cell values in the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * rows may have changed. The number of rows may also have changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * and the <code>JTable</code> should redraw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * table from scratch. The structure of the table (as in the order of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * columns) is assumed to be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see javax.swing.JTable#tableChanged(TableModelEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void fireTableDataChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        fireTableChanged(new TableModelEvent(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Notifies all listeners that the table's structure has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * The number of columns in the table, and the names and types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * the new columns may be different from the previous state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * If the <code>JTable</code> receives this event and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <code>autoCreateColumnsFromModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * flag is set it discards any table columns that it had and reallocates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * default columns in the order they appear in the model. This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * same as calling <code>setModel(TableModel)</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public void fireTableStructureChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <code>[firstRow, lastRow]</code>, inclusive, have been inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param  firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param  lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void fireTableRowsInserted(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <code>[firstRow, lastRow]</code>, inclusive, have been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void fireTableRowsUpdated(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Notifies all listeners that rows in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <code>[firstRow, lastRow]</code>, inclusive, have been deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param firstRow  the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param lastRow   the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void fireTableRowsDeleted(int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                             TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Notifies all listeners that the value of the cell at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <code>[row, column]</code> has been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param row  row of cell which has been updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param column  column of cell which has been updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public void fireTableCellUpdated(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        fireTableChanged(new TableModelEvent(this, row, row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Forwards the given notification event to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <code>TableModelListeners</code> that registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * themselves as listeners for this table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param e  the event to be forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see #addTableModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void fireTableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (listeners[i]==TableModelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                ((TableModelListener)listeners[i+1]).tableChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * upon this <code>AbstractTableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * with a class literal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * model <code>m</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * for its table model listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <pre>TableModelListener[] tmls = (TableModelListener[])(m.getListeners(TableModelListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *          <code>java.util.EventListener</code>
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