1. /*
  2. * @(#)ListDataEvent.java 1.16 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.event;
  8. import java.util.EventObject;
  9. /**
  10. * Defines an event that encapsulates changes to a list.
  11. * <p>
  12. * <strong>Warning:</strong>
  13. * Serialized objects of this class will not be compatible with
  14. * future Swing releases. The current serialization support is
  15. * appropriate for short term storage or RMI between applications running
  16. * the same version of Swing. As of 1.4, support for long term storage
  17. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  18. * has been added to the <code>java.beans</code> package.
  19. * Please see {@link java.beans.XMLEncoder}.
  20. *
  21. * @version 1.16 01/23/03
  22. * @author Hans Muller
  23. */
  24. public class ListDataEvent extends EventObject
  25. {
  26. /** Identifies one or more changes in the lists contents. */
  27. public static final int CONTENTS_CHANGED = 0;
  28. /** Identifies the addition of one or more contiguous items to the list */
  29. public static final int INTERVAL_ADDED = 1;
  30. /** Identifies the removal of one or more contiguous items from the list */
  31. public static final int INTERVAL_REMOVED = 2;
  32. private int type;
  33. private int index0;
  34. private int index1;
  35. /**
  36. * Returns the event type. The possible values are:
  37. * <ul>
  38. * <li> {@link #CONTENTS_CHANGED}
  39. * <li> {@link #INTERVAL_ADDED}
  40. * <li> {@link #INTERVAL_REMOVED}
  41. * </ul>
  42. *
  43. * @return an int representing the type value
  44. */
  45. public int getType() { return type; }
  46. /**
  47. * Returns the lower index of the range. For a single
  48. * element, this value is the same as that returned by {@link #getIndex1}.
  49. *
  50. * @return an int representing the lower index value
  51. */
  52. public int getIndex0() { return index0; }
  53. /**
  54. * Returns the upper index of the range. For a single
  55. * element, this value is the same as that returned by {@link #getIndex0}.
  56. *
  57. * @return an int representing the upper index value
  58. */
  59. public int getIndex1() { return index1; }
  60. /**
  61. * Constructs a ListDataEvent object.
  62. *
  63. * @param source the source Object (typically <code>this</code>)
  64. * @param type an int specifying {@link #CONTENTS_CHANGED},
  65. * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}
  66. * @param index0 an int specifying the bottom of a range
  67. * @param index1 an int specifying the top of a range
  68. */
  69. public ListDataEvent(Object source, int type, int index0, int index1) {
  70. super(source);
  71. this.type = type;
  72. this.index0 = index0;
  73. this.index1 = index1;
  74. }
  75. /**
  76. * Returns a string representation of this ListDataEvent. This method
  77. * is intended to be used only for debugging purposes, and the
  78. * content and format of the returned string may vary between
  79. * implementations. The returned string may be empty but may not
  80. * be <code>null</code>.
  81. *
  82. * @since 1.4
  83. * @return a string representation of this ListDataEvent.
  84. */
  85. public String toString() {
  86. return getClass().getName() +
  87. "[type=" + type +
  88. ",index0=" + index0 +
  89. ",index1=" + index1 + "]";
  90. }
  91. }