jdk/src/share/classes/javax/swing/SpinnerDateModel.java
author ant
Thu, 17 May 2012 21:48:57 +0400
changeset 12661 6cf8b7116579
parent 5506 202f599c92aa
child 20169 d7fa6d7586c9
permissions -rw-r--r--
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application. Summary: forward port from 7u4 Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2004, 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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * However some UIs may set the calendarField before commiting the edit
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
public class SpinnerDateModel extends AbstractSpinnerModel implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private Comparable start, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Calendar value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private boolean calendarFieldOK(int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        switch(calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        case Calendar.ERA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        case Calendar.YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        case Calendar.MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        case Calendar.WEEK_OF_YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        case Calendar.WEEK_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        case Calendar.DAY_OF_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        case Calendar.DAY_OF_YEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case Calendar.DAY_OF_WEEK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        case Calendar.DAY_OF_WEEK_IN_MONTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        case Calendar.AM_PM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case Calendar.HOUR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        case Calendar.HOUR_OF_DAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        case Calendar.MINUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        case Calendar.SECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        case Calendar.MILLISECOND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
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
     * Creates a <code>SpinnerDateModel</code> that represents a sequence of dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * between <code>start</code> and <code>end</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <code>nextValue</code> and <code>previousValue</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * compute elements of the sequence by advancing or reversing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * the current date <code>value</code> by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <code>calendarField</code> time unit.  For a precise description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * of what it means to increment or decrement a <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <code>field</code>, see the <code>add</code> method in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>java.util.Calendar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The <code>start</code> and <code>end</code> parameters can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <code>null</code> to indicate that the range doesn't have an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * upper or lower bound.  If <code>value</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <code>calendarField</code> is <code>null</code>, or if both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>start</code> and <code>end</code> are specified and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>mininum &gt; maximum</code> then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>IllegalArgumentException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Similarly if <code>(minimum &lt;= value &lt;= maximum)</code> is false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * an IllegalArgumentException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param value the current (non <code>null</code>) value of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param start the first date in the sequence or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param end the last date in the sequence or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param calendarField one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *    <li><code>Calendar.ERA</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *    <li><code>Calendar.YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *    <li><code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *    <li><code>Calendar.WEEK_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *    <li><code>Calendar.WEEK_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *    <li><code>Calendar.DAY_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *    <li><code>Calendar.DAY_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *    <li><code>Calendar.DAY_OF_WEEK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *    <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *    <li><code>Calendar.AM_PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *    <li><code>Calendar.HOUR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *    <li><code>Calendar.HOUR_OF_DAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *    <li><code>Calendar.MINUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *    <li><code>Calendar.SECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *    <li><code>Calendar.MILLISECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws IllegalArgumentException if <code>value</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *    <code>calendarField</code> are <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *    if <code>calendarField</code> isn't valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *    or if the following expression is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *    false: <code>(start &lt;= value &lt;= end)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see Calendar#add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public SpinnerDateModel(Date value, Comparable start, Comparable end, int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new IllegalArgumentException("value is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (!calendarFieldOK(calendarField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new IllegalArgumentException("invalid calendarField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (!(((start == null) || (start.compareTo(value) <= 0)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
              ((end == null) || (end.compareTo(value) >= 0)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new IllegalArgumentException("(start <= value <= end) is false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this.value = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        this.calendarField = calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this.value.setTime(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
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
     * Constructs a <code>SpinnerDateModel</code> whose initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <code>value</code> is the current date, <code>calendarField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * is equal to <code>Calendar.DAY_OF_MONTH</code>, and for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * there are no <code>start</code>/<code>end</code> limits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public SpinnerDateModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        this(new Date(), null, null, Calendar.DAY_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
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
     * Changes the lower limit for Dates in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * If <code>start</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * then there is no lower limit.  No bounds checking is done here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * the new start value may invalidate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>(start &lt;= value &lt;= end)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * invariant enforced by the constructors.  This is to simplify updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the model.  Naturally one should ensure that the invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Typically this property is a <code>Date</code> however it's possible to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * a <code>Comparable</code> with a <code>compareTo</code> method for Dates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * For example <code>start</code> might be an instance of a class like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * MyStartDate implements Comparable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     long t = 12345;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *     public int compareTo(Date d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *            return (t < d.getTime() ? -1 : (t == d.getTime() ? 0 : 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *     public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *            return compareTo((Date)o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Note that the above example will throw a <code>ClassCastException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * if the <code>Object</code> passed to <code>compareTo(Object)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * is not a <code>Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <code>start</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param start defines the first date in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see #getStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void setStart(Comparable start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if ((start == null) ? (this.start != null) : !start.equals(this.start)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
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
     * Returns the first <code>Date</code> in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the value of the <code>start</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Comparable getStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
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
     * Changes the upper limit for <code>Date</code>s in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * If <code>start</code> is <code>null</code>, then there is no upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * limit.  No bounds checking is done here: the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * start value may invalidate the <code>(start &lt;= value &lt;= end)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * invariant enforced by the constructors.  This is to simplify updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the model.  Naturally, one should ensure that the invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Typically this property is a <code>Date</code> however it's possible to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>Comparable</code> with a <code>compareTo</code> method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>Date</code>s.  See <code>setStart</code> for an example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * This method fires a <code>ChangeEvent</code> if the <code>end</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param end defines the last date in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see #getEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see #setStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void setEnd(Comparable end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if ((end == null) ? (this.end != null) : !end.equals(this.end)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
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
     * Returns the last <code>Date</code> in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @return the value of the <code>end</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see #setEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public Comparable getEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
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
     * Changes the size of the date value change computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * by the <code>nextValue</code> and <code>previousValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * The <code>calendarField</code> parameter must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <code>Calendar</code> field constants like <code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * or <code>Calendar.MINUTE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * The <code>nextValue</code> and <code>previousValue</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * simply move the specified <code>Calendar</code> field forward or backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * by one unit with the <code>Calendar.add</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * You should use this method with care as some UIs may set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * calendarField before commiting the edit to spin the field under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * the cursor. If you only want one field to spin you can subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * and ignore the setCalendarField calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param calendarField one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *    <li><code>Calendar.ERA</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *    <li><code>Calendar.YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *    <li><code>Calendar.MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *    <li><code>Calendar.WEEK_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *    <li><code>Calendar.WEEK_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *    <li><code>Calendar.DAY_OF_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *    <li><code>Calendar.DAY_OF_YEAR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *    <li><code>Calendar.DAY_OF_WEEK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *    <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *    <li><code>Calendar.AM_PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *    <li><code>Calendar.HOUR</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *    <li><code>Calendar.HOUR_OF_DAY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *    <li><code>Calendar.MINUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *    <li><code>Calendar.SECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *    <li><code>Calendar.MILLISECOND</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <code>calendarField</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @see #getCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see Calendar#add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public void setCalendarField(int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (!calendarFieldOK(calendarField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            throw new IllegalArgumentException("invalid calendarField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (calendarField != this.calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            this.calendarField = calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
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
     * Returns the <code>Calendar</code> field that is added to or subtracted from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * by the <code>nextValue</code> and <code>previousValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @return the value of the <code>calendarField</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public int getCalendarField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
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
     * Returns the next <code>Date</code> in the sequence, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * the next date is after <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @return the next <code>Date</code> in the sequence, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *     the next date is after <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see SpinnerModel#getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see #getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public Object getNextValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        Calendar cal = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        cal.setTime(value.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        cal.add(calendarField, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Date next = cal.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return ((end == null) || (end.compareTo(next) >= 0)) ? next : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
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
     * Returns the previous <code>Date</code> in the sequence, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * if the previous date is before <code>start</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return the previous <code>Date</code> in the sequence, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *     <code>null</code> if the previous date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *     is before <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see SpinnerModel#getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see #getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #setCalendarField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public Object getPreviousValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        Calendar cal = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        cal.setTime(value.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        cal.add(calendarField, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        Date prev = cal.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return ((start == null) || (start.compareTo(prev) <= 0)) ? prev : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
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
     * Returns the current element in this sequence of <code>Date</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * This method is equivalent to <code>(Date)getValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @return the <code>value</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public Date getDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return value.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
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
     * Returns the current element in this sequence of <code>Date</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return the <code>value</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see #getDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return value.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
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
     * Sets the current <code>Date</code> for this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * If <code>value</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * an <code>IllegalArgumentException</code> is thrown.  No bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * checking is done here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * the new value may invalidate the <code>(start &lt= value &lt end)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * invariant enforced by the constructors.  Naturally, one should ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * that the <code>(start &lt;= value &lt;= maximum)</code> invariant is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * before calling the <code>nextValue</code>, <code>previousValue</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * or <code>setValue</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * This method fires a <code>ChangeEvent</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <code>value</code> has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param value the current (non <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *    <code>Date</code> for this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @throws IllegalArgumentException if value is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *    or not a <code>Date</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see #getDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if ((value == null) || !(value instanceof Date)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            throw new IllegalArgumentException("illegal value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (!value.equals(this.value.getTime())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            this.value.setTime((Date)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
}