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
28 @Getter
29 @Setter
30 public Allinone allinone = new Allinone();
31 @Valid
32 @Getter
33 @Setter
34 public Mandelbrot mandelbrot = new Mandelbrot();
35 @Valid
36 @Getter
37 @Setter
38 public SimulatedEvolution simulatedevolution = new SimulatedEvolution();
39 @Valid
40 @Getter
41 @Setter
42 public Cca cca = new Cca();
43 @Valid
44 @Getter
45 @Setter
46 public WienerProcess randomwalk = new WienerProcess();
47 @Valid
48 @Getter
49 @Setter
50 public Dla dla = new Dla();
51 @Valid
52 @Getter
53 @Setter
54 public Kochsnowflake kochsnowflake = new Kochsnowflake();
55 @Valid
56 @Getter
57 @Setter
58 public Samegame samegame = new Samegame();
59 @Valid
60 @Getter
61 @Setter
62 public Sierpinskitriangle sierpinskitriangle = new Sierpinskitriangle();
63 @Valid
64 @Getter
65 @Setter
66 public Tetris tetris = new Tetris();
67 @Valid
68 @Getter
69 @Setter
70 public Turmite turmite = new Turmite();
71 @Valid
72 @Getter
73 @Setter
74 public Wator wator = new Wator();
75 @Valid
76 @Getter
77 @Setter
78 public Gameoflive gameoflive = new Gameoflive();
79
80
81 @ToString
82 public static class Allinone {
83
84 @Valid
85 @Getter
86 @Setter
87 public Lattice lattice = new Lattice();
88 @Valid
89 @Getter
90 @Setter
91 public View view = new View();
92
93
94 @ToString
95 public static class Lattice {
96 @NotNull
97 @Getter
98 @Setter
99 private Integer width;
100 @NotNull
101 @Getter
102 @Setter
103 private Integer height;
104 }
105
106
107 @ToString
108 public static class View {
109 @NotBlank
110 @Getter
111 @Setter
112 private String title;
113 @NotBlank
114 @Getter
115 @Setter
116 private String subtitle;
117 @NotBlank
118 @Getter
119 @Setter
120 private String copyright;
121 @NotNull
122 @Getter
123 @Setter
124 private Integer borderPaddingX;
125 @NotNull
126 @Getter
127 @Setter
128 private Integer borderPaddingY;
129 @NotNull
130 @Getter
131 @Setter
132 private Integer titleHeight;
133 @NotBlank
134 @Getter
135 @Setter
136 private String startStopp;
137 @NotBlank
138 @Getter
139 @Setter
140 private String start;
141 @NotBlank
142 @Getter
143 @Setter
144 private String stop;
145 @NotBlank
146 @Getter
147 @Setter
148 private String info;
149 }
150 }
151
152
153 @ToString
154 public static class Mandelbrot {
155
156 @Valid
157 @Getter
158 @Setter
159 public View view = new View();
160 @Valid
161 @Getter
162 @Setter
163 public Control control = new Control();
164
165
166 @ToString
167 public static class View {
168 @NotBlank
169 @Getter
170 @Setter
171 private String title;
172 @NotBlank
173 @Getter
174 @Setter
175 private String subtitle;
176 @NotBlank
177 @Getter
178 @Setter
179 private String buttonsZoom;
180 @NotBlank
181 @Getter
182 @Setter
183 private String buttonsZoomOut;
184 @NotBlank
185 @Getter
186 @Setter
187 private String buttonsSwitch;
188 @NotBlank
189 @Getter
190 @Setter
191 private String buttonsZoomLabel;
192 @NotBlank
193 @Getter
194 @Setter
195 private String buttonsLabel;
196 }
197
198
199 @ToString
200 public static class Control {
201 @NotNull
202 @Getter
203 @Setter
204 private Integer threadSleepTime;
205 }
206 }
207
208
209 @ToString
210 public static class SimulatedEvolution {
211
212 @Valid
213 @Getter
214 @Setter
215 public View view = new View();
216 @Valid
217 @Getter
218 @Setter
219 public Control control = new Control();
220 @Valid
221 @Getter
222 @Setter
223 public CellConf cellConf = new CellConf();
224 @Valid
225 @Getter
226 @Setter
227 public Population population = new Population();
228 @Valid
229 @Getter
230 @Setter
231 public Food food = new Food();
232 @Valid
233 @Getter
234 @Setter
235 public GardenOfEden gardenOfEden = new GardenOfEden();
236
237
238 @ToString
239 public static class View {
240 @NotBlank
241 @Getter
242 @Setter
243 private String title;
244 @NotBlank
245 @Getter
246 @Setter
247 private String subtitle;
248 }
249
250
251 @ToString
252 public static class Control {
253 @NotNull
254 @Getter
255 @Setter
256 private Integer threadSleepTime;
257 @NotNull
258 @Getter
259 @Setter
260 private Integer exitStatus;
261 @NotNull
262 @Getter
263 @Setter
264 private Integer queueMaxLength;
265 }
266
267
268 @ToString
269 public static class CellConf {
270 @NotNull
271 @Getter
272 @Setter
273 private Integer fatMax;
274 @NotNull
275 @Getter
276 @Setter
277 private Integer fatHungerMax;
278 @NotNull
279 @Getter
280 @Setter
281 private Integer fatMinimumForSex;
282 @NotNull
283 @Getter
284 @Setter
285 private Integer fatAtBirth;
286 @NotNull
287 @Getter
288 @Setter
289 private Integer fatPerFood;
290 @NotNull
291 @Getter
292 @Setter
293 private Integer ageOfAdulthood;
294 @NotNull
295 @Getter
296 @Setter
297 private Integer ageOld;
298 @NotNull
299 @Getter
300 @Setter
301 private Integer ageMax;
302 }
303
304
305 @ToString
306 public static class Population {
307 @NotNull
308 @Getter
309 @Setter
310 private Integer initialPopulation;
311 @NotBlank
312 @Getter
313 @Setter
314 private String panelPopulationStatistics;
315 @NotBlank
316 @Getter
317 @Setter
318 private String youngCellsLabel;
319 @NotBlank
320 @Getter
321 @Setter
322 private String youngAndFatCellsLabel;
323 @NotBlank
324 @Getter
325 @Setter
326 private String fullAgeCellsLabel;
327 @NotBlank
328 @Getter
329 @Setter
330 private String hungryCellsLabel;
331 @NotBlank
332 @Getter
333 @Setter
334 private String oldCellsLabel;
335 @NotBlank
336 @Getter
337 @Setter
338 private String populationLabel;
339 @NotBlank
340 @Getter
341 @Setter
342 private String generationOldestLabel;
343 @NotBlank
344 @Getter
345 @Setter
346 private String generationYoungestLabel;
347 }
348
349
350 @ToString
351 public static class Food {
352 @NotNull
353 @Getter
354 @Setter
355 private Integer foodPerDay;
356 @NotNull
357 @Getter
358 @Setter
359 private Integer foodPerDayFieldColumns;
360 @NotBlank
361 @Getter
362 @Setter
363 private String foodPerDayLabel;
364 @NotBlank
365 @Getter
366 @Setter
367 private String foodPerDayBorderLabel;
368 @NotBlank
369 @Getter
370 @Setter
371 private String buttonFoodPerDayIncrease;
372 @NotBlank
373 @Getter
374 @Setter
375 private String buttonFoodPerDayDecrease;
376 @NotBlank
377 @Getter
378 @Setter
379 private String panelFood;
380 }
381
382
383 @ToString
384 public static class GardenOfEden {
385 @NotBlank
386 @Getter
387 @Setter
388 private String panelGardenOfEden;
389 @NotNull
390 @Getter
391 @Setter
392 private Boolean gardenOfEdenEnabled;
393 @NotBlank
394 @Getter
395 @Setter
396 private String gardenOfEdenEnabledString;
397 @NotBlank
398 @Getter
399 @Setter
400 private String gardenOfEdenEnabledToggleButton;
401 @NotNull
402 @Getter
403 @Setter
404 private Integer foodPerDay;
405 @NotNull
406 @Getter
407 @Setter
408 private Integer gardenOfEdenLatticeDivisor;
409 @NotNull
410 @Getter
411 @Setter
412 private Integer gardenOfEdenLatticeDivisorPadding;
413 }
414 }
415
416
417 @ToString
418 public static class Cca {
419
420 @Valid
421 @Getter
422 @Setter
423 public View view = new View();
424 @Valid
425 @Getter
426 @Setter
427 public Control control = new Control();
428
429
430 @ToString
431 public static class View {
432
433 @NotBlank
434 @Getter
435 @Setter
436 private String title;
437 @NotBlank
438 @Getter
439 @Setter
440 private String subtitle;
441
442 @Valid
443 @Getter
444 @Setter
445 public Neighborhood neighborhood = new Neighborhood();
446
447
448 @ToString
449 public static class Neighborhood {
450 @NotBlank
451 @Getter
452 @Setter
453 private String title;
454 @NotBlank
455 @Getter
456 @Setter
457 private String typeVonNeumann;
458 @NotBlank
459 @Getter
460 @Setter
461 private String typeMoore;
462 @NotBlank
463 @Getter
464 @Setter
465 private String typeWoehlke;
466 }
467 }
468
469
470 @ToString
471 public static class Control {
472 @NotNull
473 @Getter
474 @Setter
475 private Integer threadSleepTime;
476 }
477 }
478
479
480 @ToString
481 public static class WienerProcess {
482
483 @Valid
484 @Getter
485 @Setter
486 public View view = new View();
487 @Valid
488 @Getter
489 @Setter
490 public Control control = new Control();
491
492
493 @ToString
494 public static class View {
495
496 @NotBlank
497 @Getter
498 @Setter
499 private String title;
500 @NotBlank
501 @Getter
502 @Setter
503 private String subtitle;
504 }
505
506
507 @ToString
508 public static class Control {
509 @NotNull
510 @Getter
511 @Setter
512 private Integer threadSleepTime;
513 }
514 }
515
516
517 @ToString
518 public static class Dla {
519
520 @Valid
521 @Getter
522 @Setter
523 public View view = new View();
524 @Valid
525 @Getter
526 @Setter
527 public Control control = new Control();
528
529
530 @ToString
531 public static class View {
532 @NotBlank
533 @Getter
534 @Setter
535 private String title;
536 @NotBlank
537 @Getter
538 @Setter
539 private String subtitle;
540 }
541
542
543 @ToString
544 public static class Control {
545 @NotNull
546 @Getter
547 @Setter
548 private Integer threadSleepTime;
549 @NotNull
550 @Getter
551 @Setter
552 private Integer numberOfParticles;
553 }
554 }
555
556 @ToString
557 public static class Kochsnowflake {
558
559 @Valid
560 @Getter
561 @Setter
562 public View view = new View();
563 @Valid
564 @Getter
565 @Setter
566 public Control control = new Control();
567
568
569 @ToString
570 public static class View {
571 @NotBlank
572 @Getter
573 @Setter
574 private String title;
575 @NotBlank
576 @Getter
577 @Setter
578 private String subtitle;
579
580 @Valid
581 @Getter
582 @Setter
583 public Neighborhood neighborhood = new Neighborhood();
584
585
586 @ToString
587 public static class Neighborhood {
588 @NotBlank
589 @Getter
590 @Setter
591 private String title;
592 @NotBlank
593 @Getter
594 @Setter
595 private String typeVonNeumann;
596 @NotBlank
597 @Getter
598 @Setter
599 private String typeMoore;
600 @NotBlank
601 @Getter
602 @Setter
603 private String typeWoehlke;
604 }
605 }
606
607
608 @ToString
609 public static class Control {
610 @NotNull
611 @Getter
612 @Setter
613 private Integer threadSleepTime;
614 @NotNull
615 @Getter
616 @Setter
617 private Integer numberOfParticles;
618 }
619 }
620
621 @ToString
622 public static class Samegame {
623
624 @Valid
625 @Getter
626 @Setter
627 public View view = new View();
628 @Valid
629 @Getter
630 @Setter
631 public Control control = new Control();
632
633
634 @ToString
635 public static class View {
636 @NotBlank
637 @Getter
638 @Setter
639 private String title;
640 @NotBlank
641 @Getter
642 @Setter
643 private String subtitle;
644
645 @Valid
646 @Getter
647 @Setter
648 public Neighborhood neighborhood = new Neighborhood();
649
650
651 @ToString
652 public static class Neighborhood {
653 @NotBlank
654 @Getter
655 @Setter
656 private String title;
657 @NotBlank
658 @Getter
659 @Setter
660 private String typeVonNeumann;
661 @NotBlank
662 @Getter
663 @Setter
664 private String typeMoore;
665 @NotBlank
666 @Getter
667 @Setter
668 private String typeWoehlke;
669 }
670 }
671
672
673 @ToString
674 public static class Control {
675 @NotNull
676 @Getter
677 @Setter
678 private Integer threadSleepTime;
679 @NotNull
680 @Getter
681 @Setter
682 private Integer numberOfParticles;
683 }
684 }
685
686 @ToString
687 public static class Sierpinskitriangle {
688
689 @Valid
690 @Getter
691 @Setter
692 public View view = new View();
693 @Valid
694 @Getter
695 @Setter
696 public Control control = new Control();
697
698
699 @ToString
700 public static class View {
701 @NotBlank
702 @Getter
703 @Setter
704 private String title;
705 @NotBlank
706 @Getter
707 @Setter
708 private String subtitle;
709
710 @Valid
711 @Getter
712 @Setter
713 public Neighborhood neighborhood = new Neighborhood();
714
715
716 @ToString
717 public static class Neighborhood {
718 @NotBlank
719 @Getter
720 @Setter
721 private String title;
722 @NotBlank
723 @Getter
724 @Setter
725 private String typeVonNeumann;
726 @NotBlank
727 @Getter
728 @Setter
729 private String typeMoore;
730 @NotBlank
731 @Getter
732 @Setter
733 private String typeWoehlke;
734 }
735 }
736
737
738 @ToString
739 public static class Control {
740 @NotNull
741 @Getter
742 @Setter
743 private Integer threadSleepTime;
744 @NotNull
745 @Getter
746 @Setter
747 private Integer numberOfParticles;
748 }
749 }
750
751 @ToString
752 public static class Tetris {
753
754 @Valid
755 @Getter
756 @Setter
757 public View view = new View();
758 @Valid
759 @Getter
760 @Setter
761 public Control control = new Control();
762
763
764 @ToString
765 public static class View {
766 @NotBlank
767 @Getter
768 @Setter
769 private String title;
770 @NotBlank
771 @Getter
772 @Setter
773 private String subtitle;
774
775 @Valid
776 @Getter
777 @Setter
778 public Neighborhood neighborhood = new Neighborhood();
779
780
781 @ToString
782 public static class Neighborhood {
783 @NotBlank
784 @Getter
785 @Setter
786 private String title;
787 @NotBlank
788 @Getter
789 @Setter
790 private String typeVonNeumann;
791 @NotBlank
792 @Getter
793 @Setter
794 private String typeMoore;
795 @NotBlank
796 @Getter
797 @Setter
798 private String typeWoehlke;
799 }
800 }
801
802
803 @ToString
804 public static class Control {
805 @NotNull
806 @Getter
807 @Setter
808 private Integer threadSleepTime;
809 @NotNull
810 @Getter
811 @Setter
812 private Integer numberOfParticles;
813 }
814 }
815
816 @ToString
817 public static class Turmite {
818
819 @Valid
820 @Getter
821 @Setter
822 public View view = new View();
823 @Valid
824 @Getter
825 @Setter
826 public Control control = new Control();
827
828
829 @ToString
830 public static class View {
831 @NotBlank
832 @Getter
833 @Setter
834 private String title;
835 @NotBlank
836 @Getter
837 @Setter
838 private String subtitle;
839
840 @Valid
841 @Getter
842 @Setter
843 public Neighborhood neighborhood = new Neighborhood();
844
845
846 @ToString
847 public static class Neighborhood {
848 @NotBlank
849 @Getter
850 @Setter
851 private String title;
852 @NotBlank
853 @Getter
854 @Setter
855 private String typeVonNeumann;
856 @NotBlank
857 @Getter
858 @Setter
859 private String typeMoore;
860 @NotBlank
861 @Getter
862 @Setter
863 private String typeWoehlke;
864 }
865 }
866
867
868 @ToString
869 public static class Control {
870 @NotNull
871 @Getter
872 @Setter
873 private Integer threadSleepTime;
874 @NotNull
875 @Getter
876 @Setter
877 private Integer numberOfParticles;
878 }
879 }
880
881 @ToString
882 public static class Wator {
883
884 @Valid
885 @Getter
886 @Setter
887 public View view = new View();
888 @Valid
889 @Getter
890 @Setter
891 public Control control = new Control();
892
893
894 @ToString
895 public static class View {
896 @NotBlank
897 @Getter
898 @Setter
899 private String title;
900 @NotBlank
901 @Getter
902 @Setter
903 private String subtitle;
904
905 @Valid
906 @Getter
907 @Setter
908 public Neighborhood neighborhood = new Neighborhood();
909
910
911 @ToString
912 public static class Neighborhood {
913 @NotBlank
914 @Getter
915 @Setter
916 private String title;
917 @NotBlank
918 @Getter
919 @Setter
920 private String typeVonNeumann;
921 @NotBlank
922 @Getter
923 @Setter
924 private String typeMoore;
925 @NotBlank
926 @Getter
927 @Setter
928 private String typeWoehlke;
929 }
930 }
931
932
933 @ToString
934 public static class Control {
935 @NotNull
936 @Getter
937 @Setter
938 private Integer threadSleepTime;
939 @NotNull
940 @Getter
941 @Setter
942 private Integer numberOfParticles;
943 }
944 }
945
946 @ToString
947 public static class Gameoflive{
948
949 @Valid
950 @Getter
951 @Setter
952 public View view = new View();
953 @Valid
954 @Getter
955 @Setter
956 public Control control = new Control();
957
958
959 @ToString
960 public static class View {
961 @NotBlank
962 @Getter
963 @Setter
964 private String title;
965 @NotBlank
966 @Getter
967 @Setter
968 private String subtitle;
969
970 @Valid
971 @Getter
972 @Setter
973 public ComputerKurzweilProperties.Wator.View.Neighborhood neighborhood = new Wator.View.Neighborhood();
974
975
976 @ToString
977 public static class Neighborhood {
978 @NotBlank
979 @Getter
980 @Setter
981 private String title;
982 @NotBlank
983 @Getter
984 @Setter
985 private String typeVonNeumann;
986 @NotBlank
987 @Getter
988 @Setter
989 private String typeMoore;
990 @NotBlank
991 @Getter
992 @Setter
993 private String typeWoehlke;
994 }
995 }
996
997
998 @ToString
999 public static class Control {
1000 @NotNull
1001 @Getter
1002 @Setter
1003 private Integer threadSleepTime;
1004 @NotNull
1005 @Getter
1006 @Setter
1007 private Integer numberOfParticles;
1008 }
1009 }
1010
1011 public static ComputerKurzweilProperties propertiesFactory(File conf){
1012 log.info("propertiesFactory");
1013 log.info("propertiesFactory conf: "+conf.getAbsolutePath());
1014 ComputerKurzweilProperties properties;
1015 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
1016 try {
1017 InputStream input = new FileInputStream(conf);
1018 properties = mapper.readValue(input, ComputerKurzweilProperties.class);
1019 log.info(properties.toString());
1020 } catch (Exception e) {
1021 e.printStackTrace();
1022 properties = new ComputerKurzweilProperties();
1023 }
1024 log.info("propertiesFactory done");
1025 return properties;
1026 }
1027
1028 public String getSubtitle(TabType tabType){
1029 switch (tabType){
1030 case CYCLIC_CELLULAR_AUTOMATON:
1031 return this.getCca().getView().getSubtitle();
1032 case DIFFUSION_LIMITED_AGGREGATION:
1033 return this.getDla().getView().getSubtitle();
1034 case SIMULATED_EVOLUTION:
1035 return this.getSimulatedevolution().getView().getSubtitle();
1036 case MANDELBROT_SET:
1037 return this.getMandelbrot().getView().getSubtitle();
1038 case RANDOM_WALK_WIENER_PROCESS:
1039 return this.getRandomwalk().getView().getSubtitle();
1040 case KOCH_SNOWFLAKE:
1041 return this.getKochsnowflake().getView().getSubtitle();
1042 case SAME_GAME:
1043 return this.getSamegame().getView().getSubtitle();
1044 case SIERPINSKI_TRIANGLE:
1045 return this.getSierpinskitriangle().getView().getSubtitle();
1046 case TETRIS:
1047 return this.getTetris().getView().getSubtitle();
1048 case TURMITE:
1049 return this.getTurmite().getView().getSubtitle();
1050 case WATOR:
1051 return this.getWator().getView().getSubtitle();
1052 case CONWAYS_GAME_OF_LIFE:
1053 return this.getGameoflive().getView().getSubtitle();
1054 default:
1055 return "UNDEFINED";
1056 }
1057 }
1058
1059 public String getTitle(TabType tabType){
1060 switch (tabType){
1061 case CYCLIC_CELLULAR_AUTOMATON:
1062 return this.getCca().getView().getTitle();
1063 case DIFFUSION_LIMITED_AGGREGATION:
1064 return this.getDla().getView().getTitle();
1065 case SIMULATED_EVOLUTION:
1066 return this.getSimulatedevolution().getView().getTitle();
1067 case MANDELBROT_SET:
1068 return this.getMandelbrot().getView().getTitle();
1069 case RANDOM_WALK_WIENER_PROCESS:
1070 return this.getRandomwalk().getView().getTitle();
1071 case KOCH_SNOWFLAKE:
1072 return this.getKochsnowflake().getView().getTitle();
1073 case SAME_GAME:
1074 return this.getSamegame().getView().getTitle();
1075 case SIERPINSKI_TRIANGLE:
1076 return this.getSierpinskitriangle().getView().getTitle();
1077 case TETRIS:
1078 return this.getTetris().getView().getTitle();
1079 case TURMITE:
1080 return this.getTurmite().getView().getTitle();
1081 case WATOR:
1082 return this.getWator().getView().getTitle();
1083 case CONWAYS_GAME_OF_LIFE:
1084 return this.getGameoflive().getView().getTitle();
1085 default:
1086 return "UNDEFINED";
1087 }
1088 }
1089 }