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