View Javadoc
1   /*
2    * Metis: Java Data Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.metis.preference;
18  
19  import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleId;
20  import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleLoader;
21  import io.github.tonywasher.joceanus.metis.data.MetisDataResource;
22  
23  import java.util.EnumMap;
24  import java.util.Map;
25  import java.util.ResourceBundle;
26  
27  /**
28   * Resource IDs for JMetis preferences.
29   */
30  public enum MetisPreferenceResource implements OceanusBundleId {
31      /**
32       * Preference type STRING.
33       */
34      TYPE_STRING("type.STRING"),
35  
36      /**
37       * Preference type INTEGER.
38       */
39      TYPE_INTEGER("type.INTEGER"),
40  
41      /**
42       * Preference type BOOLEAN.
43       */
44      TYPE_BOOLEAN("type.BOOLEAN"),
45  
46      /**
47       * Preference type DATE.
48       */
49      TYPE_DATE("type.DATE"),
50  
51      /**
52       * Preference type FILE.
53       */
54      TYPE_FILE("type.FILE"),
55  
56      /**
57       * Preference type DIRECTORY.
58       */
59      TYPE_DIRECTORY("type.DIRECTORY"),
60  
61      /**
62       * Preference type ENUM.
63       */
64      TYPE_ENUM("type.ENUM"),
65  
66      /**
67       * Preference type COLOR.
68       */
69      TYPE_COLOR("type.COLOR"),
70  
71      /**
72       * OK button text.
73       */
74      UI_BUTTON_OK("ui.button.Ok"),
75  
76      /**
77       * Reset button text.
78       */
79      UI_BUTTON_RESET("ui.button.Reset"),
80  
81      /**
82       * Save Title text.
83       */
84      UI_TITLE_SAVE("ui.title.Save"),
85  
86      /**
87       * Select Title text.
88       */
89      UI_TITLE_SELECT("ui.title.Select"),
90  
91      /**
92       * Preferences Title text.
93       */
94      UI_TITLE_PREFERENCES("ui.title.Preferences"),
95  
96      /**
97       * Options Title text.
98       */
99      UI_TITLE_OPTIONS("ui.title.Options"),
100 
101     /**
102      * Colour Title text.
103      */
104     UI_TITLE_COLOR("ui.title.Color"),
105 
106     /**
107      * Colour Prompt text.
108      */
109     UI_PROMPT_COLOR("ui.prompt.Color"),
110 
111     /**
112      * PreferenceSet label text.
113      */
114     UI_LABEL_SET("ui.label.Set"),
115 
116     /**
117      * Range minimum.
118      */
119     UI_RANGE_MIN("ui.range.Minimum"),
120 
121     /**
122      * Range maximum.
123      */
124     UI_RANGE_MAX("ui.range.Maximum"),
125 
126     /**
127      * Range error.
128      */
129     UI_RANGE_ERROR("ui.range.Error"),
130 
131     /**
132      * Store Error text.
133      */
134     UI_ERROR_STORE("ui.error.Store"),
135 
136     /**
137      * Select header text.
138      */
139     UI_HEADER_SELECT("ui.header.Select"),
140 
141     /**
142      * SecurityPreference Display Name.
143      */
144     SECPREF_BASEPREFNAME("secpref.baseprefname"),
145 
146     /**
147      * SecurityPreference Display Name.
148      */
149     SECPREF_PREFNAME("secpref.prefname"),
150 
151     /**
152      * SecurityPreference Factory.
153      */
154     SECPREF_FACTORY("secpref.factory"),
155 
156     /**
157      * SecurityPreference keyLength.
158      */
159     SECPREF_KEYLEN("secpref.keylen"),
160 
161     /**
162      * SecurityPreference Cipher Steps.
163      */
164     SECPREF_CIPHERSTEPS("secpref.ciphersteps"),
165 
166     /**
167      * SecurityPreference Hash Iterations.
168      */
169     SECPREF_ITERATIONS("secpref.hashiterations"),
170 
171     /**
172      * SecurityPreference Phrase.
173      */
174     SECPREF_PHRASE("secpref.phrase"),
175 
176     /**
177      * SecurityPreference Active KeySets.
178      */
179     SECPREF_KEYSETS("secpref.keysets");
180 
181     /**
182      * The PreferenceType Map.
183      */
184     private static final Map<MetisPreferenceType, OceanusBundleId> PREF_MAP = buildPreferenceMap();
185 
186     /**
187      * The Resource Loader.
188      */
189     private static final OceanusBundleLoader LOADER = OceanusBundleLoader.getLoader(MetisDataResource.class.getCanonicalName(),
190             ResourceBundle::getBundle);
191 
192     /**
193      * The Id.
194      */
195     private final String theKeyName;
196 
197     /**
198      * The Value.
199      */
200     private String theValue;
201 
202     /**
203      * Constructor.
204      *
205      * @param pKeyName the key name
206      */
207     MetisPreferenceResource(final String pKeyName) {
208         theKeyName = pKeyName;
209     }
210 
211     @Override
212     public String getKeyName() {
213         return theKeyName;
214     }
215 
216     @Override
217     public String getNameSpace() {
218         return "Metis.preference";
219     }
220 
221     @Override
222     public String getValue() {
223         /* If we have not initialised the value */
224         if (theValue == null) {
225             /* Derive the value */
226             theValue = LOADER.getValue(this);
227         }
228 
229         /* return the value */
230         return theValue;
231     }
232 
233     /**
234      * Build preference map.
235      *
236      * @return the map
237      */
238     private static Map<MetisPreferenceType, OceanusBundleId> buildPreferenceMap() {
239         /* Create the map and return it */
240         final Map<MetisPreferenceType, OceanusBundleId> myMap = new EnumMap<>(MetisPreferenceType.class);
241         myMap.put(MetisPreferenceType.STRING, TYPE_STRING);
242         myMap.put(MetisPreferenceType.INTEGER, TYPE_INTEGER);
243         myMap.put(MetisPreferenceType.BOOLEAN, TYPE_BOOLEAN);
244         myMap.put(MetisPreferenceType.DATE, TYPE_DATE);
245         myMap.put(MetisPreferenceType.FILE, TYPE_FILE);
246         myMap.put(MetisPreferenceType.DIRECTORY, TYPE_DIRECTORY);
247         myMap.put(MetisPreferenceType.ENUM, TYPE_ENUM);
248         myMap.put(MetisPreferenceType.COLOR, TYPE_COLOR);
249         return myMap;
250     }
251 
252     /**
253      * Obtain key for prefType.
254      *
255      * @param pType the type
256      * @return the resource key
257      */
258     public static OceanusBundleId getKeyForPrefType(final MetisPreferenceType pType) {
259         return OceanusBundleLoader.getKeyForEnum(PREF_MAP, pType);
260     }
261 }