SpinnerListModel.java revision 2362
1008N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. 1008N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1008N/A * This code is free software; you can redistribute it and/or modify it 1008N/A * under the terms of the GNU General Public License version 2 only, as 1008N/A * published by the Free Software Foundation. Oracle designates this 1008N/A * particular file as subject to the "Classpath" exception as provided 1008N/A * by Oracle in the LICENSE file that accompanied this code. 1008N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1008N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1008N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1008N/A * version 2 for more details (a copy is included in the LICENSE file that 1008N/A * You should have received a copy of the GNU General Public License version 1008N/A * 2 along with this work; if not, write to the Free Software Foundation, 1008N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1008N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1008N/A * or visit www.oracle.com if you need additional information or have any 1008N/A * A simple implementation of <code>SpinnerModel</code> whose 1008N/A * values are defined by an array or a <code>List</code>. 3646N/A * For example to create a model defined by 2617N/A * an array of the names of the days of the week: 1008N/A * String[] days = new DateFormatSymbols().getWeekdays(); 2086N/A * SpinnerModel model = new SpinnerListModel(Arrays.asList(days).subList(1, 8)); 2617N/A * This class only stores a reference to the array or <code>List</code> 2617N/A * so if an element of the underlying sequence changes, it's up 2617N/A * to the application to notify the <code>ChangeListeners</code> by calling 2617N/A * <code>fireStateChanged</code>. 1008N/A * This model inherits a <code>ChangeListener</code>. 1008N/A * The <code>ChangeListener</code>s are notified whenever the 1008N/A * model's <code>value</code> or <code>list</code> properties changes. 1008N/A * @see AbstractSpinnerModel 1008N/A * Constructs a <code>SpinnerModel</code> whose sequence of 1008N/A * values is defined by the specified <code>List</code>. 1008N/A * The initial value (<i>current element</i>) 1008N/A * of the model will be <code>values.get(0)</code>. 1008N/A * If <code>values</code> is <code>null</code> or has zero 1008N/A * size, an <code>IllegalArugmentException</code> is thrown. 2617N/A * @param values the sequence this model represents 2617N/A * @throws IllegalArugmentException if <code>values</code> is 2617N/A * <code>null</code> or zero size 2617N/A * Constructs a <code>SpinnerModel</code> whose sequence of values 1008N/A * is defined by the specified array. The initial value of the model 1008N/A * will be <code>values[0]</code>. If <code>values</code> is 1008N/A * <code>null</code> or has zero length, an 1008N/A * <code>IllegalArugmentException</code> is thrown. 1008N/A * @param values the sequence this model represents 1008N/A * @throws IllegalArugmentException if <code>values</code> is 1008N/A * <code>null</code> or zero length 1008N/A * Constructs an effectively empty <code>SpinnerListModel</code>. 1008N/A * The model's list will contain a single 1008N/A * <code>"empty"</code> string element. 2617N/A * Returns the <code>List</code> that defines the sequence for this model. 2617N/A * @return the value of the <code>list</code> property 3646N/A * Changes the list that defines this sequence and resets the index 1008N/A * of the models <code>value</code> to zero. Note that <code>list</code> 1008N/A * is not copied, the model just stores a reference to it. 1008N/A * This method fires a <code>ChangeEvent</code> if <code>list</code> is 1008N/A * not equal to the current list. 2617N/A * @param list the sequence that this model represents 2617N/A * @throws IllegalArgumentException if <code>list</code> is 2617N/A * <code>null</code> or zero length 1008N/A * Returns the current element of the sequence. 1008N/A * @return the <code>value</code> property 1008N/A * @see SpinnerModel#getValue 2617N/A * Changes the current element of the sequence and notifies 2617N/A * <code>ChangeListeners</code>. If the specified 2617N/A * value is not equal to an element of the underlying sequence 2617N/A * then an <code>IllegalArgumentException</code> is thrown. 2617N/A * In the following example the <code>setValue</code> call 2617N/A * would cause an exception to be thrown: 2617N/A * String[] values = {"one", "two", "free", "four"}; 1008N/A * SpinnerModel model = new SpinnerListModel(values); 1008N/A * @param elt the sequence element that will be model's current value 1008N/A * @throws IllegalArgumentException if the specified value isn't allowed 1008N/A * @see SpinnerModel#setValue * Returns the next legal value of the underlying sequence or * <code>null</code> if value is already the last element. * @return the next legal value of the underlying sequence or * <code>null</code> if value is already the last element * @see SpinnerModel#getNextValue * Returns the previous element of the underlying sequence or * <code>null</code> if value is already the first element. * @return the previous element of the underlying sequence or * <code>null</code> if value is already the first element * @see SpinnerModel#getPreviousValue * Returns the next object that starts with <code>substring</code>. * @param substring the string to be matched