1 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 [] values) { 33 this.list = Arrays.asList(values); 34 this.index = 0; 35 } 36 37 public SpinnerListModel() { 38 this(new Object []{ "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 getValue() { 52 return list.get(index); 53 } 54 55 public void setValue(Object elt) { 56 this.index = list.indexOf(elt); 57 fireStateChanged(); 58 } 59 60 public Object getNextValue() { 61 return (index >= (list.size() - 1)) ? null : list.get(index + 1); 62 } 63 64 public Object getPreviousValue() { 65 return (index <= 0) ? null : list.get(index - 1); 66 } 67 68 } 69 70 | Popular Tags |