View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.bean;
16  
17  import java.io.Serializable;
18  
19  import net.curre.prefcount.PrefCountRegistry;
20  import net.curre.prefcount.gui.theme.skin.DefaultSkin;
21  import net.curre.prefcount.gui.type.WindowComponent;
22  import net.curre.prefcount.gui.type.Place;
23  
24  /**
25   * Object of this class represents a bean for storing
26   * application settings (window size, theme, default locale, etc.).
27   * <p/>
28   * Created date: Jun 10, 2007
29   *
30   * @author Yevgeny Nyden
31   */
32  public class Settings implements Serializable {
33  
34    /** Serial version number. */
35    private static final long serialVersionUID = 39036452918252735L;
36  
37    /** Default value for the main window frame width. */
38    public static final int DEFAULT_MAIN_FRAME_WIDTH = 520;
39  
40    /** Default value for the main window frame height. */
41    public static final int DEFAULT_MAIN_FRAME_HEIGHT = 600;
42  
43    /** Default value for the dialog window frame width. */
44    public static final int DEFAULT_DIALOG_FRAME_WIDTH = 300;
45  
46    /** Default value for the dialog window frame height. */
47    public static final int DEFAULT_DIALOG_FRAME_HEIGHT = 340;
48  
49    /** Default value for the Look and Feel theme/skin ID. */
50    public static final String DEFAULT_LAF_SKIN_ID = DefaultSkin.NAME_KEY;
51  
52    /** Default preferance type option. */
53    public static final String DEFAULT_PREF_TYPE = WindowComponent.LENINGRAD.name();
54  
55    /** Default number of players option. */
56    public static final String DEFAULT_PLAYERS_NUMBER = WindowComponent.MAIN_3_PLAYERS.name();
57  
58    /** Default divisible by option. */
59    public static final String DEFAULT_DIVISIBLE_BY = WindowComponent.DIVISIBLE_IGNORE.name();
60  
61    /** Default player for the "Divisible by N" mount adjustment. */
62    public static final Place DEFAULT_ADJ_PLAYER = Place.EAST;
63  
64    /** The main window frame width. */
65    private int mainFrameWidth;
66  
67    /** The main window frame height. */
68    private int mainFrameHeight;
69  
70    /** The dialog window frame width. */
71    private int dialogFrameWidth;
72  
73    /** The dialog window frame height. */
74    private int dialogFrameHeight;
75  
76    /** Look and Feel theme/skin ID (resource key). */
77    private String lafSkinId;
78  
79    /** Locale identifier (case insensitive language name). */
80    private String localeId;
81  
82    /** Preferance type (a WindowComponent enum name). */
83    private String prefType;
84  
85    /** Number of players in the game (a WindowComponent enum name). */
86    private String playersNumber;
87  
88    /** Divisible By option (a WindowComponent enum name). */
89    private String divisibleBy;
90  
91    /**
92     * Default constructor that initializes
93     * all properties to the default values.
94     */
95    public Settings() {
96      initializeToDefaults();
97    }
98  
99    /**
100    * Getter for the main window frame width.
101    *
102    * @return The main window frame width.
103    */
104   public int getMainFrameWidth() {
105     return mainFrameWidth;
106   }
107 
108   /**
109    * Setter for the main window frame width.
110    *
111    * @param mainFrameWidth Main window frame width.
112    */
113   public void setMainFrameWidth(int mainFrameWidth) {
114     this.mainFrameWidth = mainFrameWidth;
115   }
116 
117   /**
118    * Getter for the main window frame height.
119    *
120    * @return The main window frame height.
121    */
122   public int getMainFrameHeight() {
123     return mainFrameHeight;
124   }
125 
126   /**
127    * Setter for the main window frame height.
128    *
129    * @param mainFrameHeight Main window frame height.
130    */
131   public void setMainFrameHeight(int mainFrameHeight) {
132     this.mainFrameHeight = mainFrameHeight;
133   }
134 
135   /**
136    * Getter for the dialog window frame width.
137    *
138    * @return The dialog window frame width.
139    */
140   public int getDialogFrameWidth() {
141     return dialogFrameWidth;
142   }
143 
144   /**
145    * Setter for the dialog window frame width.
146    *
147    * @param dialogFrameWidth Dialog window frame width.
148    */
149   public void setDialogFrameWidth(int dialogFrameWidth) {
150     this.dialogFrameWidth = dialogFrameWidth;
151   }
152 
153   /**
154    * Getter for the dialog window frame height.
155    *
156    * @return The dialog window frame height.
157    */
158   public int getDialogFrameHeight() {
159     return dialogFrameHeight;
160   }
161 
162   /**
163    * Setter for the dialog window frame height.
164    *
165    * @param dialogFrameHeight Dialog window frame height.
166    */
167   public void setDialogFrameHeight(int dialogFrameHeight) {
168     this.dialogFrameHeight = dialogFrameHeight;
169   }
170 
171   /**
172    * Getter for the Look and Feel theme/skin ID (resource key).
173    *
174    * @return The Look and Feel theme/skin ID (resource key).
175    */
176   public String getLafSkinId() {
177     return lafSkinId;
178   }
179 
180   /**
181    * Setter for the Look and Feel theme/skin ID (resource key).
182    *
183    * @param lafSkinId The Look and Feel theme/skin ID (resource key).
184    */
185   public void setLafSkinId(String lafSkinId) {
186     this.lafSkinId = lafSkinId;
187   }
188 
189   /**
190    * Getter for the locale identifier (case
191    * insensitive language name).
192    *
193    * @return The locale identifier (language name).
194    */
195   public String getLocaleId() {
196     return localeId;
197   }
198 
199   /**
200    * Setter for the locale identifier (case
201    * insensitive language name).
202    *
203    * @param localeId Locale identifier (case insensitive language name).
204    */
205   public void setLocaleId(String localeId) {
206     this.localeId = localeId;
207   }
208 
209   /**
210    * Getter for the the Preferance type option.
211    *
212    * @return WindowComponent enum name that represents the Preferance type option.
213    */
214   public String getPrefType() {
215     return this.prefType;
216   }
217 
218   /**
219    * Setter for property 'prefType'.
220    *
221    * @param prefType WindowComponent enum name that represents the Preferance type option.
222    */
223   public void setPrefType(String prefType) {
224     this.prefType = prefType;
225   }
226 
227   /**
228    * Getter for the Number of players option.
229    *
230    * @return WindowComponent enum name that represents the Number of players option.
231    */
232   public String getPlayersNumber() {
233     return this.playersNumber;
234   }
235 
236   /**
237    * Setter for property 'playersNumber'.
238    *
239    * @param playersNumber WindowComponent enum name that represents the Number of players option.
240    */
241   public void setPlayersNumber(String playersNumber) {
242     this.playersNumber = playersNumber;
243   }
244 
245   /**
246    * Getter for the Divisible By option (a WindowComponent enum name).
247    *
248    * @return WindowComponent enum name that represents the Divisible By option.
249    */
250   public String getDivisibleBy() {
251     return this.divisibleBy;
252   }
253 
254   /**
255    * Setter for property 'divisibleBy'.
256    *
257    * @param divisibleBy WindowComponent enum name that represents the Divisible By option.
258    */
259   public void setDivisibleBy(String divisibleBy) {
260     this.divisibleBy = divisibleBy;
261   }
262 
263   /** Method to reset the settings to default values. */
264   public void reset() {
265     initializeToDefaults();
266   }
267 
268   /**
269    * Tests if settings values are null and sets them to the
270    * default values if they are null. This is crucial when
271    * a newer application uses an older version of serialized
272    * settings object.
273    */
274   public void testSettings() {
275     if (this.lafSkinId == null) {
276       this.lafSkinId = DEFAULT_LAF_SKIN_ID;
277     }
278     if (this.localeId == null) {
279       this.localeId = PrefCountRegistry.DEFAULT_LOCALE_ID;
280     }
281     if (this.prefType == null) {
282       this.prefType = DEFAULT_PREF_TYPE;
283     }
284     if (this.playersNumber == null) {
285       this.playersNumber = DEFAULT_PLAYERS_NUMBER;
286     }
287     if (this.divisibleBy == null) {
288       this.divisibleBy = DEFAULT_DIVISIBLE_BY;
289     }
290   }
291 
292   /** Private methods ********************** */
293 
294   /**
295    * Helper method to initialize all settings
296    * properties to default values.
297    */
298   private void initializeToDefaults() {
299     this.mainFrameWidth = DEFAULT_MAIN_FRAME_WIDTH;
300     this.mainFrameHeight = DEFAULT_MAIN_FRAME_HEIGHT;
301     this.dialogFrameWidth = DEFAULT_DIALOG_FRAME_WIDTH;
302     this.dialogFrameHeight = DEFAULT_DIALOG_FRAME_HEIGHT;
303     this.lafSkinId = DEFAULT_LAF_SKIN_ID;
304     this.localeId = PrefCountRegistry.DEFAULT_LOCALE_ID;
305     this.prefType = DEFAULT_PREF_TYPE;
306     this.playersNumber = DEFAULT_PLAYERS_NUMBER;
307     this.divisibleBy = DEFAULT_DIVISIBLE_BY;
308   }
309 
310 }