1. /*
  2. * @(#)ListSelectionEvent.java 1.20 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. import javax.swing.*;
  10. /**
  11. * An event that characterizes a change in the current
  12. * selection. The change is limited to a row interval.
  13. * ListSelectionListeners will generally query the source of
  14. * the event for the new selected status of each potentially
  15. * changed row.
  16. * <p>
  17. * <strong>Warning:</strong>
  18. * Serialized objects of this class will not be compatible with
  19. * future Swing releases. The current serialization support is
  20. * appropriate for short term storage or RMI between applications running
  21. * the same version of Swing. As of 1.4, support for long term storage
  22. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  23. * has been added to the <code>java.beans</code> package.
  24. * Please see {@link java.beans.XMLEncoder}.
  25. *
  26. * @version 1.20 12/19/03
  27. * @author Hans Muller
  28. * @author Ray Ryan
  29. * @see ListSelectionModel
  30. */
  31. public class ListSelectionEvent extends EventObject
  32. {
  33. private int firstIndex;
  34. private int lastIndex;
  35. private boolean isAdjusting;
  36. /**
  37. * Represents a change in selection status between <code>firstIndex</code>
  38. * and <code>lastIndex</code> inclusive
  39. * (</code>firstIndex</code> is less than or equal to
  40. * <code>lastIndex</code>). At least one of the rows within the range will
  41. * have changed, a good <code>ListSelectionModel</code> implementation will
  42. * keep the range as small as possible.
  43. *
  44. * @param firstIndex the first index that changed
  45. * @param lastIndex the last index that changed, lastIndex >= firstIndex
  46. * @param isAdjusting an indication that this is one of rapid a series of events
  47. */
  48. public ListSelectionEvent(Object source, int firstIndex, int lastIndex,
  49. boolean isAdjusting)
  50. {
  51. super(source);
  52. this.firstIndex = firstIndex;
  53. this.lastIndex = lastIndex;
  54. this.isAdjusting = isAdjusting;
  55. }
  56. /**
  57. * Returns the index of the first row whose selection may have changed.
  58. * @return the first row whose selection value may have changed,
  59. * where zero is the first row
  60. */
  61. public int getFirstIndex() { return firstIndex; }
  62. /**
  63. * Returns the index of the last row whose selection may have changed.
  64. * @return the last row whose selection value may have changed,
  65. * where zero is the first row
  66. */
  67. public int getLastIndex() { return lastIndex; }
  68. /**
  69. * Returns true if this is one of multiple change events.
  70. * @return true if this is one of a rapid series of events
  71. */
  72. public boolean getValueIsAdjusting() { return isAdjusting; }
  73. /**
  74. * Returns a string that displays and identifies this
  75. * object's properties.
  76. *
  77. * @return a String representation of this object
  78. */
  79. public String toString() {
  80. String properties =
  81. " source=" + getSource() +
  82. " firstIndex= " + firstIndex +
  83. " lastIndex= " + lastIndex +
  84. " isAdjusting= " + isAdjusting +
  85. " ";
  86. return getClass().getName() + "[" + properties + "]";
  87. }
  88. }