1 package org.objectweb.proactive.p2p.peerconfiguration; 2 import javax.swing.SpinnerModel ; 3 import javax.swing.SpinnerListModel ; 4 5 19 public class CyclingSpinnerListModel extends SpinnerListModel { 20 Object firstValue, lastValue; 21 SpinnerModel linkedModel = null; 22 23 public CyclingSpinnerListModel(Object [] values) { 24 super(values); 25 firstValue = values[0]; 26 lastValue = values[values.length - 1]; 27 } 28 29 public void setLinkedModel(SpinnerModel linkedModel) { 30 this.linkedModel = linkedModel; 31 } 32 33 public Object getNextValue() { 34 Object value = super.getNextValue(); 35 if (value == null) { 36 value = firstValue; 37 if (linkedModel != null) { 38 linkedModel.setValue(linkedModel.getNextValue()); 39 } 40 } 41 return value; 42 } 43 44 public Object getPreviousValue() { 45 Object value = super.getPreviousValue(); 46 if (value == null) { 47 value = lastValue; 48 if (linkedModel != null) { 49 linkedModel.setValue(linkedModel.getPreviousValue()); 50 } 51 } 52 return value; 53 } 54 } 55 | Popular Tags |