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