001    /* TableModelEvent.java --
002       Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.swing.event;
040    
041    import java.util.EventObject;
042    
043    import javax.swing.table.TableModel;
044    
045    /**
046     * An event that describes changes to a {@link TableModel}.
047     * 
048     * @see javax.swing.event.TableModelListener
049     * 
050     * @author Andrew Selkirk
051     */
052    public class TableModelEvent extends EventObject
053    {
054      private static final long serialVersionUID = -7849342674552212824L;
055      
056      /** A column index representing all columns. */
057      public static final int ALL_COLUMNS = -1;
058      
059      /** 
060       * An event type indicating that one or more rows have been deleted from the 
061       * model. 
062       */
063      public static final int DELETE = -1;
064      
065      /** A row index representing the header row. */
066      public static final int HEADER_ROW = -1;
067      
068      /** 
069       * An event type indicating that one or more rows have been inserted into the 
070       * model. 
071       */
072      public static final int INSERT = 1;
073      
074      /** An event type indicating that data has been updated in the model. */
075      public static final int UPDATE = 0;
076    
077      /** The column in the table model that the event relates to. */
078      protected int column = 0;
079      
080      /** The first row in the table model that the event relates to. */
081      protected int firstRow = 0;
082      
083      /** The last row in the table model that the event relates to. */
084      protected int lastRow = 0;
085      
086      /** 
087       * The event type (one of {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}). 
088       */
089      protected int type = 0;
090    
091      /**
092       * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE} 
093       * to the data in all columns and rows.
094       * 
095       * @param source  the source object (<code>null</code> not permitted).
096       * 
097       * @throws IllegalArgumentException if <code>source</code> is 
098       *         <code>null</code>. 
099       */
100      public TableModelEvent(TableModel source)
101      {
102        this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
103      }
104    
105      /**
106       * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
107       * to the data in a single row across all columns.
108       * 
109       * @param source  the source object (<code>null</code> not permitted).
110       * @param row  the updated row.
111       * 
112       * @throws IllegalArgumentException if <code>source</code> is 
113       *         <code>null</code>.
114       */
115      public TableModelEvent(TableModel source, int row)
116      {
117        this(source, row, row, ALL_COLUMNS, UPDATE);
118      }
119    
120      /**
121       * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
122       * to the data in the specified rows across all columns.
123       * 
124       * @param source  the source object (<code>null</code> not permitted).
125       * @param firstRow  the first row of update.
126       * @param lastRow  the last row of update.
127       * 
128       * @throws IllegalArgumentException if <code>source</code> is 
129       *         <code>null</code>.
130       */
131      public TableModelEvent(TableModel source, int firstRow, int lastRow)
132      {
133        this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
134      }
135    
136      /**
137       * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
138       * to the data in the specified rows and column.  Use {@link #ALL_COLUMNS} 
139       * for the <code>column</code> argument to indicate all columns.
140       * 
141       * @param source  the source object (<code>null</code> not permitted).
142       * @param firstRow  the first row of update.
143       * @param lastRow  the last row of update.
144       * @param column  the affected column.
145       *    
146       * @throws IllegalArgumentException if <code>source</code> is 
147       *         <code>null</code>.
148       */
149      public TableModelEvent(TableModel source, int firstRow, int lastRow, 
150                             int column)
151      {
152        this(source, firstRow, lastRow, column, UPDATE);
153      }
154    
155      /**
156       * Creates a new <code>TableModelEvent</code> indicating an operation of
157       * the specified <code>type</code> on the data in the specified rows and
158       * column.  The event type is usually one of {@link #UPDATE}, {@link #INSERT},
159       * and {@link #DELETE}.
160       * 
161       * @param source  the source object (<code>null</code> not permitted).
162       * @param firstRow  the first row of update.
163       * @param lastRow  the last row of update.
164       * @param column  the affected column.
165       * @param type  the type of change.
166       * 
167       * @throws IllegalArgumentException if <code>source</code> is 
168       *         <code>null</code>.
169       */
170      public TableModelEvent(TableModel source, int firstRow, int lastRow, 
171                             int column, int type)
172      {
173        super(source);
174        this.firstRow = firstRow;
175        this.lastRow = lastRow;
176        this.column = column;
177        this.type = type;
178      }
179    
180      /**
181       * Returns the affected column of this event.
182       * 
183       * @return The column index.
184       */
185      public int getColumn()
186      {
187        return column;
188      }
189    
190      /**
191       * Returns the first affected row of this event.
192       * 
193       * @return The row index.
194       */
195      public int getFirstRow()
196      {
197        return firstRow;
198      }
199    
200      /**
201       * Returns the last affected row of this event.
202       * 
203       * @return The row index.
204       */
205      public int getLastRow()
206      {
207        return lastRow;
208      }
209    
210      /**
211       * Returns the type of change indicated by this event (usually one of 
212       * {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}).
213       * 
214       * @return The type.
215       */
216      public int getType()
217      {
218        return type;
219      }
220    }