1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.ximtec.igesture.configuration;
33
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.logging.Level;
39 import java.util.logging.Logger;
40
41 import org.sigtec.util.Constant;
42 import org.ximtec.igesture.core.DefaultDataObject;
43 import org.ximtec.igesture.core.GestureSet;
44 import org.ximtec.igesture.core.Visitor;
45 import org.ximtec.igesture.event.GestureHandler;
46 import org.ximtec.igesture.util.GestureTool;
47
48
49
50
51
52
53
54
55
56
57
58
59 public class Configuration extends DefaultDataObject implements Cloneable {
60
61 private static final Logger LOGGER = Logger.getLogger(Configuration.class
62 .getName());
63
64 public static final String PROPERTY_NAME = "name";
65
66 private static final String PROPERTY_MIN_ACCURACY = "minAccuracy";
67
68 private static final String PROPERTY_MAX_RESULT_SET_SIZE = "maxResultSetSize";
69
70
71
72
73 private List<GestureSet> gestureSets;
74
75
76
77
78 private String name;
79
80
81
82
83 private List<String> algorithms;
84
85
86
87
88
89 private HashMap<String, HashMap<String, String>> algorithmParameters;
90
91
92
93
94 private transient GestureHandler gestureHandler;
95
96
97
98
99 private int maxResultSetSize;
100
101
102
103
104 private double minAccuracy;
105
106
107
108
109
110 public Configuration() {
111
112 this("New Configuration");
113 }
114
115
116 public Configuration(String name) {
117 super();
118 this.gestureSets = new ArrayList<GestureSet>();
119 this.algorithms = new ArrayList<String>();
120 this.algorithmParameters = new HashMap<String, HashMap<String, String>>();
121 this.maxResultSetSize = Integer.MAX_VALUE;
122 this.minAccuracy = 0;
123 this.name = name;
124 }
125
126
127
128
129
130
131
132 public void addGestureSet(GestureSet gestureSet) {
133 gestureSets.add(gestureSet);
134 }
135
136
137
138
139
140
141
142 public void addGestureSets(List<GestureSet> gestureSets) {
143 this.gestureSets.addAll(gestureSets);
144 }
145
146
147
148
149
150 public void removeAllGestureSets() {
151 this.gestureSets.clear();
152 }
153
154
155
156
157
158
159
160 public void removeGestureSet(GestureSet gestureSet) {
161 gestureSets.remove(gestureSet);
162 }
163
164
165
166
167
168
169
170 public List<GestureSet> getGestureSets() {
171 return gestureSets;
172 }
173
174
175
176
177
178
179
180 public GestureSet getGestureSet() {
181 return GestureTool.combine(getGestureSets());
182 }
183
184
185
186
187
188
189
190 public void addAlgorithm(String algorithm) {
191 algorithms.add(algorithm);
192 algorithmParameters.put(algorithm, new HashMap<String, String>());
193 }
194
195
196
197
198
199
200
201 public void removeAlgorithm(String algorithm) {
202 algorithms.remove(algorithm);
203 algorithmParameters.remove(algorithm);
204 }
205
206
207
208
209
210
211
212 public List<String> getAlgorithms() {
213 return algorithms;
214 }
215
216
217
218
219
220
221
222
223
224
225 public void addParameter(String algorithm, String key, String value) {
226 Map<String, String> parameters = getParameters(algorithm);
227 parameters.put(key, value);
228 propertyChangeSupport.firePropertyChange("parameters", null, value);
229 }
230
231
232
233
234
235
236
237
238
239 public Map<String, String> getParameters(String classname) {
240 HashMap<String, String> parameters = algorithmParameters.get(classname);
241
242 if (parameters == null) {
243 parameters = new HashMap<String, String>();
244 algorithmParameters.put(classname, parameters);
245 }
246
247 return parameters;
248 }
249
250
251
252
253
254
255
256
257 public void removeParameters(String classname) {
258 algorithmParameters.remove(classname);
259 }
260
261
262
263
264
265
266
267 public void setGestureHandler(GestureHandler gestureHandler) {
268 this.gestureHandler = gestureHandler;
269 }
270
271
272
273
274
275
276
277 public GestureHandler getGestureHandler() {
278 return gestureHandler;
279 }
280
281
282
283
284
285
286
287 public void setMinAccuracy(double minAccuracy) {
288 double oldValue = this.minAccuracy;
289 this.minAccuracy = minAccuracy;
290 propertyChangeSupport.firePropertyChange(PROPERTY_MIN_ACCURACY, oldValue,
291 minAccuracy);
292 }
293
294
295
296
297
298
299
300 public double getMinAccuracy() {
301 return minAccuracy;
302 }
303
304
305 public void setName(String name) {
306 String oldValue = this.name;
307 this.name = name;
308 propertyChangeSupport.firePropertyChange(PROPERTY_NAME, oldValue, name);
309 }
310
311
312 public String getName() {
313 return this.name;
314 }
315
316
317
318
319
320
321
322 public void setMaxResultSetSize(int maxResultSetSize) {
323 int oldValue = maxResultSetSize;
324 this.maxResultSetSize = maxResultSetSize;
325 propertyChangeSupport.firePropertyChange(PROPERTY_MAX_RESULT_SET_SIZE,
326 oldValue, maxResultSetSize);
327 }
328
329
330
331
332
333
334
335 public int getMaxResultSetSize() {
336 return maxResultSetSize;
337 }
338
339
340
341
342
343
344 @Override
345 public Object clone() {
346 Configuration clone = null;
347
348 try {
349 clone = (Configuration)super.clone();
350
351 clone.algorithmParameters = new HashMap<String, HashMap<String, String>>();
352
353 for (String key : algorithmParameters.keySet()) {
354 HashMap<String, String> paramsClone = new HashMap<String, String>();
355 HashMap<String, String> paramsOriginal = algorithmParameters
356 .get(key);
357
358 for (String paramKey : paramsOriginal.keySet()) {
359 paramsClone
360 .put(paramKey, paramsOriginal.get(paramKey).toString());
361 }
362
363 clone.algorithmParameters.put(key, paramsClone);
364 }
365
366
367 clone.algorithms = new ArrayList<String>();
368
369 for (String s : algorithms) {
370 clone.algorithms.add(s.toString());
371 }
372
373
374 clone.gestureHandler = gestureHandler;
375
376
377 clone.gestureSets = new ArrayList<GestureSet>();
378 }
379 catch (CloneNotSupportedException e) {
380 LOGGER.log(Level.SEVERE, Constant.EMPTY_STRING, e);
381 }
382
383 return clone;
384 }
385
386
387 @Override
388 public void accept(Visitor visitor) {
389 visitor.visit(this);
390
391 for (GestureSet gestureSet : gestureSets) {
392 gestureSet.accept(visitor);
393 }
394
395 }
396
397
398 @Override
399 public String toString() {
400 return name;
401 }
402
403 }