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 package org.ximtec.igesture.geco;
27
28 import java.io.File;
29 import java.util.List;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32
33 import org.apache.commons.configuration.ConfigurationException;
34 import org.apache.commons.configuration.XMLConfiguration;
35 import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
36 import org.sigtec.util.Constant;
37 import org.sigtec.util.FileHandler;
38
39
40
41
42
43
44
45
46 public class Configuration {
47
48 private static final Logger LOGGER = Logger.getLogger(Configuration.class
49 .getName());
50
51 private static final String ALL_INPUT_DEVICES = "inputdevices/device/@name";
52 private static final String SELECTED_INPUT_DEVICE = "inputdevices/device[@selected='true']/@name";
53 private static final String SELECTED_INPUT_DEVICE2 = "inputdevices/device/name";
54
55 private static final String PROPERTY_DATABASE = "database";
56 private static final String PROPERTY_ALGORITHM = "algorithm/class";
57 private static final String PROPERTY_TAB = "tab/class";
58
59 private static final String MINIMIZE = "minimize";
60 private static final String LAST_PROJECT = "lastproject";
61
62 private static final String TRUE = "true";
63
64 private XMLConfiguration configuration;
65
66
67 public Configuration(String file) {
68 try {
69 File confFile = FileHandler.getResource(file);
70 configuration = new XMLConfiguration();
71 configuration.setFileName(confFile.getPath());
72 configuration.setExpressionEngine(new XPathExpressionEngine());
73 configuration.setAutoSave(true);
74 configuration.load();
75 selectDevice();
76 }
77 catch (ConfigurationException e) {
78 LOGGER.log(Level.SEVERE, Constant.EMPTY_STRING, e);
79 }
80
81 }
82
83
84
85
86
87
88
89 public String getDatabase() {
90 return configuration.getString(PROPERTY_DATABASE);
91 }
92
93
94
95
96
97
98
99 @SuppressWarnings("unchecked")
100 public List<String> getAlgorithms() {
101 return configuration.getList(PROPERTY_ALGORITHM);
102 }
103
104
105
106
107
108
109
110 @SuppressWarnings("unchecked")
111 public List<String> getTabs() {
112 return configuration.getList(PROPERTY_TAB);
113 }
114
115
116
117
118
119
120
121
122
123
124 @SuppressWarnings("unchecked")
125 public String getInputDeviceName() {
126 List<String> list = configuration.getList(SELECTED_INPUT_DEVICE);
127 if (!list.isEmpty()) {
128 return list.get(0);
129 }
130 return null;
131 }
132
133
134
135
136
137
138
139
140 @SuppressWarnings("unchecked")
141 public String getMostRecentProject() {
142 List<String> list = configuration.getList(LAST_PROJECT);
143 if (!list.isEmpty()) {
144 return list.get(0);
145 }
146 return null;
147 }
148
149
150
151
152
153
154
155
156 @SuppressWarnings("unchecked")
157 public boolean getMinimize() {
158 List<String> list = configuration.getList(MINIMIZE);
159 if (!list.isEmpty()) {
160 if ((list.get(0)).equals(TRUE)) {
161 return true;
162 }
163 else {
164 return false;
165 }
166 }
167 return false;
168 }
169
170
171
172
173
174
175
176
177 @SuppressWarnings("unchecked")
178 public List<String> getInputDevices() {
179 List<String> list = configuration.getList(ALL_INPUT_DEVICES);
180 return list;
181 }
182
183
184
185
186
187 @SuppressWarnings("unchecked")
188 private synchronized void selectDevice() {
189 int i = 1;
190
191 for (String deviceName : (List<String>)configuration
192 .getList(SELECTED_INPUT_DEVICE2)) {
193
194
195 i++;
196 }
197
198 }
199
200 }