jdk/src/share/classes/javax/swing/event/TableModelEvent.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2001 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * TableModelEvent is used to notify listeners that a table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * has changed. The model event describes changes to a TableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * and all references to rows and columns are in the co-ordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * system of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Depending on the parameters used in the constructors, the TableModelevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * can be used to specify the following types of changes: <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * TableModelEvent(source);              //  The data, ie. all rows changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * TableModelEvent(source, HEADER_ROW);  //  Structure change, reallocate TableColumns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * TableModelEvent(source, 1);           //  Row 1 changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * TableModelEvent(source, 3, 6);        //  Rows 3 to 6 inclusive changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * TableModelEvent(source, 2, 2, 6);     //  Cell at (2, 6) changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * It is possible to use other combinations of the parameters, not all of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * are meaningful. By subclassing, you can add other information, for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * whether the event WILL happen or DID happen. This makes the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of rows in DELETE events more useful but has not been included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the swing package as the JTable only needs post-event notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Alan Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see TableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class TableModelEvent extends java.util.EventObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /** Identifies the addtion of new rows or columns. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final int INSERT =  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /** Identifies a change to existing data. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final int UPDATE =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /** Identifies the removal of rows or columns. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int DELETE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /** Identifies the header row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int HEADER_ROW = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /** Specifies all columns in a row or rows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int ALL_COLUMNS = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
//  Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected int       type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected int       firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected int       lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected int       column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *  All row data in the table has changed, listeners should discard any state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *  that was based on the rows and requery the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *  to get the new row count and all the appropriate values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *  The <code>JTable</code> will repaint the entire visible region on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *  receiving this event, querying the model for the cell values that are visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *  The structure of the table ie, the column names, types and order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *  have not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public TableModelEvent(TableModel source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Use Integer.MAX_VALUE instead of getRowCount() in case rows were deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *  This row of data has been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *  To denote the arrival of a completely new table with a different structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *  use <code>HEADER_ROW</code> as the value for the <code>row</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *  When the <code>JTable</code> receives this event and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *  <code>autoCreateColumnsFromModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *  flag is set it discards any TableColumns that it had and reallocates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *  default ones in the order they appear in the model. This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *  same as calling <code>setModel(TableModel)</code> on the <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public TableModelEvent(TableModel source, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this(source, row, row, ALL_COLUMNS, UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *  The data in rows [<I>firstRow</I>, <I>lastRow</I>] have been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public TableModelEvent(TableModel source, int firstRow, int lastRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *  The cells in column <I>column</I> in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  [<I>firstRow</I>, <I>lastRow</I>] have been updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public TableModelEvent(TableModel source, int firstRow, int lastRow, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this(source, firstRow, lastRow, column, UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *  The cells from (firstRow, column) to (lastRow, column) have been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *  The <I>column</I> refers to the column index of the cell in the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *  co-ordinate system. When <I>column</I> is ALL_COLUMNS, all cells in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *  specified range of rows are considered changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *  The <I>type</I> should be one of: INSERT, UPDATE and DELETE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public TableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.firstRow = firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.lastRow = lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        this.type = type;
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
// Querying Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
   /** Returns the first row that changed.  HEADER_ROW means the meta data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * ie. names, types and order of the columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public int getFirstRow() { return firstRow; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /** Returns the last row that changed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public int getLastRow() { return lastRow; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *  Returns the column for the event.  If the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *  value is ALL_COLUMNS; it means every column in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *  rows changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int getColumn() { return column; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *  Returns the type of event - one of: INSERT, UPDATE and DELETE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public int getType() { return type; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}