0N/A/*
2362N/A * Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.event;
0N/A
0N/Aimport java.util.EventObject;
0N/Aimport javax.swing.table.*;
0N/A
0N/A/**
0N/A * TableModelEvent is used to notify listeners that a table model
0N/A * has changed. The model event describes changes to a TableModel
0N/A * and all references to rows and columns are in the co-ordinate
0N/A * system of the model.
0N/A * Depending on the parameters used in the constructors, the TableModelevent
0N/A * can be used to specify the following types of changes: <p>
0N/A *
0N/A * <pre>
0N/A * TableModelEvent(source); // The data, ie. all rows changed
0N/A * TableModelEvent(source, HEADER_ROW); // Structure change, reallocate TableColumns
0N/A * TableModelEvent(source, 1); // Row 1 changed
0N/A * TableModelEvent(source, 3, 6); // Rows 3 to 6 inclusive changed
0N/A * TableModelEvent(source, 2, 2, 6); // Cell at (2, 6) changed
0N/A * TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted
0N/A * TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted
0N/A * </pre>
0N/A *
0N/A * It is possible to use other combinations of the parameters, not all of them
0N/A * are meaningful. By subclassing, you can add other information, for example:
0N/A * whether the event WILL happen or DID happen. This makes the specification
0N/A * of rows in DELETE events more useful but has not been included in
0N/A * the swing package as the JTable only needs post-event notification.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Alan Chung
0N/A * @author Philip Milne
0N/A * @see TableModel
0N/A */
0N/Apublic class TableModelEvent extends java.util.EventObject
0N/A{
0N/A /** Identifies the addtion of new rows or columns. */
0N/A public static final int INSERT = 1;
0N/A /** Identifies a change to existing data. */
0N/A public static final int UPDATE = 0;
0N/A /** Identifies the removal of rows or columns. */
0N/A public static final int DELETE = -1;
0N/A
0N/A /** Identifies the header row. */
0N/A public static final int HEADER_ROW = -1;
0N/A
0N/A /** Specifies all columns in a row or rows. */
0N/A public static final int ALL_COLUMNS = -1;
0N/A
0N/A//
0N/A// Instance Variables
0N/A//
0N/A
0N/A protected int type;
0N/A protected int firstRow;
0N/A protected int lastRow;
0N/A protected int column;
0N/A
0N/A//
0N/A// Constructors
0N/A//
0N/A
0N/A /**
0N/A * All row data in the table has changed, listeners should discard any state
0N/A * that was based on the rows and requery the <code>TableModel</code>
0N/A * to get the new row count and all the appropriate values.
0N/A * The <code>JTable</code> will repaint the entire visible region on
0N/A * receiving this event, querying the model for the cell values that are visible.
0N/A * The structure of the table ie, the column names, types and order
0N/A * have not changed.
0N/A */
0N/A public TableModelEvent(TableModel source) {
0N/A // Use Integer.MAX_VALUE instead of getRowCount() in case rows were deleted.
0N/A this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
0N/A }
0N/A
0N/A /**
0N/A * This row of data has been updated.
0N/A * To denote the arrival of a completely new table with a different structure
0N/A * use <code>HEADER_ROW</code> as the value for the <code>row</code>.
0N/A * When the <code>JTable</code> receives this event and its
0N/A * <code>autoCreateColumnsFromModel</code>
0N/A * flag is set it discards any TableColumns that it had and reallocates
0N/A * default ones in the order they appear in the model. This is the
0N/A * same as calling <code>setModel(TableModel)</code> on the <code>JTable</code>.
0N/A */
0N/A public TableModelEvent(TableModel source, int row) {
0N/A this(source, row, row, ALL_COLUMNS, UPDATE);
0N/A }
0N/A
0N/A /**
0N/A * The data in rows [<I>firstRow</I>, <I>lastRow</I>] have been updated.
0N/A */
0N/A public TableModelEvent(TableModel source, int firstRow, int lastRow) {
0N/A this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
0N/A }
0N/A
0N/A /**
0N/A * The cells in column <I>column</I> in the range
0N/A * [<I>firstRow</I>, <I>lastRow</I>] have been updated.
0N/A */
0N/A public TableModelEvent(TableModel source, int firstRow, int lastRow, int column) {
0N/A this(source, firstRow, lastRow, column, UPDATE);
0N/A }
0N/A
0N/A /**
0N/A * The cells from (firstRow, column) to (lastRow, column) have been changed.
0N/A * The <I>column</I> refers to the column index of the cell in the model's
0N/A * co-ordinate system. When <I>column</I> is ALL_COLUMNS, all cells in the
0N/A * specified range of rows are considered changed.
0N/A * <p>
0N/A * The <I>type</I> should be one of: INSERT, UPDATE and DELETE.
0N/A */
0N/A public TableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type) {
0N/A super(source);
0N/A this.firstRow = firstRow;
0N/A this.lastRow = lastRow;
0N/A this.column = column;
0N/A this.type = type;
0N/A }
0N/A
0N/A//
0N/A// Querying Methods
0N/A//
0N/A
0N/A /** Returns the first row that changed. HEADER_ROW means the meta data,
0N/A * ie. names, types and order of the columns.
0N/A */
0N/A public int getFirstRow() { return firstRow; };
0N/A
0N/A /** Returns the last row that changed. */
0N/A public int getLastRow() { return lastRow; };
0N/A
0N/A /**
0N/A * Returns the column for the event. If the return
0N/A * value is ALL_COLUMNS; it means every column in the specified
0N/A * rows changed.
0N/A */
0N/A public int getColumn() { return column; };
0N/A
0N/A /**
0N/A * Returns the type of event - one of: INSERT, UPDATE and DELETE.
0N/A */
0N/A public int getType() { return type; }
0N/A}