1 package org.catacomb.druid.gui.edit;
2
3 import org.catacomb.druid.event.LabelActor;
4 import org.catacomb.druid.gui.base.DruListCellRenderer;
5 import org.catacomb.druid.swing.DCheckboxList;
6 import org.catacomb.druid.util.ListDisplay;
7 import org.catacomb.interlish.structure.ListWatcher;
8 import org.catacomb.report.E;
9
10
11 import java.awt.Color;
12 import java.util.ArrayList;
13
14 public class DruCheckboxListPanel extends DruGCPanel implements ListDisplay, LabelActor {
15 static final long serialVersionUID = 1001;
16
17 int nrow;
18
19 DCheckboxList dList;
20
21 ListWatcher listWatcher;
22
23 String toggleAction;
24
25 boolean multiple;
26
27
28 public DruCheckboxListPanel() {
29 this(10);
30 }
31
32 public DruCheckboxListPanel(int nr) {
33 super();
34 nrow = nr;
35
36 dList = new DCheckboxList();
37
38 addSingleDComponent(dList);
39
40
41 dList.setItems(new Object[0]);
42
43 dList.setLabelActor(this);
44 }
45
46
47
48 public void setItems(String[] sa) {
49 dList.setItems(sa);
50 if (listWatcher != null) {
51 listWatcher.listChanged(this);
52 }
53 }
54
55
56 public void setItems(ArrayList<? extends Object> obal) {
57 Object[] obar = obal.toArray(new Object[obal.size()]);
58 dList.setItems(obar);
59
60 if (listWatcher != null) {
61 listWatcher.listChanged(this);
62 }
63 }
64
65
66 public void setSelected(String[] sa) {
67 dList.setSelected(sa);
68 }
69
70 public void setSelected(int[] ia) {
71 dList.setSelected(ia);
72 }
73
74 public void selectAll() {
75 dList.selectAll();
76 }
77
78
79 public ArrayList<Object> getAllItems() {
80 return dList.getAllItems();
81 }
82
83 public ArrayList<Object> getSelectedItems() {
84 return dList.getCheckedItems();
85 }
86
87
88 public void setBg(Color c) {
89 dList.setBackground(c);
90 super.setBg(c);
91 }
92
93
94
95 public void updateDisplay() {
96
97 dList.repaint();
98 }
99
100
101 public Object getSelectedItem() {
102 return dList.getSelectedValue();
103 }
104
105
106 public String getSelectedName() {
107 return "" + getSelectedItem();
108 }
109
110
111 public void labelAction(String s, boolean b) {
112 if (s.equals("selected")) {
113 valueChange(getSelectedName());
114
115 } else if (s.equals("toggle")) {
116
117 if (toggleAction != null) {
118 performAction(toggleAction, b);
119
120 }
121
122
123 if (listWatcher != null) {
124 listWatcher.listChanged(this);
125 }
126
127 } else {
128 E.warning("unhandled " + s);
129 }
130 }
131
132
133 public void setToggleAction(String ta) {
134 toggleAction = ta;
135
136 }
137
138
139 public void clear() {
140 dList.setListData(new String[0]);
141 }
142
143
144 public void selectAt(int i) {
145 dList.selectAt(i);
146 }
147
148 public ArrayList<Object> getCheckedItems() {
149 return dList.getCheckedItems();
150 }
151
152
153
154 public int[] getCheckedIndexes() {
155 return dList.getCheckedIndexes();
156 }
157
158
159 public void setCheckedIndexes(int[] inds) {
160 dList.setCheckedIndexes(inds);
161 }
162
163
164
165 public Object getLastSelected() {
166 return dList.getLastSelected();
167 }
168
169 public boolean hasActiveSelected() {
170 return dList.hasActiveSelected();
171 }
172
173 public void setListWatcher(ListWatcher lw) {
174 listWatcher = lw;
175
176 }
177
178 public int[] getSelectedIndexes() {
179 return dList.getCheckedIndexes();
180 }
181
182
183
184 public void setCellRenderer(DruListCellRenderer obj) {
185 E.error("cant set renderer for a checkbox list...");
186
187 }
188
189 public void setMultiple() {
190 multiple = true;
191 dList.setMultiple();
192 }
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219 }