4 import java.io.IOException;
5 import java.io.InputStream;
7 import java.util.HashMap;
9 import java.util.Properties;
11 import javax.swing.ImageIcon;
13 import jalview.bin.Cache;
15 public class ChannelProperties
18 private static final String CHANNEL_PROPERTIES_FILENAME = "/channel_properties";
20 private Properties channelProps = new Properties();
22 private static final Properties defaultProps;
24 private Map<String, Image> imageMap = new HashMap<String, Image>();
26 private static ChannelProperties instance;
28 private boolean initDone = false;
32 defaultProps = new Properties();
33 // these should be kept up to date, but in real life they should never
34 // actually be used anyway.
35 defaultProps.put("app_name", "Jalview");
36 defaultProps.put("banner", "/default_images/jalview_banner.png");
37 defaultProps.put("logo.16", "/default_images/jalview_logo-16.png");
38 defaultProps.put("logo.32", "/default_images/jalview_logo-32.png");
39 defaultProps.put("logo.38", "/default_images/jalview_logo-38.png");
40 defaultProps.put("logo.48", "/default_images/jalview_logo-48.png");
41 defaultProps.put("logo.64", "/default_images/jalview_logo-64.png");
42 defaultProps.put("logo.128", "/default_images/jalview_logo-128.png");
43 defaultProps.put("logo.256", "/default_images/jalview_logo-256.png");
44 defaultProps.put("logo.512", "/default_images/jalview_logo-512.png");
45 defaultProps.put("rotatable_logo.48",
46 "/default_images/rotatable_jalview_logo-38.png");
47 defaultProps.put("uod_banner", "/default_images/UoD_banner.png");
48 defaultProps.put("default_appbase",
49 "https://www.jalview.org/getdown/release/1.8");
52 private boolean init()
58 // load channel_properties
59 URL channelPropsURL = getClass()
60 .getResource(CHANNEL_PROPERTIES_FILENAME);
61 if (channelPropsURL == null)
64 System.err.println("Failed to find '" + CHANNEL_PROPERTIES_FILENAME
65 + "' filem using defaults");
66 channelProps = defaultProps;
73 InputStream channelPropsIS = channelPropsURL.openStream();
74 channelProps.load(channelPropsIS);
75 channelPropsIS.close();
76 } catch (IOException e)
78 Cache.log.warn(e.getMessage());
86 private ChannelProperties()
91 public static ChannelProperties getChannelProperties()
95 instance = new ChannelProperties();
100 private static Properties channelProps()
102 return getChannelProperties().channelProps;
105 private static Map<String, Image> imageMap()
107 return getChannelProperties().imageMap;
111 * getProperty(key) will get property value from channel_properties for key.
112 * If no property for key is found, it will fall back to using the defaultProps defined for this class.
114 public static String getProperty(String key)
116 return getProperty(key, null, true);
120 * getProperty(key, defaultVal) will get property value from channel_properties for key.
121 * If no property for key is found, it will return defaultVal and NOT fall back to the class defaultProps.
123 public static String getProperty(String key, String defaultVal)
125 return getProperty(key, defaultVal, false);
128 private static String getProperty(String key, String defaultVal,
129 boolean useClassDefaultProps)
131 if (channelProps() != null)
133 if (channelProps().containsKey(key))
135 return channelProps().getProperty(key,
136 useClassDefaultProps ? defaultProps.getProperty(key)
141 System.err.println("Failed to get channel property '" + key + "'");
147 public static Image getImage(String key)
150 if (imageMap().containsKey(key))
152 img = imageMap().get(key);
154 // Catch a previously untried or failed load
157 String path = getProperty(key);
162 URL imageURL = getChannelProperties().getClass().getResource(path);
163 img = new ImageIcon(imageURL).getImage();
167 "Failed to load channel image " + key + "=" + path);
171 imageMap().put(key, img);