1. /*
  2. * @(#)SpinnerModel.java 1.5 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;
  8. import java.awt.event.*;
  9. import javax.swing.event.*;
  10. /**
  11. * A model for a potentially unbounded sequence of object values. This model
  12. * is similar to <code>ListModel</code> however there are some important differences:
  13. * <ul>
  14. * <li> The number of sequence elements isn't neccessarily bounded.
  15. * <li> The model doesn't support indexed random access to sequence elements.
  16. * Only three sequence values are accessible at a time: current, next and
  17. * previous.
  18. * <li> The current sequence element, can be set.
  19. * </ul>
  20. * <p>
  21. * A <code>SpinnerModel</code> has three properties, only the first is read/write.
  22. * <dl>
  23. * <dt><code>value</code>
  24. * <dd>The current element of the sequence.
  25. *
  26. * <dt><code>nextValue</code>
  27. * <dd>The following element or null if <code>value</code> is the
  28. * last element of the sequence.
  29. *
  30. * <dt><code>previousValue</code>
  31. * <dd>The preceeding element or null if <code>value</code> is the
  32. * first element of the sequence.
  33. * </dl>
  34. * When the the <code>value</code> property changes,
  35. * <code>ChangeListeners</code> are notified. <code>SpinnerModel</code> may
  36. * choose to notify the <code>ChangeListeners</code> under other circumstances.
  37. *
  38. * @see JSpinner
  39. * @see AbstractSpinnerModel
  40. * @see SpinnerListModel
  41. * @see SpinnerNumberModel
  42. * @see SpinnerDateModel
  43. *
  44. * @version 1.5 01/23/03
  45. * @author Hans Muller
  46. * @since 1.4
  47. */
  48. public interface SpinnerModel
  49. {
  50. /**
  51. * The <i>current element</i> of the sequence. This element is usually
  52. * displayed by the <code>editor</code> part of a <code>JSpinner</code>.
  53. *
  54. * @return the current spinner value.
  55. * @see #setValue
  56. */
  57. Object getValue();
  58. /**
  59. * Changes current value of the model, typically this value is displayed
  60. * by the <code>editor</code> part of a <code>JSpinner</code>.
  61. * If the <code>SpinnerModel</code> implementation doesn't support
  62. * the specified value then an <code>IllegalArgumentException</code>
  63. * is thrown. For example a <code>SpinnerModel</code> for numbers might
  64. * only support values that are integer multiples of ten. In
  65. * that case, <code>model.setValue(new Number(11))</code>
  66. * would throw an exception.
  67. *
  68. * @throws IllegalArgumentException if <code>value</code> isn't allowed
  69. * @see #getValue
  70. */
  71. void setValue(Object value);
  72. /**
  73. * Return the object in the sequence that comes after the object returned
  74. * by <code>getValue()</code>. If the end of the sequence has been reached
  75. * then return null. Calling this method does not effect <code>value</code>.
  76. *
  77. * @return the next legal value or null if one doesn't exist
  78. * @see #getValue
  79. * @see #getPreviousValue
  80. */
  81. Object getNextValue();
  82. /**
  83. * Return the object in the sequence that comes before the object returned
  84. * by <code>getValue()</code>. If the end of the sequence has been reached then
  85. * return null. Calling this method does not effect <code>value</code>.
  86. *
  87. * @return the previous legal value or null if one doesn't exist
  88. * @see #getValue
  89. * @see #getNextValue
  90. */
  91. Object getPreviousValue();
  92. /**
  93. * Adds a <code>ChangeListener</code> to the model's listener list. The
  94. * <code>ChangeListeners</code> must be notified when models <code>value</code>
  95. * changes.
  96. *
  97. * @param l the ChangeListener to add
  98. * @see #removeChangeListener
  99. */
  100. void addChangeListener(ChangeListener l);
  101. /**
  102. * Removes a <code>ChangeListener</code> from the model's listener list.
  103. *
  104. * @param l the ChangeListener to remove
  105. * @see #addChangeListener
  106. */
  107. void removeChangeListener(ChangeListener l);
  108. }