src/share/classes/javax/swing/SpinnerListModel.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  39  * SpinnerModel model = new SpinnerListModel(Arrays.asList(days).subList(1, 8));
  40  * </pre>
  41  * This class only stores a reference to the array or <code>List</code>
  42  * so if an element of the underlying sequence changes, it's up
  43  * to the application to notify the <code>ChangeListeners</code> by calling
  44  * <code>fireStateChanged</code>.
  45  * <p>
  46  * This model inherits a <code>ChangeListener</code>.
  47  * The <code>ChangeListener</code>s are notified whenever the
  48  * model's <code>value</code> or <code>list</code> properties changes.
  49  *
  50  * @see JSpinner
  51  * @see SpinnerModel
  52  * @see AbstractSpinnerModel
  53  * @see SpinnerNumberModel
  54  * @see SpinnerDateModel
  55  *
  56  * @author Hans Muller
  57  * @since 1.4
  58  */

  59 public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
  60 {
  61     private List list;
  62     private int index;
  63 
  64 
  65     /**
  66      * Constructs a <code>SpinnerModel</code> whose sequence of
  67      * values is defined by the specified <code>List</code>.
  68      * The initial value (<i>current element</i>)
  69      * of the model will be <code>values.get(0)</code>.
  70      * If <code>values</code> is <code>null</code> or has zero
  71      * size, an <code>IllegalArugmentException</code> is thrown.
  72      *
  73      * @param values the sequence this model represents
  74      * @throws IllegalArgumentException if <code>values</code> is
  75      *    <code>null</code> or zero size
  76      */
  77     public SpinnerListModel(List<?> values) {
  78         if (values == null || values.size() == 0) {


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  39  * SpinnerModel model = new SpinnerListModel(Arrays.asList(days).subList(1, 8));
  40  * </pre>
  41  * This class only stores a reference to the array or <code>List</code>
  42  * so if an element of the underlying sequence changes, it's up
  43  * to the application to notify the <code>ChangeListeners</code> by calling
  44  * <code>fireStateChanged</code>.
  45  * <p>
  46  * This model inherits a <code>ChangeListener</code>.
  47  * The <code>ChangeListener</code>s are notified whenever the
  48  * model's <code>value</code> or <code>list</code> properties changes.
  49  *
  50  * @see JSpinner
  51  * @see SpinnerModel
  52  * @see AbstractSpinnerModel
  53  * @see SpinnerNumberModel
  54  * @see SpinnerDateModel
  55  *
  56  * @author Hans Muller
  57  * @since 1.4
  58  */
  59 @SuppressWarnings("serial") // Superclass is not serializable across versions
  60 public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
  61 {
  62     private List list;
  63     private int index;
  64 
  65 
  66     /**
  67      * Constructs a <code>SpinnerModel</code> whose sequence of
  68      * values is defined by the specified <code>List</code>.
  69      * The initial value (<i>current element</i>)
  70      * of the model will be <code>values.get(0)</code>.
  71      * If <code>values</code> is <code>null</code> or has zero
  72      * size, an <code>IllegalArugmentException</code> is thrown.
  73      *
  74      * @param values the sequence this model represents
  75      * @throws IllegalArgumentException if <code>values</code> is
  76      *    <code>null</code> or zero size
  77      */
  78     public SpinnerListModel(List<?> values) {
  79         if (values == null || values.size() == 0) {