jdk/src/java.desktop/share/classes/javax/swing/SpinnerDateModel.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 25859 3317bb8137f4
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A <code>SpinnerModel</code> for sequences of <code>Date</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The upper and lower bounds of the sequence are defined by properties called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>start</code> and <code>end</code> and the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * of the increase or decrease computed by the <code>nextValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * and <code>previousValue</code> methods is defined by a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * called <code>calendarField</code>.  The <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * and <code>end</code> properties can be <code>null</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * indicate that the sequence has no lower or upper limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The value of the <code>calendarField</code> property must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>java.util.Calendar</code> constants that specify a field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * within a <code>Calendar</code>.  The <code>getNextValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * and <code>getPreviousValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * methods change the date forward or backwards by this amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * For example, if <code>calendarField</code> is <code>Calendar.DAY_OF_WEEK</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * then <code>nextValue</code> produces a <code>Date</code> that's 24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * hours after the current <code>value</code>, and <code>previousValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * produces a <code>Date</code> that's 24 hours earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The legal values for <code>calendarField</code> are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   <li><code>Calendar.ERA</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <li><code>Calendar.YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <li><code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <li><code>Calendar.WEEK_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   <li><code>Calendar.WEEK_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   <li><code>Calendar.DAY_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <li><code>Calendar.DAY_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   <li><code>Calendar.DAY_OF_WEEK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   <li><code>Calendar.AM_PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   <li><code>Calendar.HOUR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <li><code>Calendar.HOUR_OF_DAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <li><code>Calendar.MINUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <li><code>Calendar.SECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   <li><code>Calendar.MILLISECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </ul>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
    70
 * However some UIs may set the calendarField before committing the edit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * to spin the field under the cursor. If you only want one field to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * spin you can subclass and ignore the setCalendarField calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * This model inherits a <code>ChangeListener</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <code>ChangeListeners</code> are notified whenever the models
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <code>value</code>, <code>calendarField</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <code>start</code>, or <code>end</code> properties changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see JSpinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see SpinnerModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see AbstractSpinnerModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see SpinnerListModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see SpinnerNumberModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see Calendar#add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    89
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public class SpinnerDateModel extends AbstractSpinnerModel implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
    92
    private Comparable<Date> start, end;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private Calendar value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private boolean calendarFieldOK(int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        switch(calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        case Calendar.ERA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        case Calendar.YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        case Calendar.MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        case Calendar.WEEK_OF_YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        case Calendar.WEEK_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        case Calendar.DAY_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case Calendar.DAY_OF_YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        case Calendar.DAY_OF_WEEK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        case Calendar.DAY_OF_WEEK_IN_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case Calendar.AM_PM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        case Calendar.HOUR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        case Calendar.HOUR_OF_DAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        case Calendar.MINUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        case Calendar.SECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        case Calendar.MILLISECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Creates a <code>SpinnerDateModel</code> that represents a sequence of dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * between <code>start</code> and <code>end</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>nextValue</code> and <code>previousValue</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * compute elements of the sequence by advancing or reversing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * the current date <code>value</code> by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>calendarField</code> time unit.  For a precise description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * of what it means to increment or decrement a <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>field</code>, see the <code>add</code> method in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <code>java.util.Calendar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The <code>start</code> and <code>end</code> parameters can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <code>null</code> to indicate that the range doesn't have an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * upper or lower bound.  If <code>value</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>calendarField</code> is <code>null</code>, or if both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>start</code> and <code>end</code> are specified and
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   137
     * <code>minimum &gt; maximum</code> then an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <code>IllegalArgumentException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Similarly if <code>(minimum &lt;= value &lt;= maximum)</code> is false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * an IllegalArgumentException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param value the current (non <code>null</code>) value of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param start the first date in the sequence or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param end the last date in the sequence or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param calendarField one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *    <li><code>Calendar.ERA</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *    <li><code>Calendar.YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *    <li><code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *    <li><code>Calendar.WEEK_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *    <li><code>Calendar.WEEK_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *    <li><code>Calendar.DAY_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *    <li><code>Calendar.DAY_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *    <li><code>Calendar.DAY_OF_WEEK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *    <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *    <li><code>Calendar.AM_PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *    <li><code>Calendar.HOUR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *    <li><code>Calendar.HOUR_OF_DAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *    <li><code>Calendar.MINUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *    <li><code>Calendar.SECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *    <li><code>Calendar.MILLISECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws IllegalArgumentException if <code>value</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *    <code>calendarField</code> are <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *    if <code>calendarField</code> isn't valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *    or if the following expression is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *    false: <code>(start &lt;= value &lt;= end)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see Calendar#add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
   176
    public SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new IllegalArgumentException("value is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (!calendarFieldOK(calendarField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new IllegalArgumentException("invalid calendarField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (!(((start == null) || (start.compareTo(value) <= 0)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              ((end == null) || (end.compareTo(value) >= 0)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            throw new IllegalArgumentException("(start <= value <= end) is false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        this.value = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.calendarField = calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this.value.setTime(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Constructs a <code>SpinnerDateModel</code> whose initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>value</code> is the current date, <code>calendarField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * is equal to <code>Calendar.DAY_OF_MONTH</code>, and for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * there are no <code>start</code>/<code>end</code> limits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public SpinnerDateModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this(new Date(), null, null, Calendar.DAY_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Changes the lower limit for Dates in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * If <code>start</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * then there is no lower limit.  No bounds checking is done here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * the new start value may invalidate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <code>(start &lt;= value &lt;= end)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * invariant enforced by the constructors.  This is to simplify updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * the model.  Naturally one should ensure that the invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Typically this property is a <code>Date</code> however it's possible to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * a <code>Comparable</code> with a <code>compareTo</code> method for Dates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * For example <code>start</code> might be an instance of a class like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * MyStartDate implements Comparable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *     long t = 12345;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *     public int compareTo(Date d) {
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   225
     *            return (t &lt; d.getTime() ? -1 : (t == d.getTime() ? 0 : 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *     public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *            return compareTo((Date)o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Note that the above example will throw a <code>ClassCastException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * if the <code>Object</code> passed to <code>compareTo(Object)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * is not a <code>Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <code>start</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param start defines the first date in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see #getStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
   244
    public void setStart(Comparable<Date> start) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if ((start == null) ? (this.start != null) : !start.equals(this.start)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns the first <code>Date</code> in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return the value of the <code>start</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
   258
    public Comparable<Date> getStart() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Changes the upper limit for <code>Date</code>s in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * If <code>start</code> is <code>null</code>, then there is no upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * limit.  No bounds checking is done here: the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * start value may invalidate the <code>(start &lt;= value &lt;= end)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * invariant enforced by the constructors.  This is to simplify updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the model.  Naturally, one should ensure that the invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Typically this property is a <code>Date</code> however it's possible to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>Comparable</code> with a <code>compareTo</code> method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <code>Date</code>s.  See <code>setStart</code> for an example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * This method fires a <code>ChangeEvent</code> if the <code>end</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param end defines the last date in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see #getEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
   285
    public void setEnd(Comparable<Date> end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if ((end == null) ? (this.end != null) : !end.equals(this.end)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Returns the last <code>Date</code> in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return the value of the <code>end</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
   299
    public Comparable<Date> getEnd() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Changes the size of the date value change computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * by the <code>nextValue</code> and <code>previousValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * The <code>calendarField</code> parameter must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <code>Calendar</code> field constants like <code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * or <code>Calendar.MINUTE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * The <code>nextValue</code> and <code>previousValue</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * simply move the specified <code>Calendar</code> field forward or backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * by one unit with the <code>Calendar.add</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * You should use this method with care as some UIs may set the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   314
     * calendarField before committing the edit to spin the field under
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * the cursor. If you only want one field to spin you can subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * and ignore the setCalendarField calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param calendarField one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *    <li><code>Calendar.ERA</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *    <li><code>Calendar.YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *    <li><code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *    <li><code>Calendar.WEEK_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *    <li><code>Calendar.WEEK_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *    <li><code>Calendar.DAY_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *    <li><code>Calendar.DAY_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *    <li><code>Calendar.DAY_OF_WEEK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *    <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *    <li><code>Calendar.AM_PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *    <li><code>Calendar.HOUR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *    <li><code>Calendar.HOUR_OF_DAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *    <li><code>Calendar.MINUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *    <li><code>Calendar.SECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *    <li><code>Calendar.MILLISECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <code>calendarField</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #getCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see #getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see Calendar#add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public void setCalendarField(int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (!calendarFieldOK(calendarField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            throw new IllegalArgumentException("invalid calendarField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (calendarField != this.calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            this.calendarField = calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Returns the <code>Calendar</code> field that is added to or subtracted from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * by the <code>nextValue</code> and <code>previousValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @return the value of the <code>calendarField</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public int getCalendarField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Returns the next <code>Date</code> in the sequence, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * the next date is after <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @return the next <code>Date</code> in the sequence, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *     the next date is after <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see SpinnerModel#getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see #getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public Object getNextValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Calendar cal = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        cal.setTime(value.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        cal.add(calendarField, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Date next = cal.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return ((end == null) || (end.compareTo(next) >= 0)) ? next : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns the previous <code>Date</code> in the sequence, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * if the previous date is before <code>start</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @return the previous <code>Date</code> in the sequence, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *     <code>null</code> if the previous date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *     is before <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see SpinnerModel#getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public Object getPreviousValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        Calendar cal = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        cal.setTime(value.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        cal.add(calendarField, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        Date prev = cal.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return ((start == null) || (start.compareTo(prev) <= 0)) ? prev : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns the current element in this sequence of <code>Date</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * This method is equivalent to <code>(Date)getValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return the <code>value</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public Date getDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return value.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Returns the current element in this sequence of <code>Date</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @return the <code>value</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #getDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return value.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Sets the current <code>Date</code> for this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * If <code>value</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * an <code>IllegalArgumentException</code> is thrown.  No bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * checking is done here:
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
   439
     * the new value may invalidate the <code>(start &lt;= value &lt; end)</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * invariant enforced by the constructors.  Naturally, one should ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * that the <code>(start &lt;= value &lt;= maximum)</code> invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * <code>value</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @param value the current (non <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *    <code>Date</code> for this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @throws IllegalArgumentException if value is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *    or not a <code>Date</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #getDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if ((value == null) || !(value instanceof Date)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            throw new IllegalArgumentException("illegal value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (!value.equals(this.value.getTime())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            this.value.setTime((Date)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}