1. /*
  2. * @(#)ListDataEvent.java 1.18 03/12/19
  3. *
  4. * Copyright 2004 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.18 12/19/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. If index0 is >
  62. * index1, index0 and index1 will be swapped such that
  63. * index0 will always be <= index1.
  64. *
  65. * @param source the source Object (typically <code>this</code>)
  66. * @param type an int specifying {@link #CONTENTS_CHANGED},
  67. * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}
  68. * @param index0 one end of the new interval
  69. * @param index1 the other end of the new interval
  70. */
  71. public ListDataEvent(Object source, int type, int index0, int index1) {
  72. super(source);
  73. this.type = type;
  74. this.index0 = Math.min(index0, index1);
  75. this.index1 = Math.max(index0, index1);
  76. }
  77. /**
  78. * Returns a string representation of this ListDataEvent. This method
  79. * is intended to be used only for debugging purposes, and the
  80. * content and format of the returned string may vary between
  81. * implementations. The returned string may be empty but may not
  82. * be <code>null</code>.
  83. *
  84. * @since 1.4
  85. * @return a string representation of this ListDataEvent.
  86. */
  87. public String toString() {
  88. return getClass().getName() +
  89. "[type=" + type +
  90. ",index0=" + index0 +
  91. ",index1=" + index1 + "]";
  92. }
  93. }