| 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 |
|
|
| |
|
| 61.4% |
Uncovered Elements: 56 (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 |
|
|
| |
|
| 64.5% |
Uncovered Elements: 22 (62) |
Complexity: 9 |
Complexity Density: 0.19 |
|
| 56 |
55 |
static... |
| 57 |
|
{ |
| 58 |
55 |
defaultProps = new Properties(); |
| 59 |
|
|
| 60 |
|
|
| 61 |
55 |
defaultProps.put("app_name", FALLBACK_APPNAME); |
| 62 |
55 |
defaultProps.put("banner", "/default_images/jalview_banner.png"); |
| 63 |
55 |
defaultProps.put("logo.16", "/default_images/jalview_logo-16.png"); |
| 64 |
55 |
defaultProps.put("logo.32", "/default_images/jalview_logo-32.png"); |
| 65 |
55 |
defaultProps.put("logo.38", "/default_images/jalview_logo-38.png"); |
| 66 |
55 |
defaultProps.put("logo.48", "/default_images/jalview_logo-48.png"); |
| 67 |
55 |
defaultProps.put("logo.64", "/default_images/jalview_logo-64.png"); |
| 68 |
55 |
defaultProps.put("logo.128", "/default_images/jalview_logo-128.png"); |
| 69 |
55 |
defaultProps.put("logo.256", "/default_images/jalview_logo-256.png"); |
| 70 |
55 |
defaultProps.put("logo.512", "/default_images/jalview_logo-512.png"); |
| 71 |
55 |
defaultProps.put("rotatable_logo.48", |
| 72 |
|
"/default_images/rotatable_jalview_logo-38.png"); |
| 73 |
55 |
defaultProps.put("bg_logo.28", "/default_images/barton_group-28.png"); |
| 74 |
55 |
defaultProps.put("bg_logo.30", "/default_images/barton_group-30.png"); |
| 75 |
55 |
defaultProps.put("bg_logo.32", "/default_images/barton_group-32.png"); |
| 76 |
55 |
defaultProps.put("uod_banner.28", "/default_images/UoD_banner-28.png"); |
| 77 |
55 |
defaultProps.put("uod_banner.30", "/default_images/UoD_banner-30.png"); |
| 78 |
55 |
defaultProps.put("uod_banner.32", "/default_images/UoD_banner-32.png"); |
| 79 |
55 |
defaultProps.put("default_appbase", |
| 80 |
|
"https://www.jalview.org/getdown/release/1.8"); |
| 81 |
55 |
defaultProps.put("preferences.filename", ".jalview_properties"); |
| 82 |
55 |
defaultProps.put("channel", "none"); |
| 83 |
|
|
| 84 |
|
|
| 85 |
55 |
Properties tryChannelProps = new Properties(); |
| 86 |
55 |
URL channelPropsURL = ChannelProperties.class |
| 87 |
|
.getResource("/" + CHANNEL_PROPERTIES_FILENAME); |
| 88 |
55 |
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 |
55 |
try |
| 101 |
|
{ |
| 102 |
55 |
InputStream channelPropsIS = HttpUtils.openStream(channelPropsURL); |
| 103 |
55 |
tryChannelProps.load(channelPropsIS); |
| 104 |
55 |
channelPropsIS.close(); |
| 105 |
|
} catch (IOException e) |
| 106 |
|
{ |
| 107 |
0 |
ErrorLog.errPrintln(e.getMessage()); |
| 108 |
|
|
| 109 |
|
} |
| 110 |
|
} |
| 111 |
55 |
channelProps = tryChannelProps; |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
55 |
iconList = new ArrayList<Image>(); |
| 120 |
55 |
List<String> sizes = Arrays.asList("16", "32", "48", "64", "128", "256", |
| 121 |
|
"512"); |
| 122 |
55 |
for (String size : sizes) |
| 123 |
|
{ |
| 124 |
385 |
Image logo = null; |
| 125 |
|
|
| 126 |
385 |
logo = ChannelProperties.getImage("logo." + size, null, false); |
| 127 |
385 |
if (logo != null) |
| 128 |
|
{ |
| 129 |
385 |
iconList.add(logo); |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
|
| 133 |
55 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 170 |
6876 |
private static Properties channelProps()... |
| 171 |
|
{ |
| 172 |
6876 |
return channelProps; |
| 173 |
|
} |
| 174 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
1186 |
private static Map<String, Image> imageMap()... |
| 176 |
|
{ |
| 177 |
1186 |
return imageMap; |
| 178 |
|
} |
| 179 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 180 |
216 |
private static Map<String, URL> urlMap()... |
| 181 |
|
{ |
| 182 |
216 |
return urlMap; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 189 |
1794 |
public static String getProperty(String key)... |
| 190 |
|
{ |
| 191 |
1794 |
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 |
|
|
| |
|
| 63.6% |
Uncovered Elements: 4 (11) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 206 |
2292 |
private static String getProperty(String key, String defaultVal,... |
| 207 |
|
boolean useClassDefaultProps) |
| 208 |
|
{ |
| 209 |
2292 |
if (channelProps() != null) |
| 210 |
|
{ |
| 211 |
2292 |
if (channelProps().containsKey(key)) |
| 212 |
|
{ |
| 213 |
2292 |
return channelProps().getProperty(key, |
| 214 |
2292 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 230 |
208 |
public static Image getImage(String key)... |
| 231 |
|
{ |
| 232 |
208 |
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 |
|
|
| |
|
| 63.6% |
Uncovered Elements: 12 (33) |
Complexity: 9 |
Complexity Density: 0.53 |
|
| 248 |
593 |
private static Image getImage(String key, Image defaultImg,... |
| 249 |
|
boolean useClassDefaultImage) |
| 250 |
|
{ |
| 251 |
593 |
Image img = null; |
| 252 |
593 |
if (imageMap().containsKey(key)) |
| 253 |
|
{ |
| 254 |
95 |
img = imageMap().get(key); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
593 |
if (img == null) |
| 258 |
|
{ |
| 259 |
498 |
String path = getProperty(key, null, useClassDefaultImage); |
| 260 |
498 |
if (path == null) |
| 261 |
|
|
| 262 |
|
{ |
| 263 |
0 |
return useClassDefaultImage ? null : defaultImg; |
| 264 |
|
} |
| 265 |
|
|
| 266 |
498 |
URL imageURL = ChannelProperties.class.getResource(path); |
| 267 |
498 |
ImageIcon imgIcon = imageURL == null ? null : new ImageIcon(imageURL); |
| 268 |
498 |
img = imgIcon == null ? null : imgIcon.getImage(); |
| 269 |
498 |
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 |
498 |
imageMap().put(key, img); |
| 281 |
498 |
urlMap.put(key, imageURL); |
| 282 |
|
} |
| 283 |
|
} |
| 284 |
593 |
return img; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
|
|
| 289 |
|
|
| |
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 290 |
108 |
public static URL getImageURL(String key)... |
| 291 |
|
{ |
| 292 |
108 |
if (getImage(key) != null) |
| 293 |
|
{ |
| 294 |
108 |
if (urlMap().containsKey(key)) |
| 295 |
|
{ |
| 296 |
108 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 307 |
227 |
public static ArrayList<Image> getIconList()... |
| 308 |
|
{ |
| 309 |
227 |
return iconList; |
| 310 |
|
} |
| 311 |
|
} |