View Javadoc
1   /*
2    * Tethys: GUI Utilities
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.tethys.api.base;
18  
19  import io.github.tonywasher.joceanus.oceanus.logger.OceanusLogManager;
20  import io.github.tonywasher.joceanus.oceanus.logger.OceanusLogger;
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.util.Iterator;
25  import java.util.LinkedHashMap;
26  import java.util.Map;
27  import java.util.Map.Entry;
28  import java.util.Properties;
29  
30  /**
31   * Program Definitions.
32   */
33  public abstract class TethysUIProgram {
34      /**
35       * Logger.
36       */
37      private static final OceanusLogger LOGGER = OceanusLogManager.getLogger(TethysUIProgram.class);
38  
39      /**
40       * APP Key.
41       */
42      private static final String PFX_APP = "App.";
43  
44      /**
45       * Version Key.
46       */
47      private static final String PFX_VERS = "Version.";
48  
49      /**
50       * Name Key.
51       */
52      private static final String KEY_NAME = PFX_APP + "name";
53  
54      /**
55       * Version Key.
56       */
57      private static final String KEY_VERSION = PFX_APP + "version";
58  
59      /**
60       * Revision Key.
61       */
62      private static final String KEY_REVISION = PFX_APP + "revision";
63  
64      /**
65       * Copyright Key.
66       */
67      private static final String KEY_COPYRIGHT = PFX_APP + "copyright";
68  
69      /**
70       * TimeStamp Key.
71       */
72      private static final String KEY_BUILTON = PFX_APP + "timeStamp";
73  
74      /**
75       * Program Details.
76       */
77      private final Map<String, String> theDetails;
78  
79      /**
80       * Program Dependencies.
81       */
82      private final Map<String, String> theDependencies;
83  
84      /**
85       * Constructor.
86       *
87       * @param pProperties the inputStream of the properties
88       */
89      protected TethysUIProgram(final InputStream pProperties) {
90          /* Create the maps */
91          theDetails = new LinkedHashMap<>();
92          theDependencies = new LinkedHashMap<>();
93  
94          /* Protect against exceptions */
95          try {
96              /* Load the properties */
97              final Properties myProperties = new Properties();
98              myProperties.load(pProperties);
99  
100             /* Load values */
101             loadValues(myProperties);
102 
103             /* Catch Exceptions */
104         } catch (IOException e) {
105             LOGGER.error("Failed to load properties", e);
106         }
107     }
108 
109     /**
110      * Load the values.
111      *
112      * @param pProperties the properties
113      */
114     private void loadValues(final Properties pProperties) {
115         /* Loop through the property names */
116         for (String myName : pProperties.stringPropertyNames()) {
117             /* If this is an Application property */
118             if (myName.startsWith(PFX_APP)) {
119                 theDetails.put(myName, pProperties.getProperty(myName));
120 
121                 /* If this is a Version property */
122             } else if (myName.startsWith(PFX_VERS)) {
123                 theDependencies.put(myName.substring(PFX_VERS.length()), pProperties.getProperty(myName));
124             }
125         }
126     }
127 
128     /**
129      * Obtain the dimensions (width, height) of the panel.
130      *
131      * @return the width/height (or null for default)
132      */
133     public int[] getPanelDimensions() {
134         return null;
135     }
136 
137     /**
138      * Does the panel use a slider status?
139      *
140      * @return true/false
141      */
142     public boolean useSliderStatus() {
143         return false;
144     }
145 
146     /**
147      * Obtain the program iconIds.
148      *
149      * @return the icon Ids.
150      */
151     public abstract TethysUIIconId[] getIcons();
152 
153     /**
154      * Obtain the splash iconId.
155      *
156      * @return the iconId.
157      */
158     public TethysUIIconId getSplash() {
159         return null;
160     }
161 
162     /**
163      * Obtain program name.
164      *
165      * @return the name.
166      */
167     public String getName() {
168         return theDetails.get(KEY_NAME);
169     }
170 
171     /**
172      * Obtain program version.
173      *
174      * @return the version.
175      */
176     public String getVersion() {
177         return theDetails.get(KEY_VERSION);
178     }
179 
180     /**
181      * Obtain program revision.
182      *
183      * @return the revision.
184      */
185     public String getRevision() {
186         return theDetails.get(KEY_REVISION);
187     }
188 
189     /**
190      * Obtain program copyright.
191      *
192      * @return the copyright.
193      */
194     public String getCopyright() {
195         return theDetails.get(KEY_COPYRIGHT);
196     }
197 
198     /**
199      * Obtain program build date.
200      *
201      * @return the build date.
202      */
203     public String getBuiltOn() {
204         return theDetails.get(KEY_BUILTON);
205     }
206 
207     /**
208      * Obtain iterator for the dependencies.
209      *
210      * @return the iterator.
211      */
212     public Iterator<Entry<String, String>> dependencyIterator() {
213         return theDependencies.entrySet().iterator();
214     }
215 }