TableModelEvent.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* TableModelEvent.java --
  2. Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.swing.event;
  32. import java.util.EventObject;
  33. import javax.swing.table.TableModel;
  34. /**
  35. * An event that describes changes to a {@link TableModel}.
  36. *
  37. * @see javax.swing.event.TableModelListener
  38. *
  39. * @author Andrew Selkirk
  40. */
  41. public class TableModelEvent extends EventObject
  42. {
  43. private static final long serialVersionUID = -7849342674552212824L;
  44. /** A column index representing all columns. */
  45. public static final int ALL_COLUMNS = -1;
  46. /**
  47. * An event type indicating that one or more rows have been deleted from the
  48. * model.
  49. */
  50. public static final int DELETE = -1;
  51. /** A row index representing the header row. */
  52. public static final int HEADER_ROW = -1;
  53. /**
  54. * An event type indicating that one or more rows have been inserted into the
  55. * model.
  56. */
  57. public static final int INSERT = 1;
  58. /** An event type indicating that data has been updated in the model. */
  59. public static final int UPDATE = 0;
  60. /** The column in the table model that the event relates to. */
  61. protected int column = 0;
  62. /** The first row in the table model that the event relates to. */
  63. protected int firstRow = 0;
  64. /** The last row in the table model that the event relates to. */
  65. protected int lastRow = 0;
  66. /**
  67. * The event type (one of {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}).
  68. */
  69. protected int type = 0;
  70. /**
  71. * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
  72. * to the data in all columns and rows.
  73. *
  74. * @param source the source object (<code>null</code> not permitted).
  75. *
  76. * @throws IllegalArgumentException if <code>source</code> is
  77. * <code>null</code>.
  78. */
  79. public TableModelEvent(TableModel source)
  80. {
  81. this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
  82. }
  83. /**
  84. * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
  85. * to the data in a single row across all columns.
  86. *
  87. * @param source the source object (<code>null</code> not permitted).
  88. * @param row the updated row.
  89. *
  90. * @throws IllegalArgumentException if <code>source</code> is
  91. * <code>null</code>.
  92. */
  93. public TableModelEvent(TableModel source, int row)
  94. {
  95. this(source, row, row, ALL_COLUMNS, UPDATE);
  96. }
  97. /**
  98. * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
  99. * to the data in the specified rows across all columns.
  100. *
  101. * @param source the source object (<code>null</code> not permitted).
  102. * @param firstRow the first row of update.
  103. * @param lastRow the last row of update.
  104. *
  105. * @throws IllegalArgumentException if <code>source</code> is
  106. * <code>null</code>.
  107. */
  108. public TableModelEvent(TableModel source, int firstRow, int lastRow)
  109. {
  110. this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
  111. }
  112. /**
  113. * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
  114. * to the data in the specified rows and column. Use {@link #ALL_COLUMNS}
  115. * for the <code>column</code> argument to indicate all columns.
  116. *
  117. * @param source the source object (<code>null</code> not permitted).
  118. * @param firstRow the first row of update.
  119. * @param lastRow the last row of update.
  120. * @param column the affected column.
  121. *
  122. * @throws IllegalArgumentException if <code>source</code> is
  123. * <code>null</code>.
  124. */
  125. public TableModelEvent(TableModel source, int firstRow, int lastRow,
  126. int column)
  127. {
  128. this(source, firstRow, lastRow, column, UPDATE);
  129. }
  130. /**
  131. * Creates a new <code>TableModelEvent</code> indicating an operation of
  132. * the specified <code>type</code> on the data in the specified rows and
  133. * column. The event type is usually one of {@link #UPDATE}, {@link #INSERT},
  134. * and {@link #DELETE}.
  135. *
  136. * @param source the source object (<code>null</code> not permitted).
  137. * @param firstRow the first row of update.
  138. * @param lastRow the last row of update.
  139. * @param column the affected column.
  140. * @param type the type of change.
  141. *
  142. * @throws IllegalArgumentException if <code>source</code> is
  143. * <code>null</code>.
  144. */
  145. public TableModelEvent(TableModel source, int firstRow, int lastRow,
  146. int column, int type)
  147. {
  148. super(source);
  149. this.firstRow = firstRow;
  150. this.lastRow = lastRow;
  151. this.column = column;
  152. this.type = type;
  153. }
  154. /**
  155. * Returns the affected column of this event.
  156. *
  157. * @return The column index.
  158. */
  159. public int getColumn()
  160. {
  161. return column;
  162. }
  163. /**
  164. * Returns the first affected row of this event.
  165. *
  166. * @return The row index.
  167. */
  168. public int getFirstRow()
  169. {
  170. return firstRow;
  171. }
  172. /**
  173. * Returns the last affected row of this event.
  174. *
  175. * @return The row index.
  176. */
  177. public int getLastRow()
  178. {
  179. return lastRow;
  180. }
  181. /**
  182. * Returns the type of change indicated by this event (usually one of
  183. * {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}).
  184. *
  185. * @return The type.
  186. */
  187. public int getType()
  188. {
  189. return type;
  190. }
  191. }