Source for javax.swing.event.TableModelEvent

   1: /* TableModelEvent.java --
   2:    Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.event;
  40: 
  41: import java.util.EventObject;
  42: 
  43: import javax.swing.table.TableModel;
  44: 
  45: /**
  46:  * An event that describes changes to a {@link TableModel}.
  47:  * 
  48:  * @see javax.swing.event.TableModelListener
  49:  * 
  50:  * @author Andrew Selkirk
  51:  */
  52: public class TableModelEvent extends EventObject
  53: {
  54:   private static final long serialVersionUID = -7849342674552212824L;
  55:   
  56:   /** A column index representing all columns. */
  57:   public static final int ALL_COLUMNS = -1;
  58:   
  59:   /** 
  60:    * An event type indicating that one or more rows have been deleted from the 
  61:    * model. 
  62:    */
  63:   public static final int DELETE = -1;
  64:   
  65:   /** A row index representing the header row. */
  66:   public static final int HEADER_ROW = -1;
  67:   
  68:   /** 
  69:    * An event type indicating that one or more rows have been inserted into the 
  70:    * model. 
  71:    */
  72:   public static final int INSERT = 1;
  73:   
  74:   /** An event type indicating that data has been updated in the model. */
  75:   public static final int UPDATE = 0;
  76: 
  77:   /** The column in the table model that the event relates to. */
  78:   protected int column = 0;
  79:   
  80:   /** The first row in the table model that the event relates to. */
  81:   protected int firstRow = 0;
  82:   
  83:   /** The last row in the table model that the event relates to. */
  84:   protected int lastRow = 0;
  85:   
  86:   /** 
  87:    * The event type (one of {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}). 
  88:    */
  89:   protected int type = 0;
  90: 
  91:   /**
  92:    * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE} 
  93:    * to the data in all columns and rows.
  94:    * 
  95:    * @param source  the source object (<code>null</code> not permitted).
  96:    * 
  97:    * @throws IllegalArgumentException if <code>source</code> is 
  98:    *         <code>null</code>. 
  99:    */
 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: }