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