View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.cca.config;
2   
3   import java.awt.*;
4   import java.io.FileInputStream;
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.Properties;
8   
9   public class Config implements ConfigProperties {
10  
11      private String title;
12      private String subtitle;
13      private int width;
14      private int height;
15      private String neighborhood;
16      private String buttonVonNeumann;
17      private String buttonMoore;
18      private String buttonWoehlke;
19  
20      private static final int TITLE_HEIGHT = 30;
21  
22      public Config() {
23          String appPropertiesFile = (APP_PROPERTIES_FILENAME);
24          Properties prop = new Properties();
25          try (
26              InputStream input = new FileInputStream(appPropertiesFile)) {
27              prop.load(input);
28              for( Object key : prop.keySet()){
29                  //System.out.println(prop.get(key).toString());
30              }
31              title = prop.getProperty(KEY_TITLE,TITLE);
32              subtitle = prop.getProperty(KEY_SUBTITLE,SUBTITLE);
33              String widthString = prop.getProperty(KEY_WIDTH,WIDTH);
34              String heightString = prop.getProperty(KEY_HEIGHT,HEIGHT);
35              width = Integer.parseInt(widthString);
36              height = Integer.parseInt(heightString);
37              neighborhood=prop.getProperty(KEY_NEIGHBORHOOD,NEIGHBORHOOD);
38              buttonVonNeumann=prop.getProperty(KEY_BUTTON_VON_NEUMANN,BUTTON_VON_NEUMANN);
39              buttonMoore=prop.getProperty(KEY_BUTTON_MOORE,BUTTON_MOORE);
40              buttonWoehlke=prop.getProperty(KEY_BUTTON_WOEHLKE,BUTTON_WOEHLKE);
41          } catch (IOException ex) {
42              System.out.println(ex.getLocalizedMessage());
43          }
44      }
45  
46      public Rectangle getFrameBounds(){
47          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
48          double startX = (screenSize.getWidth() - height) / 2d;
49          double startY = (screenSize.getHeight() - width) / 2d;
50          int myheight = Double.valueOf(height).intValue()+TITLE_HEIGHT;
51          int mywidth = Double.valueOf(width).intValue();
52          int mystartX = Double.valueOf(startX).intValue();
53          int mystartY = Double.valueOf(startY).intValue();
54          return new Rectangle(mystartX, mystartY, mywidth, myheight);
55      }
56  
57      public Rectangle getCanvasBounds(){
58          return new Rectangle(0, 0, width , height);
59      }
60  
61      public Point getLatticeDimensions(){
62          return new Point(width,height);
63      }
64  
65      public int getWidth() {
66          return width;
67      }
68  
69      public int getHeight() {
70          return height;
71      }
72  
73      public String getTitle() {
74          return title;
75      }
76  
77      public String getSubtitle() {
78          return subtitle;
79      }
80  
81      public String getNeighborhood() {
82          return neighborhood;
83      }
84  
85      public String getButtonVonNeumann() {
86          return buttonVonNeumann;
87      }
88  
89      public String getButtonMoore() {
90          return buttonMoore;
91      }
92  
93      public String getButtonWoehlke() {
94          return buttonWoehlke;
95      }
96  
97  
98  }