KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > SpinnerListModel


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: SpinnerListModel.java,v $
11    Revision 1.1 2004/04/18 14:21:50 bobintetley
12    JSpinner implementation
13
14
15 */

16
17
18 package swingwtx.swing;
19
20 import java.util.*;
21
22 public class SpinnerListModel extends AbstractSpinnerModel {
23     
24     private List list;
25     private int index;
26
27     public SpinnerListModel(List values) {
28     this.list = values;
29     this.index = 0;
30     }
31
32     public SpinnerListModel(Object JavaDoc[] values) {
33     this.list = Arrays.asList(values);
34         this.index = 0;
35     }
36
37     public SpinnerListModel() {
38     this(new Object JavaDoc[]{ "empty" });
39     }
40
41     public List getList() {
42     return list;
43     }
44
45     public void setList(List list) {
46         this.list = list;
47         index = 0;
48         fireStateChanged();
49     }
50
51     public Object JavaDoc getValue() {
52     return list.get(index);
53     }
54
55     public void setValue(Object JavaDoc elt) {
56     this.index = list.indexOf(elt);
57     fireStateChanged();
58     }
59
60     public Object JavaDoc getNextValue() {
61     return (index >= (list.size() - 1)) ? null : list.get(index + 1);
62     }
63
64     public Object JavaDoc getPreviousValue() {
65     return (index <= 0) ? null : list.get(index - 1);
66     }
67
68 }
69
70
Popular Tags