From b6f8ec5c6678d0f363c521b97bda9574d04c6338 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 9 Dec 2020 13:57:08 +0000 Subject: [PATCH] JAL-3594 JAL-3728 Added taskbar icons to desktop and Java console. Changed "Jalview" to "app_name" in various appropriate places --- src/jalview/bin/Cache.java | 22 +++-- src/jalview/gui/Console.java | 15 +++- src/jalview/gui/Desktop.java | 3 + src/jalview/gui/SplashScreen.java | 2 +- src/jalview/util/ChannelProperties.java | 133 ++++++++++++++++++++++--------- 5 files changed, 123 insertions(+), 52 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index dc71f91..e6f86fe 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -60,6 +60,7 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.UserColourScheme; import jalview.structure.StructureImportSettings; import jalview.urls.IdOrgSettings; +import jalview.util.ChannelProperties; import jalview.util.ColorUtils; import jalview.util.MessageManager; import jalview.util.Platform; @@ -356,7 +357,8 @@ public class Cache // lcastor.addAppender(ap); // jalview.bin.Cache.log.addAppender(ap); // Tell the user that debug is enabled - jalview.bin.Cache.log.debug("Jalview Debugging Output Follows."); + jalview.bin.Cache.log.debug(ChannelProperties.getProperty("app_name") + + " Debugging Output Follows."); } catch (Exception ex) { System.err.println("Problems initializing the log4j system\n"); @@ -661,8 +663,8 @@ public class Cache new BuildDetails(codeVersion, null, codeInstallation); if (printVersion && reportVersion) { - System.out.println( - "Jalview Version: " + codeVersion + codeInstallation); + System.out.println(ChannelProperties.getProperty("app_name") + + " Version: " + codeVersion + codeInstallation); } } @@ -829,7 +831,8 @@ public class Cache lvclient.addAppender(log.getAppender("JalviewLogger")); // Tell the user that debug is enabled - lvclient.debug("Jalview Vamsas Client Debugging Output Follows."); + lvclient.debug(ChannelProperties.getProperty("app_name") + + " Vamsas Client Debugging Output Follows."); } } catch (Exception e) { @@ -868,7 +871,8 @@ public class Cache lgclient.addAppender(log.getAppender("JalviewLogger")); // Tell the user that debug is enabled - lgclient.debug("Jalview Groovy Client Debugging Output Follows."); + lgclient.debug(ChannelProperties.getProperty("app_name") + + " Groovy Client Debugging Output Follows."); } } catch (Error e) { @@ -930,7 +934,7 @@ public class Cache .getConstructor(new Class[] { String.class, String.class, String.class }) .newInstance(new Object[] - { "Jalview Desktop", + { ChannelProperties.getProperty("app_name") + " Desktop", (vrs = jalview.bin.Cache.getProperty("VERSION") + "_" + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")), @@ -1206,10 +1210,12 @@ public class Cache public static String getVersionDetailsForConsole() { StringBuilder sb = new StringBuilder(); - sb.append("Jalview Version: "); + sb.append(ChannelProperties.getProperty("app_name")) + .append(" Version: "); sb.append(jalview.bin.Cache.getDefault("VERSION", "TEST")); sb.append("\n"); - sb.append("Jalview Installation: "); + sb.append(ChannelProperties.getProperty("app_name")) + .append(" Installation: "); sb.append(jalview.bin.Cache.getDefault("INSTALLATION", "unknown")); sb.append("\n"); sb.append("Build Date: "); diff --git a/src/jalview/gui/Console.java b/src/jalview/gui/Console.java index b456025..050523e 100644 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@ -54,6 +54,7 @@ import org.apache.log4j.Level; import org.apache.log4j.SimpleLayout; import jalview.bin.Cache; +import jalview.util.ChannelProperties; import jalview.util.MessageManager; /** @@ -255,6 +256,9 @@ public class Console extends WindowAdapter textAppender = new Thread(this); textAppender.setDaemon(true); textAppender.start(); + + // set icons + frame.setIconImages(ChannelProperties.getIconList()); } private void setChosenLogLevelCombo() @@ -453,13 +457,16 @@ public class Console extends WindowAdapter Rectangle bounds = desktop.getLastKnownDimensions("JAVA_CONSOLE_"); if (bounds == null) { - frame = initFrame("Jalview Java Console", desktop.getWidth() / 2, - desktop.getHeight() / 4, desktop.getX(), desktop.getY()); + frame = initFrame( + ChannelProperties.getProperty("app_name") + " Java Console", + desktop.getWidth() / 2, desktop.getHeight() / 4, + desktop.getX(), desktop.getY()); } else { - frame = initFrame("Jalview Java Console", bounds.width, bounds.height, - bounds.x, bounds.y); + frame = initFrame( + ChannelProperties.getProperty("app_name") + " Java Console", + bounds.width, bounds.height, bounds.x, bounds.y); } frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); // desktop.add(frame); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index b38a5a2..0f5a931 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -390,6 +390,7 @@ public class Desktop extends jalview.jbgui.GDesktop System.out.println("Error setting APQHandlers: " + t.toString()); // t.printStackTrace(); } + setIconImages(ChannelProperties.getIconList()); addWindowListener(new WindowAdapter() { @@ -409,6 +410,8 @@ public class Desktop extends jalview.jbgui.GDesktop showMemusage.setSelected(selmemusage); desktop.setBackground(Color.white); + this.setIconImages(ChannelProperties.getIconList()); + getContentPane().setLayout(new BorderLayout()); // alternate config - have scrollbars - see notes in JAL-153 // JScrollPane sp = new JScrollPane(); diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 76168ba..9dfd1d5 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -161,7 +161,7 @@ public class SplashScreen extends JPanel System.err.println("Error when loading images!"); } } while (!mt.checkAll()); - Desktop.instance.setIconImage(logo); + Desktop.instance.setIconImages(ChannelProperties.getIconList()); } } catch (Exception ex) { diff --git a/src/jalview/util/ChannelProperties.java b/src/jalview/util/ChannelProperties.java index 0b165c7..2194c4d 100644 --- a/src/jalview/util/ChannelProperties.java +++ b/src/jalview/util/ChannelProperties.java @@ -4,7 +4,10 @@ import java.awt.Image; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -17,15 +20,13 @@ public class ChannelProperties private static final String CHANNEL_PROPERTIES_FILENAME = "/channel_properties"; - private Properties channelProps = new Properties(); + private static final Properties channelProps; private static final Properties defaultProps; - private Map imageMap = new HashMap(); + private static Map imageMap = new HashMap(); - private static ChannelProperties instance; - - private boolean initDone = false; + private static final ArrayList iconList; static { @@ -48,64 +49,77 @@ public class ChannelProperties defaultProps.put("uod_banner", "/default_images/UoD_banner.png"); defaultProps.put("default_appbase", "https://www.jalview.org/getdown/release/1.8"); - } - private boolean init() - { - if (initDone) - { - return initDone; - } // load channel_properties - URL channelPropsURL = getClass() + Properties tryChannelProps = new Properties(); + URL channelPropsURL = ChannelProperties.class .getResource(CHANNEL_PROPERTIES_FILENAME); if (channelPropsURL == null) { - // fallback + // complete failure of channel_properties, set all properties to defaults System.err.println("Failed to find '" + CHANNEL_PROPERTIES_FILENAME - + "' filem using defaults"); - channelProps = defaultProps; - return false; + + "' file, using defaults"); + tryChannelProps = defaultProps; } else { try { InputStream channelPropsIS = channelPropsURL.openStream(); - channelProps.load(channelPropsIS); + tryChannelProps.load(channelPropsIS); channelPropsIS.close(); } catch (IOException e) { Cache.log.warn(e.getMessage()); - return false; + // return false; } } - initDone = true; - return initDone; - } - - private ChannelProperties() - { - init(); - } - - public static ChannelProperties getChannelProperties() - { - if (instance == null) + channelProps = tryChannelProps; + + /* + * The following slight palava for caching an icon list is so that all sizes of icons + * are the same. i.e. if there are /any/ channel_properties icons to use, then _only_ + * use those channel_properties icons, don't mix in class default icons for missing + * sizes. If there are _no_ (usable) channel icons then we can use the class default icons. + */ + iconList = new ArrayList(); + List sizes = Arrays.asList("16", "32", "48", "64", "128", "256", + "512"); + for (String size : sizes) { - instance = new ChannelProperties(); + Image logo = null; + // not using defaults or class props first time through + logo = ChannelProperties.getImage("logo." + size, null, false); + if (logo != null) + { + iconList.add(logo); + } + } + // now add the class defaults if there were no channel icons defined + if (iconList.size() == 0) + { + for (String size : sizes) + { + Image logo = null; + String path = defaultProps.getProperty("logo." + size); + URL imageURL = ChannelProperties.class.getResource(path); + logo = new ImageIcon(imageURL).getImage(); + if (logo != null) + { + iconList.add(logo); + } + } } - return instance; } private static Properties channelProps() { - return getChannelProperties().channelProps; + return channelProps; } private static Map imageMap() { - return getChannelProperties().imageMap; + return imageMap; } /* @@ -126,6 +140,9 @@ public class ChannelProperties return getProperty(key, defaultVal, false); } + /* + * internal method. note that setting useClassDefaultProps=true will ignore the provided defaultVal + */ private static String getProperty(String key, String defaultVal, boolean useClassDefaultProps) { @@ -145,8 +162,32 @@ public class ChannelProperties return null; } + /* + * getImage(key) returns the channel defined image for property key. If that is null (e.g. due to + * no defined channel image or the image file being corrupt/unusable/missing) it uses the image + * defined in defaultChannelProps + */ public static Image getImage(String key) { + return getImage(key, null, true); + } + + /* + * getImage(key, defaultImg) will get image associated with value from channel_properties for key. + * If no property or associated image for key is found (or is usable), it will return defaultImg + * and NOT fall back to the class defaultProps. + */ + public static Image getImage(String key, Image defaultImg) + { + return getImage(key, defaultImg, false); + } + + /* + * internal method. note that setting useClassDefaultImage=true will ignore the provided defaultImg + */ + private static Image getImage(String key, Image defaultImg, + boolean useClassDefaultImage) + { Image img = null; if (imageMap().containsKey(key)) { @@ -155,17 +196,23 @@ public class ChannelProperties // Catch a previously untried or failed load if (img == null) { - String path = getProperty(key); - if (path == null) + String path = getProperty(key, null, useClassDefaultImage); + if (path == null) // no channel property or class default property (if + // requested) { - return null; + return useClassDefaultImage ? null : defaultImg; } - URL imageURL = getChannelProperties().getClass().getResource(path); + + URL imageURL = ChannelProperties.class.getResource(path); img = new ImageIcon(imageURL).getImage(); if (img == null) { System.err.println( "Failed to load channel image " + key + "=" + path); + if (!useClassDefaultImage) + { + return defaultImg; + } } else { @@ -174,4 +221,12 @@ public class ChannelProperties } return img; } + + /* + * Get a List of Icon images of different sizes. + */ + public static ArrayList getIconList() + { + return iconList; + } } \ No newline at end of file -- 1.7.10.2