1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.web;
9
10 import java.util.HashMap;
11 import java.util.LinkedList;
12 import java.util.List;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17 import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
18 import com.buckosoft.PicMan.business.PicManFacade;
19 import com.buckosoft.PicMan.business.mosaic.MosaicEngine;
20 import com.buckosoft.PicMan.business.mosaic.MosaicEngine.ConfigItem;
21 import com.buckosoft.PicMan.business.util.Classes;
22 import com.buckosoft.PicMan.domain.Mosaic;
23 import com.buckosoft.PicMan.domain.MosaicBatch;
24 import com.buckosoft.PicMan.domain.Set;
25
26
27
28
29
30 public class MosaicSetupForm {
31 private final static boolean DEBUG = true;
32 protected final Log logger = LogFactory.getLog(getClass());
33
34 private BSAccountUserWebSession userWebSession;
35 private Mosaic mosaic;
36 private String masterPic;
37 private int mosaicHeight;
38 private String mosaicOutputFile;
39
40
41 private int mosaicSid;
42 private List<Set> sets;
43 private boolean startBuilding;
44 private boolean makeBackups = true;
45 private String mosaicName = "New Mosaic";
46 private List<Mosaic> mosaics;
47 private List<MosaicBatch> mosaicBatches;
48
49 private String mosaicEngineName;
50 private List<String> engines;
51 private String mosaicSelectName = "";
52 private boolean batchMode = false;
53 private String mosaicSizes;
54
55 private String mosaicEngineConfig;
56 private String mosaicConfigs;
57
58 @SuppressWarnings("unused")
59 private PicManFacade pmf;
60
61
62
63
64 public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
65
66 public BSAccountUserWebSession getUserWebSession() { return(userWebSession); }
67 public void setUserWebSession(BSAccountUserWebSession us) { userWebSession = us; }
68
69
70
71
72
73 public String getMasterPic() {
74 return masterPic;
75 }
76
77
78
79 public void setMasterPic(String masterPic) {
80 this.masterPic = masterPic;
81 }
82
83
84
85 public Mosaic getMosaic() {
86 return mosaic;
87 }
88
89
90
91 public void setMosaic(Mosaic mosaic) {
92 this.mosaic = mosaic;
93 }
94
95
96
97
98 public String getMosaicSelectName() {
99 return mosaicSelectName;
100 }
101
102
103
104 public void setMosaicSelectName(String mosaicSelectName) {
105 this.mosaicSelectName = mosaicSelectName;
106 }
107
108
109
110 public String getMosaicName() {
111 return mosaicName;
112 }
113
114
115
116 public void setMosaicName(String mosaicName) {
117 this.mosaicName = mosaicName;
118 }
119
120
121
122
123 public List<Mosaic> getMosaics() {
124 return mosaics;
125 }
126
127
128
129 public void setMosaics(List<Mosaic> mosaics) {
130 this.mosaics = mosaics;
131 }
132
133
134
135
136 public void setMosaicBatches(List<MosaicBatch> mbatches) {
137 this.mosaicBatches = mbatches;
138 }
139
140
141
142 public List<MosaicBatch> getMosaicBatches() {
143 return mosaicBatches;
144 }
145
146
147
148 public String getMosaicEngineName() {
149 return mosaicEngineName;
150 }
151
152
153
154 public void setMosaicEngineName(String mosaicEngineName) {
155 this.mosaicEngineName = mosaicEngineName;
156 }
157
158
159
160 public List<String> getEngines() {
161 return engines;
162 }
163
164
165
166 public void setEngines(List<String> engines) {
167 this.engines = engines;
168 }
169
170
171
172 public int getMosaicHeight() {
173 return mosaicHeight;
174 }
175
176
177
178 public void setMosaicHeight(int mosaicHeight) {
179 this.mosaicHeight = mosaicHeight;
180 }
181
182
183
184
185 public String getMosaicOutputFile() {
186 return mosaicOutputFile;
187 }
188
189
190
191 public void setMosaicOutputFile(String mosaicOutputFile) {
192 this.mosaicOutputFile = mosaicOutputFile;
193 }
194
195
196
197 public boolean isStartBuilding() {
198 return startBuilding;
199 }
200
201
202
203 public void setStartBuilding(boolean startBuilding) {
204 this.startBuilding = startBuilding;
205 }
206
207
208
209
210 public boolean isMakeBackups() {
211 return makeBackups;
212 }
213
214
215
216
217 public void setMakeBackups(boolean makeBackups) {
218 this.makeBackups = makeBackups;
219 }
220
221
222
223 public int getMosaicSid() {
224 return mosaicSid;
225 }
226
227
228
229 public void setMosaicSid(int mosaicSid) {
230 this.mosaicSid = mosaicSid;
231 }
232
233
234
235 public List<Set> getSets() {
236 return sets;
237 }
238
239
240
241 public void setSets(List<Set> sets) {
242 this.sets = sets;
243 }
244
245
246
247 public boolean isBatchMode() {
248 return batchMode;
249 }
250
251
252
253 public void setBatchMode(boolean batchMode) {
254 this.batchMode = batchMode;
255 }
256
257
258
259 public String getMosaicSizes() {
260 return mosaicSizes;
261 }
262
263
264
265 public void setMosaicSizes(String mosaicSizes) {
266 this.mosaicSizes = mosaicSizes;
267 }
268
269
270
271
272 public String getMosaicEngineConfig() {
273 return mosaicEngineConfig;
274 }
275
276
277
278
279 public void setMosaicEngineConfig(String mosaicEngineConfig) {
280 this.mosaicEngineConfig = mosaicEngineConfig;
281 }
282
283
284
285
286 public String getMosaicConfigs() {
287 return mosaicConfigs;
288 }
289
290
291
292
293 public void setMosaicConfigs(String mosaicConfigs) {
294 this.mosaicConfigs = mosaicConfigs;
295 }
296
297
298
299
300
301
302
303
304
305 public static class MosaicConfig {
306 public String engineConfig;
307 public String mosaicConfig;
308 public List<String> engines;
309
310 }
311
312 public static MosaicConfig getConfigs(List<Mosaic> list) {
313 MosaicConfig mosaicConfig = new MosaicConfig();
314 mosaicConfig.engines = new LinkedList<String>();
315 StringBuffer sb = new StringBuffer();
316 sb.append("var mosaicConfigs = new Array();\n");
317 for (Mosaic mb : list) {
318 if (!mb.getEngineConfig().isEmpty()) {
319 sb.append("mosaicConfigs[" + mb.getMid() + "] = [\n");
320 for (String key : mb.getEngineConfig().keySet()) {
321 sb.append("new KeyValue(\"" + key + "\",\"" + mb.getEngineConfig().get(key) + "\"),\n");
322 }
323 sb.append("];\n");
324 }
325 }
326 mosaicConfig.mosaicConfig = sb.toString();
327
328
329
330
331
332
333
334
335
336
337
338 int i;
339 sb.setLength(0);
340 String[] cl = Classes.getClasses("com.buckosoft.PicMan.business.mosaic.engine");
341
342 for (i=0; i<cl.length; i++) {
343 if (cl[i].indexOf('$') != -1)
344 continue;
345 mosaicConfig.engines.add(cl[i]);
346 addEngineConfig(sb, cl[i]);
347 }
348 if (DEBUG) {
349 for (i=0; i<cl.length; i++) {
350
351 }
352 }
353 mosaicConfig.engineConfig = sb.toString();
354
355 return(mosaicConfig);
356 }
357
358 private static void addEngineConfig(StringBuffer sb, String className) {
359 MosaicEngine mosaicEngine;
360
361 try {
362 mosaicEngine = (MosaicEngine)Class.forName("com.buckosoft.PicMan.business.mosaic.engine."
363 + className).newInstance();
364 } catch (Exception e) {
365 Exception ex = new Exception("Can't instantiate Mosaic Engine: " + className, e);
366 LogFactory.getLog(MosaicSetupForm.class).warn("addEngineConfig", ex);
367
368 sb.append("engineConfigArray[\"" + className + "\"]=\"<tr><td colspan=\"2\">addEngineConfig Can't instantiate '" + className + "'</td></tr>\";\n");
369 return;
370 }
371 HashMap<String, ConfigItem> configMap = mosaicEngine.getConfigMap();
372 if (configMap.isEmpty())
373 return;
374 sb.append("engineConfigArray[\"" + className + "\"]=\'");
375 int flipFlop = 0;
376 for (String key : configMap.keySet()) {
377 ConfigItem item = configMap.get(key);
378 sb.append("<tr class=\"back" + flipFlop + "\"><td>");
379 sb.append(item.getDescription());
380 sb.append("</td><td><input type=\"text\" name=\"");
381 sb.append(key);
382 sb.append("\" id=\"inp_");
383 sb.append(key);
384 sb.append("\" value=\"");
385 if (item.getType() == ConfigItem.TYPE_INT)
386 sb.append("" + item.getValueInt());
387 sb.append("\"/>");
388 flipFlop++;
389 if (flipFlop >= 2)
390 flipFlop = 0;
391 }
392 sb.append("';\n");
393 }
394
395
396 }