1. /*
  2. * @(#)ListSelectionEvent.java 1.14 01/11/29
  3. *
  4. * Copyright 2002 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 appropriate
  20. * for short term storage or RMI between applications running the same
  21. * version of Swing. A future release of Swing will provide support for
  22. * long term persistence.
  23. *
  24. * @version 1.14 11/29/01
  25. * @author Hans Muller
  26. * @author Ray Ryan
  27. * @see ListSelectionModel
  28. */
  29. public class ListSelectionEvent extends EventObject
  30. {
  31. private int firstIndex;
  32. private int lastIndex;
  33. private boolean isAdjusting;
  34. /**
  35. * Represents a change in selection status between firstIndex
  36. * and lastIndex inclusive (firstIndex is less than or equal to
  37. * lastIndex). Atleast one of the rows within the range will
  38. * have changed, a good ListSelectionModel implementation will
  39. * keep the range as small as possible.
  40. *
  41. * @param firstIndex The first index that changed.
  42. * @param lastIndex The last index that changed, lastIndex >= firstIndex.
  43. * @param isAdjusting An indication that this is one of rapid a series of events
  44. */
  45. public ListSelectionEvent(Object source, int firstIndex, int lastIndex,
  46. boolean isAdjusting)
  47. {
  48. super(source);
  49. this.firstIndex = firstIndex;
  50. this.lastIndex = lastIndex;
  51. this.isAdjusting = isAdjusting;
  52. }
  53. /**
  54. * Returns the index of the first row whose selection may have changed.
  55. * @return The first row whose selection value may have changed,
  56. * where zero is the first row
  57. */
  58. public int getFirstIndex() { return firstIndex; }
  59. /**
  60. * Returns the index of the last row whose selection may have changed.
  61. * @return The last row whose selection value may have changed,
  62. * where zero is the first row
  63. */
  64. public int getLastIndex() { return lastIndex; }
  65. /**
  66. * Returns true if this is one of multiple change events.
  67. * @return true if this is one of a rapid series of events
  68. */
  69. public boolean getValueIsAdjusting() { return isAdjusting; }
  70. /**
  71. * Returns a string that displays and identifies this
  72. * object's properties.
  73. *
  74. * @return a String representation of this object
  75. */
  76. public String toString() {
  77. String properties =
  78. " source=" + getSource() +
  79. " firstIndex= " + firstIndex +
  80. " lastIndex= " + lastIndex +
  81. " isAdjusting= " + isAdjusting +
  82. " ";
  83. return getClass().getName() + "[" + properties + "]";
  84. }
  85. }