1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.table.renderers;
21
22 import com.cosylab.gui.components.table.cells.LongEnumCell;
23
24 import javax.swing.AbstractListModel;
25 import javax.swing.ComboBoxModel;
26
27
28 class EnumComboBoxModel extends AbstractListModel implements ComboBoxModel
29 {
30 private static final long serialVersionUID = 1L;
31 LongEnumCell cell;
32 int min = -1;
33 int max = 0;
34 String selected;
35
36 public EnumComboBoxModel()
37 {
38 super();
39 }
40
41
42
43
44 public Object getElementAt(int index)
45 {
46 if (cell == null) {
47 return null;
48 }
49
50 return cell.getStateLabel(index - min);
51 }
52
53
54
55
56 public int getSize()
57 {
58 return max - min + 1;
59 }
60
61
62
63
64 public Object getSelectedItem()
65 {
66 return selected;
67 }
68
69
70
71
72 public void setSelectedItem(Object anItem)
73 {
74 selected = (String)anItem;
75 }
76
77 public void setCell(LongEnumCell c)
78 {
79 cell = c;
80 selected = null;
81
82 int size = getSize();
83 max = 0;
84 min = -1;
85
86 if (size > 0) {
87 fireIntervalRemoved(this, 0, size);
88 }
89
90 if (cell == null) {
91 return;
92 }
93
94 min = 15;
95 max = 0;
96
97 for (int i = 0; i < 16; i++) {
98 Object o = cell.getCharacteristic(LongEnumCell.STATE_DESCRIPTION
99 + i);
100
101 if (o !=null ) {
102 if (i < min) {
103 min = i;
104 }
105
106 if (i > max) {
107 max = i;
108 }
109 }
110 }
111
112 fireIntervalAdded(this, 0, getSize());
113 }
114
115 public Long getLongVale()
116 {
117 if (selected == null || cell == null) {
118 return null;
119 }
120
121 return new Long(cell.toLongValue(selected));
122 }
123 }
124
125