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 Map<String, Image> imageMap = new HashMap<String, Image>();
24 private static ChannelProperties instance;
26 private boolean initDone = false;
28 private boolean init()
34 // load channel_properties
35 URL channelPropsURL = getClass()
36 .getResource(CHANNEL_PROPERTIES_FILENAME);
37 if (channelPropsURL == null)
41 "Failed to find '" + CHANNEL_PROPERTIES_FILENAME + "' file");
48 InputStream channelPropsIS = channelPropsURL.openStream();
49 channelProps.load(channelPropsIS);
50 channelPropsIS.close();
51 } catch (IOException e)
53 Cache.log.warn(e.getMessage());
61 private ChannelProperties()
66 public static ChannelProperties getChannelProperties()
70 instance = new ChannelProperties();
75 public static String getProperty(String key)
77 return getProperty(key, null);
80 private static Properties channelProps()
82 return getChannelProperties().channelProps;
85 private static Map<String, Image> imageMap()
87 return getChannelProperties().imageMap;
90 public static String getProperty(String key, String defaultVal)
92 if (channelProps() != null)
94 if (channelProps().containsKey(key))
96 String val = channelProps().getProperty(key, "NOTFOUND");
97 return channelProps().getProperty(key, defaultVal);
101 System.err.println("Failed to get channel property '" + key + "'");
107 public static Image getImage(String key)
110 if (imageMap().containsKey(key))
112 img = imageMap().get(key);
114 // Catch a previously untried or failed load
117 String path = getProperty(key);
122 URL imageURL = getChannelProperties().getClass().getResource(path);
123 img = new ImageIcon(imageURL).getImage();
127 "Failed to load channel image " + key + "=" + path);
131 imageMap().put(key, img);