1 package org.woehlke.computer.kurzweil.application;
2
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5 import lombok.*;
6 import lombok.extern.log4j.Log4j2;
7 import org.woehlke.computer.kurzweil.tabs.TabType;
8
9 import javax.validation.Valid;
10 import javax.validation.constraints.NotBlank;
11 import javax.validation.constraints.NotNull;
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.InputStream;
15 import java.util.jar.JarEntry;
16 import java.util.jar.JarFile;
17
18 @Log4j2
19 @ToString
20 @EqualsAndHashCode
21 @NoArgsConstructor
22 @AllArgsConstructor
23 @Valid
24
25 public class ComputerKurzweilProperties {
26
27 @Valid @Getter @Setter public Allinone allinone = new Allinone();
28 @Valid @Getter @Setter public Mandelbrot mandelbrot = new Mandelbrot();
29 @Valid @Getter @Setter public MandelbrotZoom mandelbrotZoom = new MandelbrotZoom();
30 @Valid @Getter @Setter public SimulatedEvolution simulatedevolution = new SimulatedEvolution();
31 @Valid @Getter @Setter public Cca cca = new Cca();
32 @Valid @Getter @Setter public WienerProcess randomwalk = new WienerProcess();
33 @Valid @Getter @Setter public Dla dla = new Dla();
34 @Valid @Getter @Setter public Kochsnowflake kochsnowflake = new Kochsnowflake();
35 @Valid @Getter @Setter public Samegame samegame = new Samegame();
36 @Valid @Getter @Setter public Sierpinskitriangle sierpinskitriangle = new Sierpinskitriangle();
37 @Valid @Getter @Setter public Tetris tetris = new Tetris();
38 @Valid @Getter @Setter public Turmite turmite = new Turmite();
39 @Valid @Getter @Setter public Wator wator = new Wator();
40 @Valid @Getter @Setter public Gameoflive gameoflive = new Gameoflive();
41
42 public static ComputerKurzweilProperties propertiesFactory(File conf){
43 log.info("propertiesFactory");
44 log.info("propertiesFactory conf: "+conf.getAbsolutePath());
45 ComputerKurzweilProperties properties;
46 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
47 try {
48 InputStream input = new FileInputStream(conf);
49 properties = mapper.readValue(input, ComputerKurzweilProperties.class);
50 log.info(properties.toString());
51 } catch (Exception e) {
52 e.printStackTrace();
53 properties = new ComputerKurzweilProperties();
54 }
55 log.info("propertiesFactory done");
56 return properties;
57 }
58
59 public static ComputerKurzweilProperties propertiesFactory(String conf, String jar){
60 log.info("propertiesFactory");
61 log.info("propertiesFactory conf: "+conf);
62 log.info("propertiesFactory jar: "+jar);
63 ComputerKurzweilProperties properties;
64 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
65 try {
66 JarFile jarFile = new JarFile(jar);
67 JarEntry entry = jarFile.getJarEntry(conf);
68 InputStream input = jarFile.getInputStream(entry);
69 properties = mapper.readValue(input, ComputerKurzweilProperties.class);
70 log.info(properties.toString());
71 } catch (Exception e) {
72 e.printStackTrace();
73 properties = new ComputerKurzweilProperties();
74 }
75 log.info("propertiesFactory done");
76 return properties;
77 }
78
79 public String getSubtitle(TabType tabType){
80 switch (tabType){
81 case CYCLIC_CELLULAR_AUTOMATON:
82 return this.getCca().getView().getSubtitle();
83 case DIFFUSION_LIMITED_AGGREGATION:
84 return this.getDla().getView().getSubtitle();
85 case SIMULATED_EVOLUTION:
86 return this.getSimulatedevolution().getView().getSubtitle();
87 case MANDELBROT_SET:
88 return this.getMandelbrot().getView().getSubtitle();
89 case RANDOM_WALK_WIENER_PROCESS:
90 return this.getRandomwalk().getView().getSubtitle();
91 case KOCH_SNOWFLAKE:
92 return this.getKochsnowflake().getView().getSubtitle();
93 case SAME_GAME:
94 return this.getSamegame().getView().getSubtitle();
95 case SIERPINSKI_TRIANGLE:
96 return this.getSierpinskitriangle().getView().getSubtitle();
97 case TETRIS:
98 return this.getTetris().getView().getSubtitle();
99 case TURMITE:
100 return this.getTurmite().getView().getSubtitle();
101 case WATOR:
102 return this.getWator().getView().getSubtitle();
103 case CONWAYS_GAME_OF_LIFE:
104 return this.getGameoflive().getView().getSubtitle();
105 default:
106 return "UNDEFINED";
107 }
108 }
109
110 public String getTitle(TabType tabType){
111 switch (tabType){
112 case CYCLIC_CELLULAR_AUTOMATON:
113 return this.getCca().getView().getTitle();
114 case DIFFUSION_LIMITED_AGGREGATION:
115 return this.getDla().getView().getTitle();
116 case SIMULATED_EVOLUTION:
117 return this.getSimulatedevolution().getView().getTitle();
118 case MANDELBROT_SET:
119 return this.getMandelbrot().getView().getTitle();
120 case RANDOM_WALK_WIENER_PROCESS:
121 return this.getRandomwalk().getView().getTitle();
122 case KOCH_SNOWFLAKE:
123 return this.getKochsnowflake().getView().getTitle();
124 case SAME_GAME:
125 return this.getSamegame().getView().getTitle();
126 case SIERPINSKI_TRIANGLE:
127 return this.getSierpinskitriangle().getView().getTitle();
128 case TETRIS:
129 return this.getTetris().getView().getTitle();
130 case TURMITE:
131 return this.getTurmite().getView().getTitle();
132 case WATOR:
133 return this.getWator().getView().getTitle();
134 case CONWAYS_GAME_OF_LIFE:
135 return this.getGameoflive().getView().getTitle();
136 default:
137 return "UNDEFINED";
138 }
139 }
140
141
142 @ToString
143 public static class Allinone {
144
145 @Valid @Getter @Setter public Lattice lattice = new Lattice();
146 @Valid @Getter @Setter public View view = new View();
147
148
149 @ToString
150 public static class Lattice {
151 @NotNull @Getter @Setter private Integer width;
152 @NotNull @Getter @Setter private Integer height;
153 }
154
155
156 @ToString
157 public static class View {
158 @NotBlank @Getter @Setter private String title;
159 @NotBlank @Getter @Setter private String subtitle;
160 @NotBlank @Getter @Setter private String copyright;
161 @NotNull @Getter @Setter private Integer borderPaddingX;
162 @NotNull @Getter @Setter private Integer borderPaddingY;
163 @NotNull @Getter @Setter private Integer titleHeight;
164 @NotBlank @Getter @Setter private String startStopp;
165 @NotBlank @Getter @Setter private String start;
166 @NotBlank @Getter @Setter private String stop;
167 @NotBlank @Getter @Setter private String info;
168 }
169 }
170
171
172 @ToString
173 public static class Mandelbrot {
174
175 @Valid @Getter @Setter public View view = new View();
176 @Valid @Getter @Setter public Control control = new Control();
177
178
179 @ToString
180 public static class View {
181 @NotBlank @Getter @Setter private String title;
182 @NotBlank @Getter @Setter private String subtitle;
183 @NotBlank @Getter @Setter private String buttonsZoom;
184 @NotBlank @Getter @Setter private String buttonsZoomOut;
185 @NotBlank @Getter @Setter private String buttonsSwitch;
186 @NotBlank @Getter @Setter private String buttonsZoomLabel;
187 @NotBlank @Getter @Setter private String buttonsLabel;
188 }
189
190
191 @ToString
192 public static class Control {
193 @NotNull @Getter @Setter private Integer threadSleepTime;
194 }
195 }
196
197
198 @ToString
199 public static class MandelbrotZoom {
200
201 @Valid @Getter @Setter public View view = new View();
202 @Valid @Getter @Setter public Control control = new Control();
203
204
205 @ToString
206 public static class View {
207 @NotBlank @Getter @Setter private String title;
208 @NotBlank @Getter @Setter private String subtitle;
209 @NotBlank @Getter @Setter private String buttonsZoom;
210 @NotBlank @Getter @Setter private String buttonsZoomOut;
211 @NotBlank @Getter @Setter private String buttonsSwitch;
212 @NotBlank @Getter @Setter private String buttonsZoomLabel;
213 @NotBlank @Getter @Setter private String buttonsLabel;
214 }
215
216
217 @ToString
218 public static class Control {
219 @NotNull @Getter @Setter private Integer threadSleepTime;
220 }
221 }
222
223
224 @ToString
225 public static class SimulatedEvolution {
226
227 @Valid @Getter @Setter public View view = new View();
228 @Valid @Getter @Setter public Control control = new Control();
229 @Valid @Getter @Setter public CellConf cellConf = new CellConf();
230 @Valid @Getter @Setter public Population population = new Population();
231 @Valid @Getter @Setter public Food food = new Food();
232 @Valid @Getter @Setter public GardenOfEden gardenOfEden = new GardenOfEden();
233
234
235 @ToString
236 public static class View {
237 @NotBlank @Getter @Setter private String title;
238 @NotBlank @Getter @Setter private String subtitle;
239 }
240
241
242 @ToString
243 public static class Control {
244 @NotNull @Getter @Setter private Integer threadSleepTime;
245 @NotNull @Getter @Setter private Integer exitStatus;
246 @NotNull @Getter @Setter private Integer queueMaxLength;
247 }
248
249
250 @ToString
251 public static class CellConf {
252 @NotNull @Getter @Setter private Integer fatMax;
253 @NotNull @Getter @Setter private Integer fatHungerMax;
254 @NotNull @Getter @Setter private Integer fatMinimumForSex;
255 @NotNull @Getter @Setter private Integer fatAtBirth;
256 @NotNull @Getter @Setter private Integer fatPerFood;
257 @NotNull @Getter @Setter private Integer ageOfAdulthood;
258 @NotNull @Getter @Setter private Integer ageOld;
259 @NotNull @Getter @Setter private Integer ageMax;
260 }
261
262
263 @ToString
264 public static class Population {
265 @NotNull @Getter @Setter private Integer initialPopulation;
266 @NotBlank @Getter @Setter private String panelPopulationStatistics;
267 @NotBlank @Getter @Setter private String panelLifeCycleStatistics;
268 @NotBlank @Getter @Setter private String youngCellsLabel;
269 @NotBlank @Getter @Setter private String youngAndFatCellsLabel;
270 @NotBlank @Getter @Setter private String fullAgeCellsLabel;
271 @NotBlank @Getter @Setter private String hungryCellsLabel;
272 @NotBlank @Getter @Setter private String oldCellsLabel;
273 @NotBlank @Getter @Setter private String populationLabel;
274 @NotBlank @Getter @Setter private String generationOldestLabel;
275 @NotBlank @Getter @Setter private String generationYoungestLabel;
276 }
277
278
279 @ToString
280 public static class Food {
281 @NotNull @Getter @Setter private Integer foodPerDay;
282 @NotNull @Getter @Setter private Integer foodPerDayFieldColumns;
283 @NotBlank @Getter @Setter private String foodPerDayLabel;
284 @NotBlank @Getter @Setter private String foodPerDayBorderLabel;
285 @NotBlank @Getter @Setter private String buttonFoodPerDayIncrease;
286 @NotBlank @Getter @Setter private String buttonFoodPerDayDecrease;
287 @NotBlank @Getter @Setter private String panelFood;
288 }
289
290
291 @ToString
292 public static class GardenOfEden {
293 @NotBlank @Getter @Setter private String panelGardenOfEden;
294 @NotNull @Getter @Setter private Boolean gardenOfEdenEnabled;
295 @NotBlank @Getter @Setter private String gardenOfEdenEnabledString;
296 @NotBlank @Getter @Setter private String gardenOfEdenEnabledToggleButton;
297 @NotNull @Getter @Setter private Integer foodPerDay;
298 @NotNull @Getter @Setter private Integer gardenOfEdenLatticeDivisor;
299 @NotNull @Getter @Setter private Integer gardenOfEdenLatticeDivisorPadding;
300 }
301 }
302
303
304 @ToString
305 public static class Cca {
306
307 @Valid @Getter @Setter public View view = new View();
308 @Valid @Getter @Setter public Control control = new Control();
309
310
311 @ToString
312 public static class View {
313
314 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
315 @NotBlank @Getter @Setter private String title;
316 @NotBlank @Getter @Setter private String subtitle;
317
318
319 @ToString
320 public static class Neighborhood {
321 @NotBlank @Getter @Setter private String title;
322 @NotBlank @Getter @Setter private String typeVonNeumann;
323 @NotBlank @Getter @Setter private String typeMoore;
324 @NotBlank @Getter @Setter private String typeWoehlke;
325 }
326 }
327
328
329 @ToString
330 public static class Control {
331 @NotNull @Getter @Setter private Integer threadSleepTime;
332 }
333 }
334
335
336 @ToString
337 public static class WienerProcess {
338
339 @Valid @Getter @Setter public View view = new View();
340 @Valid @Getter @Setter public Control control = new Control();
341
342
343 @ToString
344 public static class View {
345
346 @NotBlank @Getter @Setter private String title;
347 @NotBlank @Getter @Setter private String subtitle;
348 }
349
350
351 @ToString
352 public static class Control {
353 @NotNull @Getter @Setter private Integer threadSleepTime;
354 }
355 }
356
357
358 @ToString
359 public static class Dla {
360
361 @Valid @Getter @Setter public View view = new View();
362 @Valid @Getter @Setter public Control control = new Control();
363
364
365 @ToString
366 public static class View {
367 @NotBlank @Getter @Setter private String title;
368 @NotBlank @Getter @Setter private String subtitle;
369 }
370
371
372 @ToString
373 public static class Control {
374 @NotNull @Getter @Setter private Integer threadSleepTime;
375 @NotNull @Getter @Setter private Integer numberOfParticles;
376 }
377 }
378
379 @ToString
380 public static class Kochsnowflake {
381
382 @Valid @Getter @Setter public View view = new View();
383 @Valid @Getter @Setter public Control control = new Control();
384
385
386 @ToString
387 public static class View {
388 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
389 @NotBlank @Getter @Setter private String title;
390 @NotBlank @Getter @Setter private String subtitle;
391
392
393 @ToString
394 public static class Neighborhood {
395 @NotBlank @Getter @Setter private String title;
396 @NotBlank @Getter @Setter private String typeVonNeumann;
397 @NotBlank @Getter @Setter private String typeMoore;
398 @NotBlank @Getter @Setter private String typeWoehlke;
399 }
400 }
401
402
403 @ToString
404 public static class Control {
405 @NotNull @Getter @Setter private Integer threadSleepTime;
406 @NotNull @Getter @Setter private Integer numberOfParticles;
407 }
408 }
409
410 @ToString
411 public static class Samegame {
412
413 @Valid @Getter @Setter public View view = new View();
414 @Valid @Getter @Setter public Control control = new Control();
415
416
417 @ToString
418 public static class View {
419 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
420 @NotBlank @Getter @Setter private String title;
421 @NotBlank @Getter @Setter private String subtitle;
422
423
424 @ToString
425 public static class Neighborhood {
426 @NotBlank @Getter @Setter private String title;
427 @NotBlank @Getter @Setter private String typeVonNeumann;
428 @NotBlank @Getter @Setter private String typeMoore;
429 @NotBlank @Getter @Setter private String typeWoehlke;
430 }
431 }
432
433
434 @ToString
435 public static class Control {
436 @NotNull @Getter @Setter private Integer threadSleepTime;
437 @NotNull @Getter @Setter private Integer numberOfParticles;
438 }
439 }
440
441 @ToString
442 public static class Sierpinskitriangle {
443
444 @Valid @Getter @Setter public View view = new View();
445 @Valid @Getter @Setter public Control control = new Control();
446
447
448 @ToString
449 public static class View {
450 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
451 @NotBlank @Getter @Setter private String title;
452 @NotBlank @Getter @Setter private String subtitle;
453
454
455 @ToString
456 public static class Neighborhood {
457 @NotBlank @Getter @Setter private String title;
458 @NotBlank @Getter @Setter private String typeVonNeumann;
459 @NotBlank @Getter @Setter private String typeMoore;
460 @NotBlank @Getter @Setter private String typeWoehlke;
461 }
462 }
463
464
465 @ToString
466 public static class Control {
467 @NotNull @Getter @Setter private Integer threadSleepTime;
468 @NotNull @Getter @Setter private Integer numberOfParticles;
469 }
470 }
471
472 @ToString
473 public static class Tetris {
474
475 @Valid @Getter @Setter public View view = new View();
476 @Valid @Getter @Setter public Control control = new Control();
477
478
479 @ToString
480 public static class View {
481 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
482 @NotBlank @Getter @Setter private String title;
483 @NotBlank @Getter @Setter private String subtitle;
484
485
486 @ToString
487 public static class Neighborhood {
488 @NotBlank @Getter @Setter private String title;
489 @NotBlank @Getter @Setter private String typeVonNeumann;
490 @NotBlank @Getter @Setter private String typeMoore;
491 @NotBlank @Getter @Setter private String typeWoehlke;
492 }
493 }
494
495
496 @ToString
497 public static class Control {
498 @NotNull @Getter @Setter private Integer threadSleepTime;
499 @NotNull @Getter @Setter private Integer numberOfParticles;
500 }
501 }
502
503 @ToString
504 public static class Turmite {
505
506 @Valid @Getter @Setter public View view = new View();
507 @Valid @Getter @Setter public Control control = new Control();
508
509
510 @ToString
511 public static class View {
512 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
513 @NotBlank @Getter @Setter private String title;
514 @NotBlank @Getter @Setter private String subtitle;
515
516
517 @ToString
518 public static class Neighborhood {
519 @NotBlank @Getter @Setter private String title;
520 @NotBlank @Getter @Setter private String typeVonNeumann;
521 @NotBlank @Getter @Setter private String typeMoore;
522 @NotBlank @Getter @Setter private String typeWoehlke;
523 }
524 }
525
526
527 @ToString
528 public static class Control {
529 @NotNull @Getter @Setter private Integer threadSleepTime;
530 @NotNull @Getter @Setter private Integer numberOfParticles;
531 }
532 }
533
534 @ToString
535 public static class Wator {
536
537 @Valid @Getter @Setter public View view = new View();
538 @Valid @Getter @Setter public Control control = new Control();
539
540
541 @ToString
542 public static class View {
543 @Valid @Getter @Setter public Neighborhood neighborhood = new Neighborhood();
544 @NotBlank @Getter @Setter private String title;
545 @NotBlank @Getter @Setter private String subtitle;
546 @NotBlank @Getter @Setter private String buttonsZoom;
547 @NotBlank @Getter @Setter private String buttonsZoomOut;
548 @NotBlank @Getter @Setter private String buttonsSwitch;
549 @NotBlank @Getter @Setter private String buttonsZoomLabel;
550 @NotBlank @Getter @Setter private String buttonsLabel;
551
552
553 @ToString
554 public static class Neighborhood {
555 @NotBlank @Getter @Setter private String title;
556 @NotBlank @Getter @Setter private String typeVonNeumann;
557 @NotBlank @Getter @Setter private String typeMoore;
558 @NotBlank @Getter @Setter private String typeWoehlke;
559 }
560 }
561
562
563 @ToString
564 public static class Control {
565 @NotNull @Getter @Setter private Integer threadSleepTime;
566 @NotNull @Getter @Setter private Integer numberOfParticles;
567 }
568 }
569
570 @ToString
571 public static class Gameoflive{
572
573 @Valid @Getter @Setter public View view = new View();
574 @Valid @Getter @Setter public Control control = new Control();
575
576
577 @ToString
578 public static class View {
579 @Valid @Getter @Setter public ComputerKurzweilProperties.Wator.View.Neighborhood neighborhood = new Wator.View.Neighborhood();
580 @NotBlank @Getter @Setter private String title;
581 @NotBlank @Getter @Setter private String subtitle;
582
583
584 @ToString
585 public static class Neighborhood {
586 @NotBlank @Getter @Setter private String title;
587 @NotBlank @Getter @Setter private String typeVonNeumann;
588 @NotBlank @Getter @Setter private String typeMoore;
589 @NotBlank @Getter @Setter private String typeWoehlke;
590 }
591 }
592
593
594 @ToString
595 public static class Control {
596 @NotNull @Getter @Setter private Integer threadSleepTime;
597 @NotNull @Getter @Setter private Integer numberOfParticles;
598 }
599 }
600 }