1. /*
  2. * @(#)ListSelectionModel.java 1.17 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing;
  11. import javax.swing.event.*;
  12. /**
  13. * This interface represents the current state of the
  14. * selection for any of the components that display a
  15. * list of values with stable indices. The selection is
  16. * modeled as a set of intervals, each interval represents
  17. * a contiguous range of selected list elements.
  18. * The methods for modifying the set of selected intervals
  19. * all take a pair of indices, index0 and index1, that represent
  20. * a closed interval, i.e. the interval includes both index0 and
  21. * index1.
  22. *
  23. * @version 1.17 02/02/00
  24. * @author Hans Muller
  25. * @author Philip Milne
  26. * @see DefaultListSelectionModel
  27. */
  28. public interface ListSelectionModel
  29. {
  30. /**
  31. * A value for the selectionMode property: select one list index
  32. * at a time.
  33. *
  34. * @see #setSelectionMode
  35. */
  36. int SINGLE_SELECTION = 0;
  37. /**
  38. * A value for the selectionMode property: select one contiguous
  39. * range of indices at a time.
  40. *
  41. * @see #setSelectionMode
  42. */
  43. int SINGLE_INTERVAL_SELECTION = 1;
  44. /**
  45. * A value for the selectionMode property: select one or more
  46. * contiguous ranges of indices at a time.
  47. *
  48. * @see #setSelectionMode
  49. */
  50. int MULTIPLE_INTERVAL_SELECTION = 2;
  51. /**
  52. * Change the selection to be between index0 and index1 inclusive.
  53. * If this represents a change to the current selection, then
  54. * notify each ListSelectionListener. Note that index0 doesn't have
  55. * to be less than or equal to index1.
  56. *
  57. * @param index0 one end of the interval.
  58. * @param index1 other end of the interval
  59. * @see #addListSelectionListener
  60. */
  61. void setSelectionInterval(int index0, int index1);
  62. /**
  63. * Change the selection to be the set union of the current selection
  64. * and the indices between index0 and index1 inclusive. If this represents
  65. * a change to the current selection, then notify each
  66. * ListSelectionListener. Note that index0 doesn't have to be less
  67. * than or equal to index1.
  68. *
  69. * @param index0 one end of the interval.
  70. * @param index1 other end of the interval
  71. * @see #addListSelectionListener
  72. */
  73. void addSelectionInterval(int index0, int index1);
  74. /**
  75. * Change the selection to be the set difference of the current selection
  76. * and the indices between index0 and index1 inclusive. If this represents
  77. * a change to the current selection, then notify each
  78. * ListSelectionListener. Note that index0 doesn't have to be less
  79. * than or equal to index1.
  80. *
  81. * @param index0 one end of the interval.
  82. * @param index1 other end of the interval
  83. * @see #addListSelectionListener
  84. */
  85. void removeSelectionInterval(int index0, int index1);
  86. /**
  87. * Returns the first selected index or -1 if the selection is empty.
  88. */
  89. int getMinSelectionIndex();
  90. /**
  91. * Returns the last selected index or -1 if the selection is empty.
  92. */
  93. int getMaxSelectionIndex();
  94. /**
  95. * Returns true if the specified index is selected.
  96. */
  97. boolean isSelectedIndex(int index);
  98. /**
  99. * Return the first index argument from the most recent call to
  100. * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
  101. * The most recent index0 is considered the "anchor" and the most recent
  102. * index1 is considered the "lead". Some interfaces display these
  103. * indices specially, e.g. Windows95 displays the lead index with a
  104. * dotted yellow outline.
  105. *
  106. * @see #getLeadSelectionIndex
  107. * @see #setSelectionInterval
  108. * @see #addSelectionInterval
  109. */
  110. int getAnchorSelectionIndex();
  111. /**
  112. * Set the anchor selection index.
  113. *
  114. * @see #getAnchorSelectionIndex
  115. */
  116. void setAnchorSelectionIndex(int index);
  117. /**
  118. * Return the second index argument from the most recent call to
  119. * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
  120. *
  121. * @see #getAnchorSelectionIndex
  122. * @see #setSelectionInterval
  123. * @see #addSelectionInterval
  124. */
  125. int getLeadSelectionIndex();
  126. /**
  127. * Set the lead selection index.
  128. *
  129. * @see #getLeadSelectionIndex
  130. */
  131. void setLeadSelectionIndex(int index);
  132. /**
  133. * Change the selection to the empty set. If this represents
  134. * a change to the current selection then notify each ListSelectionListener.
  135. *
  136. * @see #addListSelectionListener
  137. */
  138. void clearSelection();
  139. /**
  140. * Returns true if no indices are selected.
  141. */
  142. boolean isSelectionEmpty();
  143. /**
  144. * Insert length indices beginning before/after index. This is typically
  145. * called to sync the selection model with a corresponding change
  146. * in the data model.
  147. */
  148. void insertIndexInterval(int index, int length, boolean before);
  149. /**
  150. * Remove the indices in the interval index0,index1 (inclusive) from
  151. * the selection model. This is typically called to sync the selection
  152. * model width a corresponding change in the data model.
  153. */
  154. void removeIndexInterval(int index0, int index1);
  155. /**
  156. * This property is true if upcoming changes to the value
  157. * of the model should be considered a single event. For example
  158. * if the model is being updated in response to a user drag,
  159. * the value of the valueIsAdjusting property will be set to true
  160. * when the drag is initiated and be set to false when
  161. * the drag is finished. This property allows listeners to
  162. * to update only when a change has been finalized, rather
  163. * than always handling all of the intermediate values.
  164. *
  165. * @param valueIsAdjusting The new value of the property.
  166. * @see #getValueIsAdjusting
  167. */
  168. void setValueIsAdjusting(boolean valueIsAdjusting);
  169. /**
  170. * Returns true if the value is undergoing a series of changes.
  171. * @return true if the value is currently adjusting
  172. * @see #setValueIsAdjusting
  173. */
  174. boolean getValueIsAdjusting();
  175. /**
  176. * Set the selection mode. The following selectionMode values are allowed:
  177. * <ul>
  178. * <li> <code>SINGLE_SELECTION</code>
  179. * Only one list index can be selected at a time. In this
  180. * mode the setSelectionInterval and addSelectionInterval
  181. * methods are equivalent, and only the second index
  182. * argument (the "lead index") is used.
  183. * <li> <code>SINGLE_INTERVAL_SELECTION</code>
  184. * One contiguous index interval can be selected at a time.
  185. * In this mode setSelectionInterval and addSelectionInterval
  186. * are equivalent.
  187. * <li> <code>MULTIPLE_INTERVAL_SELECTION</code>
  188. * In this mode, there's no restriction on what can be selected.
  189. * </ul>
  190. *
  191. * @see #getSelectionMode
  192. */
  193. void setSelectionMode(int selectionMode);
  194. /**
  195. * Returns the current selection mode.
  196. * @return The value of the selectionMode property.
  197. * @see #setSelectionMode
  198. */
  199. int getSelectionMode();
  200. /**
  201. * Add a listener to the list that's notified each time a change
  202. * to the selection occurs.
  203. *
  204. * @param l the ListSelectionListener
  205. * @see #removeListSelectionListener
  206. * @see #setSelectionInterval
  207. * @see #addSelectionInterval
  208. * @see #removeSelectionInterval
  209. * @see #clearSelection
  210. * @see #insertIndexInterval
  211. * @see #removeIndexInterval
  212. */
  213. void addListSelectionListener(ListSelectionListener x);
  214. /**
  215. * Remove a listener from the list that's notified each time a
  216. * change to the selection occurs.
  217. *
  218. * @param l the ListSelectionListener
  219. * @see #addListSelectionListener
  220. */
  221. void removeListSelectionListener(ListSelectionListener x);
  222. }