01: package vicazh.hyperpool.stream;
02:
03: import java.util.*;
04:
05: /**
06: * The list selector combo box model for default value
07: *
08: * @author Victor Zhigunov
09: * @version 0.4.0
10: */
11: public class ISelectorDefModel extends ISelectorListModel {
12: private List<Object> data;
13:
14: /**
15: * @param data
16: * data list
17: */
18: public ISelectorDefModel(List<Object> data) {
19: this .data = data;
20: }
21:
22: public void setSelectedItem(Object anItem) {
23: int def = selector.getGroup().getObjects().indexOf(anItem);
24: List<List<Object>> list = selector.getList();
25: for (Object o : data) {
26: int j = selector.getIndex(o);
27: List<Object> l = list.get(j);
28: if (j == def)
29: l.remove(o);
30: else if (!l.contains(o))
31: l.add(o);
32: }
33: selector.setList(list);
34: selector.setDef(def);
35: }
36:
37: public Object getSelectedItem() {
38: return selector == null ? null
39: : getElementAt(selector.getDef());
40: }
41: }
|