View Javadoc
1   package org.woehlke.computer.kurzweil.mandelbrot.zoom.config;
2   
3   import java.io.FileInputStream;
4   import java.io.IOException;
5   import java.io.InputStream;
6   import java.util.Objects;
7   import java.util.Properties;
8   
9   /**
10   * Mandelbrot Set drawn by a Turing Machine.
11   * (C) 2006 - 2022 Thomas Woehlke.
12   * @author Thomas Woehlke
13   *
14   * @see <a href="https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html">Blog Article</a>
15   * @see <a href="https://github.com/Computer-Kurzweil/mandelbrot-zoom">Github Repository</a>
16   * @see <a href="https://java.woehlke.org/mandelbrot-zoom/">Maven Project Repository</a>
17   *
18   * @see org.woehlke.computer.kurzweil.mandelbrot.zoom.config.ConfigProperties
19   *
20   * Created by tw on 16.12.2019.
21   */
22  public class Config implements ConfigProperties {
23  
24      private String title;
25      private String subtitle;
26      private String copyright;
27      private int width;
28      private int height;
29  
30      private String buttonsLabel;
31      private String buttonsSwitch;
32      private String buttonsZoom;
33      private String buttonsZoomOut;
34  
35      public Config() {
36          String appPropertiesFile = (APP_PROPERTIES_FILENAME);
37          Properties prop = new Properties();
38          try (
39              InputStream input = new FileInputStream(appPropertiesFile)) {
40              prop.load(input);
41              /*
42              for( Object key : prop.keySet()){
43                  System.out.println(prop.get(key).toString());
44              }
45              */
46              title = prop.getProperty(KEY_TITLE,TITLE);
47              subtitle = prop.getProperty(KEY_SUBTITLE,SUBTITLE);
48              copyright = prop.getProperty(KEY_COPYRIGHT,COPYRIGHT);
49              String widthString = prop.getProperty(KEY_WIDTH,WIDTH);
50              String heightString = prop.getProperty(KEY_HEIGHT,HEIGHT);
51              width = Integer.parseInt(widthString);
52              height = Integer.parseInt(heightString);
53              buttonsLabel = prop.getProperty(KEY_BUTTONS_LABEL,BUTTONS_LABEL);
54              buttonsSwitch = prop.getProperty(KEY_BUTTONS_SWITCH,BUTTONS_SWITCH);
55              buttonsZoom = prop.getProperty(KEY_BUTTONS_ZOOM,BUTTONS_ZOOM);
56              buttonsZoomOut = prop.getProperty(KEY_BUTTONS_ZOOMOUT,BUTTONS_ZOOMOUT);
57          } catch (IOException ex) {
58              System.out.println(ex.getLocalizedMessage());
59          }
60      }
61  
62      public String getTitle() {
63          return title;
64      }
65  
66      public String getSubtitle() {
67          return subtitle;
68      }
69  
70      public String getCopyright() {
71          return copyright;
72      }
73  
74      public int getWidth() {
75          return width;
76      }
77  
78      public int getHeight() {
79          return height;
80      }
81  
82      public String getButtonsLabel() {
83          return buttonsLabel;
84      }
85  
86      public String getButtonsSwitch() {
87          return buttonsSwitch;
88      }
89  
90      public String getButtonsZoom() {
91          return buttonsZoom;
92      }
93  
94      public String getButtonsZoomOut() {
95          return buttonsZoomOut;
96      }
97  
98      @Override
99      public boolean equals(Object o) {
100         if (this == o) return true;
101         if (!(o instanceof Config)) return false;
102         Config config = (Config) o;
103         return getWidth() == config.getWidth() &&
104             getHeight() == config.getHeight() &&
105             Objects.equals(getTitle(), config.getTitle()) &&
106             Objects.equals(getSubtitle(), config.getSubtitle()) &&
107             Objects.equals(getCopyright(), config.getCopyright()) &&
108             Objects.equals(getButtonsLabel(), config.getButtonsLabel()) &&
109             Objects.equals(getButtonsSwitch(), config.getButtonsSwitch()) &&
110             Objects.equals(getButtonsZoom(), config.getButtonsZoom()) &&
111             Objects.equals(getButtonsZoomOut(), config.getButtonsZoomOut());
112     }
113 
114     @Override
115     public int hashCode() {
116         return Objects.hash(getTitle(), getSubtitle(), getCopyright(), getWidth(), getHeight(), getButtonsLabel(), getButtonsSwitch(), getButtonsZoom(), getButtonsZoomOut());
117     }
118 
119     @Override
120     public String toString() {
121         return "Config{" +
122             "title='" + title + '\'' +
123             ", subtitle='" + subtitle + '\'' +
124             ", copyright='" + copyright + '\'' +
125             ", width=" + width +
126             ", height=" + height +
127             ", buttonsLabel='" + buttonsLabel + '\'' +
128             ", buttonsSwitch='" + buttonsSwitch + '\'' +
129             ", buttonsZoom='" + buttonsZoom + '\'' +
130             ", buttonsZoomOut='" + buttonsZoomOut + '\'' +
131             '}';
132     }
133 }