1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.awt.Image; |
24 |
|
import java.io.File; |
25 |
|
import java.io.FileInputStream; |
26 |
|
import java.io.FileNotFoundException; |
27 |
|
import java.io.IOException; |
28 |
|
import java.io.InputStream; |
29 |
|
import java.net.URL; |
30 |
|
import java.util.ArrayList; |
31 |
|
import java.util.Arrays; |
32 |
|
import java.util.HashMap; |
33 |
|
import java.util.List; |
34 |
|
import java.util.Map; |
35 |
|
import java.util.Properties; |
36 |
|
|
37 |
|
import javax.swing.ImageIcon; |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 145 (145) |
Complexity: 37 |
Complexity Density: 0.41 |
|
39 |
|
public class ChannelProperties |
40 |
|
{ |
41 |
|
|
42 |
|
public static final String CHANNEL_PROPERTIES_FILENAME = "channel.props"; |
43 |
|
|
44 |
|
private static Properties channelProps; |
45 |
|
|
46 |
|
private static final Properties defaultProps; |
47 |
|
|
48 |
|
private static Map<String, Image> imageMap = new HashMap<String, Image>(); |
49 |
|
|
50 |
|
private static Map<String, URL> urlMap = new HashMap<String, URL>(); |
51 |
|
|
52 |
|
private static final ArrayList<Image> iconList; |
53 |
|
|
54 |
|
public static final String FALLBACK_APPNAME = "Jalview"; |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 9 |
Complexity Density: 0.19 |
|
56 |
0 |
static... |
57 |
|
{ |
58 |
0 |
defaultProps = new Properties(); |
59 |
|
|
60 |
|
|
61 |
0 |
defaultProps.put("app_name", FALLBACK_APPNAME); |
62 |
0 |
defaultProps.put("banner", "/default_images/jalview_banner.png"); |
63 |
0 |
defaultProps.put("logo.16", "/default_images/jalview_logo-16.png"); |
64 |
0 |
defaultProps.put("logo.32", "/default_images/jalview_logo-32.png"); |
65 |
0 |
defaultProps.put("logo.38", "/default_images/jalview_logo-38.png"); |
66 |
0 |
defaultProps.put("logo.48", "/default_images/jalview_logo-48.png"); |
67 |
0 |
defaultProps.put("logo.64", "/default_images/jalview_logo-64.png"); |
68 |
0 |
defaultProps.put("logo.128", "/default_images/jalview_logo-128.png"); |
69 |
0 |
defaultProps.put("logo.256", "/default_images/jalview_logo-256.png"); |
70 |
0 |
defaultProps.put("logo.512", "/default_images/jalview_logo-512.png"); |
71 |
0 |
defaultProps.put("rotatable_logo.48", |
72 |
|
"/default_images/rotatable_jalview_logo-38.png"); |
73 |
0 |
defaultProps.put("bg_logo.28", "/default_images/barton_group-28.png"); |
74 |
0 |
defaultProps.put("bg_logo.30", "/default_images/barton_group-30.png"); |
75 |
0 |
defaultProps.put("bg_logo.32", "/default_images/barton_group-32.png"); |
76 |
0 |
defaultProps.put("uod_banner.28", "/default_images/UoD_banner-28.png"); |
77 |
0 |
defaultProps.put("uod_banner.30", "/default_images/UoD_banner-30.png"); |
78 |
0 |
defaultProps.put("uod_banner.32", "/default_images/UoD_banner-32.png"); |
79 |
0 |
defaultProps.put("default_appbase", |
80 |
|
"https://www.jalview.org/getdown/release/1.8"); |
81 |
0 |
defaultProps.put("preferences.filename", ".jalview_properties"); |
82 |
0 |
defaultProps.put("channel", "none"); |
83 |
|
|
84 |
|
|
85 |
0 |
Properties tryChannelProps = new Properties(); |
86 |
0 |
URL channelPropsURL = ChannelProperties.class |
87 |
|
.getResource("/" + CHANNEL_PROPERTIES_FILENAME); |
88 |
0 |
if (channelPropsURL == null) |
89 |
|
{ |
90 |
|
|
91 |
0 |
ErrorLog.errPrintln("Failed to find '/" + CHANNEL_PROPERTIES_FILENAME |
92 |
|
+ "' file at '" |
93 |
0 |
+ (channelPropsURL == null ? "null" |
94 |
|
: channelPropsURL.toString()) |
95 |
|
+ "'. Using class defaultProps."); |
96 |
0 |
tryChannelProps = defaultProps; |
97 |
|
} |
98 |
|
else |
99 |
|
{ |
100 |
0 |
try |
101 |
|
{ |
102 |
0 |
InputStream channelPropsIS = HttpUtils.openStream(channelPropsURL); |
103 |
0 |
tryChannelProps.load(channelPropsIS); |
104 |
0 |
channelPropsIS.close(); |
105 |
|
} catch (IOException e) |
106 |
|
{ |
107 |
0 |
ErrorLog.errPrintln(e.getMessage()); |
108 |
|
|
109 |
|
} |
110 |
|
} |
111 |
0 |
channelProps = tryChannelProps; |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
0 |
iconList = new ArrayList<Image>(); |
120 |
0 |
List<String> sizes = Arrays.asList("16", "32", "48", "64", "128", "256", |
121 |
|
"512"); |
122 |
0 |
for (String size : sizes) |
123 |
|
{ |
124 |
0 |
Image logo = null; |
125 |
|
|
126 |
0 |
logo = ChannelProperties.getImage("logo." + size, null, false); |
127 |
0 |
if (logo != null) |
128 |
|
{ |
129 |
0 |
iconList.add(logo); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
0 |
if (iconList.size() == 0) |
134 |
|
{ |
135 |
0 |
for (String size : sizes) |
136 |
|
{ |
137 |
0 |
Image logo = null; |
138 |
0 |
String path = defaultProps.getProperty("logo." + size); |
139 |
0 |
URL imageURL = ChannelProperties.class.getResource(path); |
140 |
0 |
ImageIcon imgIcon = imageURL == null ? null |
141 |
|
: new ImageIcon(imageURL); |
142 |
0 |
logo = imgIcon == null ? null : imgIcon.getImage(); |
143 |
0 |
if (logo != null) |
144 |
|
{ |
145 |
0 |
iconList.add(logo); |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
151 |
0 |
protected static void loadProps(File dir)... |
152 |
|
{ |
153 |
0 |
File channelPropsFile = new File(dir, CHANNEL_PROPERTIES_FILENAME); |
154 |
0 |
if (channelPropsFile.exists()) |
155 |
|
{ |
156 |
0 |
try |
157 |
|
{ |
158 |
0 |
InputStream is = new FileInputStream(channelPropsFile); |
159 |
0 |
channelProps.load(is); |
160 |
|
} catch (FileNotFoundException e) |
161 |
|
{ |
162 |
0 |
ErrorLog.errPrintln(e.getMessage()); |
163 |
|
} catch (IOException e) |
164 |
|
{ |
165 |
0 |
ErrorLog.errPrintln(e.getMessage()); |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
0 |
private static Properties channelProps()... |
171 |
|
{ |
172 |
0 |
return channelProps; |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
private static Map<String, Image> imageMap()... |
176 |
|
{ |
177 |
0 |
return imageMap; |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
private static Map<String, URL> urlMap()... |
181 |
|
{ |
182 |
0 |
return urlMap; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
0 |
public static String getProperty(String key)... |
190 |
|
{ |
191 |
0 |
return getProperty(key, null, true); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
public static String getProperty(String key, String defaultVal)... |
199 |
|
{ |
200 |
0 |
return getProperty(key, defaultVal, false); |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.8 |
|
206 |
0 |
private static String getProperty(String key, String defaultVal,... |
207 |
|
boolean useClassDefaultProps) |
208 |
|
{ |
209 |
0 |
if (channelProps() != null) |
210 |
|
{ |
211 |
0 |
if (channelProps().containsKey(key)) |
212 |
|
{ |
213 |
0 |
return channelProps().getProperty(key, |
214 |
0 |
useClassDefaultProps ? defaultProps.getProperty(key) |
215 |
|
: defaultVal); |
216 |
|
} |
217 |
|
else |
218 |
|
{ |
219 |
0 |
ErrorLog.errPrintln("Failed to get channel property '" + key + "'"); |
220 |
|
} |
221 |
|
} |
222 |
0 |
return null; |
223 |
|
} |
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0 |
public static Image getImage(String key)... |
231 |
|
{ |
232 |
0 |
return getImage(key, null, true); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
public static Image getImage(String key, Image defaultImg)... |
241 |
|
{ |
242 |
0 |
return getImage(key, defaultImg, false); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 9 |
Complexity Density: 0.53 |
|
248 |
0 |
private static Image getImage(String key, Image defaultImg,... |
249 |
|
boolean useClassDefaultImage) |
250 |
|
{ |
251 |
0 |
Image img = null; |
252 |
0 |
if (imageMap().containsKey(key)) |
253 |
|
{ |
254 |
0 |
img = imageMap().get(key); |
255 |
|
} |
256 |
|
|
257 |
0 |
if (img == null) |
258 |
|
{ |
259 |
0 |
String path = getProperty(key, null, useClassDefaultImage); |
260 |
0 |
if (path == null) |
261 |
|
|
262 |
|
{ |
263 |
0 |
return useClassDefaultImage ? null : defaultImg; |
264 |
|
} |
265 |
|
|
266 |
0 |
URL imageURL = ChannelProperties.class.getResource(path); |
267 |
0 |
ImageIcon imgIcon = imageURL == null ? null : new ImageIcon(imageURL); |
268 |
0 |
img = imgIcon == null ? null : imgIcon.getImage(); |
269 |
0 |
if (img == null) |
270 |
|
{ |
271 |
0 |
ErrorLog.errPrintln( |
272 |
|
"Failed to load channel image " + key + "=" + path); |
273 |
0 |
if (!useClassDefaultImage) |
274 |
|
{ |
275 |
0 |
return defaultImg; |
276 |
|
} |
277 |
|
} |
278 |
|
else |
279 |
|
{ |
280 |
0 |
imageMap().put(key, img); |
281 |
0 |
urlMap.put(key, imageURL); |
282 |
|
} |
283 |
|
} |
284 |
0 |
return img; |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
290 |
0 |
public static URL getImageURL(String key)... |
291 |
|
{ |
292 |
0 |
if (getImage(key) != null) |
293 |
|
{ |
294 |
0 |
if (urlMap().containsKey(key)) |
295 |
|
{ |
296 |
0 |
return urlMap().getOrDefault(key, null); |
297 |
|
} |
298 |
0 |
ErrorLog.errPrintln( |
299 |
|
"Do not use getImageURL(key) before using getImage(key...)"); |
300 |
|
} |
301 |
0 |
return null; |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
307 |
0 |
public static ArrayList<Image> getIconList()... |
308 |
|
{ |
309 |
0 |
return iconList; |
310 |
|
} |
311 |
|
} |