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("bg_logo.62", "/default_images/barton_group-62.png");
48 defaultProps.put("uod_banner", "/default_images/UoD_banner.png");
49 defaultProps.put("default_appbase",
50 "https://www.jalview.org/getdown/release/1.8");
53 private boolean init()
59 // load channel_properties
60 URL channelPropsURL = getClass()
61 .getResource(CHANNEL_PROPERTIES_FILENAME);
62 if (channelPropsURL == null)
65 System.err.println("Failed to find '" + CHANNEL_PROPERTIES_FILENAME
66 + "' filem using defaults");
67 channelProps = defaultProps;
74 InputStream channelPropsIS = channelPropsURL.openStream();
75 channelProps.load(channelPropsIS);
76 channelPropsIS.close();
77 } catch (IOException e)
79 Cache.log.warn(e.getMessage());
87 private ChannelProperties()
92 public static ChannelProperties getChannelProperties()
96 instance = new ChannelProperties();
101 private static Properties channelProps()
103 return getChannelProperties().channelProps;
106 private static Map<String, Image> imageMap()
108 return getChannelProperties().imageMap;
112 * getProperty(key) will get property value from channel_properties for key.
113 * If no property for key is found, it will fall back to using the defaultProps defined for this class.
115 public static String getProperty(String key)
117 return getProperty(key, null, true);
121 * getProperty(key, defaultVal) will get property value from channel_properties for key.
122 * If no property for key is found, it will return defaultVal and NOT fall back to the class defaultProps.
124 public static String getProperty(String key, String defaultVal)
126 return getProperty(key, defaultVal, false);
129 private static String getProperty(String key, String defaultVal,
130 boolean useClassDefaultProps)
132 if (channelProps() != null)
134 if (channelProps().containsKey(key))
136 return channelProps().getProperty(key,
137 useClassDefaultProps ? defaultProps.getProperty(key)
142 System.err.println("Failed to get channel property '" + key + "'");
148 public static Image getImage(String key)
151 if (imageMap().containsKey(key))
153 img = imageMap().get(key);
155 // Catch a previously untried or failed load
158 String path = getProperty(key);
163 URL imageURL = getChannelProperties().getClass().getResource(path);
164 img = new ImageIcon(imageURL).getImage();
168 "Failed to load channel image " + key + "=" + path);
172 imageMap().put(key, img);