View Javadoc
1   package org.woehlke.computer.kurzweil.application;
2   
3   import lombok.Getter;
4   import lombok.ToString;
5   import lombok.extern.log4j.Log4j2;
6   import org.woehlke.computer.kurzweil.commons.Startable;
7   import org.woehlke.computer.kurzweil.commons.model.LatticePoint;
8   import org.woehlke.computer.kurzweil.tabs.simulatedevolution.model.CellCore;
9   import org.woehlke.computer.kurzweil.tabs.simulatedevolution.model.LifeCycle;
10  
11  import javax.swing.*;
12  import javax.swing.border.Border;
13  import javax.swing.border.CompoundBorder;
14  import java.util.Date;
15  import java.util.Random;
16  
17  @Log4j2
18  @Getter
19  @ToString(exclude={"random","frame"},callSuper=true)
20  public class ComputerKurzweilContext implements Startable {
21  
22      private final Random random;
23      private final ComputerKurzweilProperties properties;
24  
25      public ComputerKurzweilContext(
26          ComputerKurzweilProperties computerKurzweilProperties
27      ) {
28          this.properties = computerKurzweilProperties;
29          long seed = new Date().getTime();
30          this.random = new Random(seed);
31      }
32  
33      public CompoundBorder getTabbedPaneBorder() {
34          return getBorder();
35      }
36  
37      public CompoundBorder getFrameBorder(){
38          return getBorder();
39      }
40  
41      public CompoundBorder getBorder(){
42          int left = this.getProperties().getAllinone().getView().getBorderPaddingX();
43          int right = this.getProperties().getAllinone().getView().getBorderPaddingX();
44          int top = this.getProperties().getAllinone().getView().getBorderPaddingY();
45          int bottom = this.getProperties().getAllinone().getView().getBorderPaddingY();
46          return BorderFactory.createCompoundBorder(
47              BorderFactory.createEmptyBorder(),
48              BorderFactory.createEmptyBorder(left,right,top,bottom)
49          );
50      }
51  
52      public CompoundBorder getBorder(String label){
53          int top = this.getProperties().getAllinone().getView().getBorderPaddingY();
54          int left = this.getProperties().getAllinone().getView().getBorderPaddingX();
55          int bottom = this.getProperties().getAllinone().getView().getBorderPaddingY();
56          int right = this.getProperties().getAllinone().getView().getBorderPaddingX();
57          return BorderFactory.createCompoundBorder(
58              BorderFactory.createTitledBorder(label),
59              BorderFactory.createEmptyBorder(top,left,bottom,right)
60          );
61      }
62  
63      private CompoundBorder getDoubleBorder(){
64          int left = this.getProperties().getAllinone().getView().getBorderPaddingX();
65          int right = this.getProperties().getAllinone().getView().getBorderPaddingX();
66          int top = this.getProperties().getAllinone().getView().getBorderPaddingY();
67          int bottom = this.getProperties().getAllinone().getView().getBorderPaddingY();
68          return BorderFactory.createCompoundBorder(
69              BorderFactory.createEmptyBorder(left,right,top,bottom),
70              BorderFactory.createEmptyBorder(left,right,top,bottom)
71          );
72      }
73  
74      private CompoundBorder getDoubleBorder(String label){
75          int left = this.getProperties().getAllinone().getView().getBorderPaddingX();
76          int right = this.getProperties().getAllinone().getView().getBorderPaddingX();
77          int top = this.getProperties().getAllinone().getView().getBorderPaddingY();
78          int bottom = this.getProperties().getAllinone().getView().getBorderPaddingY();
79          return BorderFactory.createCompoundBorder(
80              BorderFactory.createEmptyBorder(left,right,top,bottom),
81              BorderFactory.createEmptyBorder(left,right,top,bottom)
82          );
83      }
84  
85      public CompoundBorder getBottomButtonsPanelBorder(){
86          return getDoubleBorder();
87      }
88  
89      public CompoundBorder getBottomButtonsPanelBorder(String label){
90          return getDoubleBorder(label);
91      }
92  
93      private Border getZeroBorder() {
94          int top = 0;
95          int left = 0;
96          int bottom = 0;
97          int right = 0;
98          return BorderFactory.createEmptyBorder(top,left,bottom,right);
99      }
100 
101     public Border getTabBorder() {
102         return getZeroBorder();
103     }
104 
105     public Border getCanvasBorder() {
106         return getZeroBorder();
107     }
108 
109     public LatticePoint getWorldDimensions(){
110         int x = this.properties.getAllinone().getLattice().getWidth();
111         int y = this.properties.getAllinone().getLattice().getHeight();
112         return new LatticePoint(x,y);
113     }
114 
115     public LatticePoint getNextRandomLatticePoint() {
116         int x = this.properties.getAllinone().getLattice().getWidth();
117         int y = this.properties.getAllinone().getLattice().getHeight();
118         int nextX = this.getRandom().nextInt(x);
119         int nextY = this.getRandom().nextInt(y);
120         LatticePointeil/commons/model/LatticePoint.html#LatticePoint">LatticePoint p = new LatticePoint(nextX,nextY);
121         p.normalize(this.getWorldDimensions());
122         p.absoluteValue();
123         return p;
124     }
125 
126     public LifeCycle getNewCellLifeCycle() {
127         return new LifeCycle(this.properties.getSimulatedevolution().getCellConf().getFatAtBirth());
128     }
129 
130     public CellCore getNewCellCore() {
131         return new CellCore(this.random);
132     }
133 
134     public void start(){ }
135 
136     public void stop() { }
137 
138 }