JAL-3594 New jalview.util.ChannelProperties to get/cache values and images used in...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 4 Dec 2020 17:16:39 +0000 (17:16 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 4 Dec 2020 17:16:39 +0000 (17:16 +0000)
21 files changed:
build.gradle
resources/images/JalviewLogo_Huge.png [deleted file]
resources/images/JalviewLogo_big.png [deleted file]
resources/images/Jalview_Develop_Logo.png [deleted file]
resources/images/Jalview_Logo.png [deleted file]
resources/images/Jalview_Logo_small.png [deleted file]
resources/images/jalview_logo_background_fade-640x480.png [deleted file]
src/jalview/bin/JalviewTaskbar.java
src/jalview/bin/Launcher.java
src/jalview/gui/SplashScreen.java
src/jalview/util/ChannelProperties.java [new file with mode: 0644]
utils/channels/develop/images/jalview_develop_getdown_background.xcf
utils/channels/develop/resources/channel_properties
utils/channels/develop/resources/images/jalview_develop_banner.png
utils/channels/release/channel_gradle.properties
utils/channels/release/images/jalview_getdown_background.png
utils/channels/release/images/jalview_getdown_background.xcf
utils/channels/release/images/jalview_getdown_background_error.png
utils/channels/release/images/jalview_getdown_background_initialising.png
utils/channels/release/resources/channel_properties
utils/channels/release/resources/images/jalview_banner.png

index bdc50d0..1b55708 100644 (file)
@@ -57,12 +57,13 @@ def string(Object o) {
   return o == null ? "" : o.toString()
 }
 
-def overrideProperties(def propsFileName) {
+def overrideProperties(String propsFileName, boolean output = false) {
   if (propsFileName == null) {
     return
   }
   def propsFile = file(propsFileName)
   if (propsFile != null && propsFile.exists()) {
+    println("Using properties from file '${propsFileName}'")
     try {
       def p = new Properties()
       def localPropsFIS = new FileInputStream(propsFile)
@@ -74,12 +75,15 @@ def overrideProperties(def propsFileName) {
           if (project.hasProperty(key)) {
             oldval = project.findProperty(key)
             project.setProperty(key, val)
-            println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
+            if (output) {
+              println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
+            }
           } else {
             ext.setProperty(key, val)
-            println("Setting ext property '${key}' with ${file(propsFile).getName()}s value '${val}'")
+            if (output) {
+              println("Setting ext property '${key}' with ${file(propsFile).getName()}s value '${val}'")
+            }
           }
-          //true
       }
     } catch (Exception e) {
       println("Exception reading local.properties")
@@ -98,12 +102,12 @@ ext {
   // Import channel_properties
   channelDir = string("${jalviewDir}/${channel_properties_dir}/${propertiesChannelName}")
   channelGradleProperties = string("${channelDir}/channel_gradle.properties")
-  overrideProperties(channelGradleProperties)
+  overrideProperties(channelGradleProperties, false)
   // local build environment properties
   // can be "projectDir/local.properties"
-  overrideProperties("${projectDir}/local.properties")
+  overrideProperties("${projectDir}/local.properties", true)
   // or "../projectDir_local.properties"
-  overrideProperties(projectDir.getParent() + "/" + projectDir.getName() + "_local.properties")
+  overrideProperties(projectDir.getParent() + "/" + projectDir.getName() + "_local.properties", true)
 
   ////  
   // Import releaseProps from the RELEASE file
diff --git a/resources/images/JalviewLogo_Huge.png b/resources/images/JalviewLogo_Huge.png
deleted file mode 100644 (file)
index 340f8e5..0000000
Binary files a/resources/images/JalviewLogo_Huge.png and /dev/null differ
diff --git a/resources/images/JalviewLogo_big.png b/resources/images/JalviewLogo_big.png
deleted file mode 100644 (file)
index d0ade1e..0000000
Binary files a/resources/images/JalviewLogo_big.png and /dev/null differ
diff --git a/resources/images/Jalview_Develop_Logo.png b/resources/images/Jalview_Develop_Logo.png
deleted file mode 100644 (file)
index 0fbe361..0000000
Binary files a/resources/images/Jalview_Develop_Logo.png and /dev/null differ
diff --git a/resources/images/Jalview_Logo.png b/resources/images/Jalview_Logo.png
deleted file mode 100644 (file)
index 8e35408..0000000
Binary files a/resources/images/Jalview_Logo.png and /dev/null differ
diff --git a/resources/images/Jalview_Logo_small.png b/resources/images/Jalview_Logo_small.png
deleted file mode 100644 (file)
index 6206a1c..0000000
Binary files a/resources/images/Jalview_Logo_small.png and /dev/null differ
diff --git a/resources/images/jalview_logo_background_fade-640x480.png b/resources/images/jalview_logo_background_fade-640x480.png
deleted file mode 100644 (file)
index 4b65200..0000000
Binary files a/resources/images/jalview_logo_background_fade-640x480.png and /dev/null differ
index da83a09..c7ababa 100644 (file)
@@ -23,6 +23,8 @@ package jalview.bin;
 import java.awt.Image;
 import java.awt.Taskbar;
 
+import jalview.util.ChannelProperties;
+
 public class JalviewTaskbar
 {
   public JalviewTaskbar()
@@ -31,23 +33,18 @@ public class JalviewTaskbar
 
   protected static void setTaskbar(Jalview jalview)
   {
-    
+
     if (Taskbar.isTaskbarSupported())
     {
       Taskbar tb = Taskbar.getTaskbar();
       if (tb.isSupported(Taskbar.Feature.ICON_IMAGE))
       {
-        try
+        Image image = ChannelProperties.getImage("logo.512");
+        if (image != null)
         {
-          java.net.URL url = jalview.getClass()
-                  .getResource("/images/JalviewLogo_Huge.png");
-          if (url != null)
-          {
-            Image image = java.awt.Toolkit.getDefaultToolkit()
-                    .createImage(url);
-            tb.setIconImage(image);
-          }
-        } catch (Exception e)
+          tb.setIconImage(image);
+        }
+        else
         {
           System.out.println("Unable to setIconImage()");
         }
@@ -55,5 +52,4 @@ public class JalviewTaskbar
     }
 
   }
-
 }
index 5e6e48c..c8f2f48 100644 (file)
@@ -26,6 +26,8 @@ import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.List;
 
+import jalview.util.ChannelProperties;
+
 /**
  * A Launcher class for Jalview. This class is used to launch Jalview from the
  * shadowJar when Getdown is not used or available. It attempts to take all the
@@ -45,7 +47,8 @@ public class Launcher
 {
   private final static String startClass = "jalview.bin.Jalview";
 
-  private final static String dockIconPath = "JalviewLogo_Huge.png";
+  private final static String dockIconPath = ChannelProperties
+          .getProperty("logo.512");
 
   /**
    * main method for jalview.bin.Launcher. This restarts the same JRE's JVM with
index f4b275d..76168ba 100755 (executable)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import jalview.util.Platform;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -30,10 +28,8 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.MediaTracker;
-import java.awt.Toolkit;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.net.URL;
 
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
@@ -43,6 +39,9 @@ import javax.swing.JTextPane;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
 
+import jalview.util.ChannelProperties;
+import jalview.util.Platform;
+
 /**
  * DOCUMENT ME!
  * 
@@ -136,17 +135,19 @@ public class SplashScreen extends JPanel
 
     try
     {
-      URL url = getClass().getResource("/images/Jalview_Logo.png");
-      URL urllogo = getClass()
-              .getResource("/images/Jalview_Logo_small.png");
-
-      if (!Platform.isJS() && url != null)
+      if (!Platform.isJS())
       {
-        image = Toolkit.getDefaultToolkit().createImage(url);
-        Image logo = Toolkit.getDefaultToolkit().createImage(urllogo);
+        image = ChannelProperties.getImage("banner");
+        Image logo = ChannelProperties.getImage("logo.48");
         MediaTracker mt = new MediaTracker(this);
-        mt.addImage(image, 0);
-        mt.addImage(logo, 1);
+        if (image != null)
+        {
+          mt.addImage(image, 0);
+        }
+        if (logo != null)
+        {
+          mt.addImage(logo, 1);
+        }
         do
         {
           try
@@ -212,7 +213,7 @@ public class SplashScreen extends JPanel
          * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
          * to display formatted html, so we use a simple alternative
          */
-        String text = "<html><br><br><img src=\"swingjs/j2s/images/Jalview_Logo.png\"/><br>"
+        String text = "<html><br><br><img src=\"swingjs/j2s/images/jalview_logo-48.png\"/><br>"
                 + newtext + "</html>";
         JLabel ta = new JLabel(text);
         ta.setOpaque(true);
@@ -269,8 +270,8 @@ public class SplashScreen extends JPanel
       {
       }
 
-      if (transientDialog
-              && ((System.currentTimeMillis() / 1000) - startTime) > SHOW_FOR_SECS)
+      if (transientDialog && ((System.currentTimeMillis() / 1000)
+              - startTime) > SHOW_FOR_SECS)
       {
         visible = false;
       }
diff --git a/src/jalview/util/ChannelProperties.java b/src/jalview/util/ChannelProperties.java
new file mode 100644 (file)
index 0000000..5d7f795
--- /dev/null
@@ -0,0 +1,136 @@
+package jalview.util;
+
+import java.awt.Image;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.swing.ImageIcon;
+
+import jalview.bin.Cache;
+
+public class ChannelProperties
+{
+
+  private static final String CHANNEL_PROPERTIES_FILENAME = "/channel_properties";
+
+  private Properties channelProps = new Properties();
+
+  private Map<String, Image> imageMap = new HashMap<String, Image>();
+
+  private static ChannelProperties instance;
+
+  private boolean initDone = false;
+
+  private boolean init()
+  {
+    if (initDone)
+    {
+      return initDone;
+    }
+    // load channel_properties
+    URL channelPropsURL = getClass()
+            .getResource(CHANNEL_PROPERTIES_FILENAME);
+    if (channelPropsURL == null)
+    {
+      // fallback
+      System.err.println(
+              "Failed to find '" + CHANNEL_PROPERTIES_FILENAME + "' file");
+      return false;
+    }
+    else
+    {
+      try
+      {
+        InputStream channelPropsIS = channelPropsURL.openStream();
+        channelProps.load(channelPropsIS);
+        channelPropsIS.close();
+      } catch (IOException e)
+      {
+        Cache.log.warn(e.getMessage());
+        return false;
+      }
+    }
+    initDone = true;
+    return initDone;
+  }
+
+  private ChannelProperties()
+  {
+    init();
+  }
+
+  public static ChannelProperties getChannelProperties()
+  {
+    if (instance == null)
+    {
+      instance = new ChannelProperties();
+    }
+    return instance;
+  }
+
+  public static String getProperty(String key)
+  {
+    return getProperty(key, null);
+  }
+
+  private static Properties channelProps()
+  {
+    return getChannelProperties().channelProps;
+  }
+
+  private static Map<String, Image> imageMap()
+  {
+    return getChannelProperties().imageMap;
+  }
+
+  public static String getProperty(String key, String defaultVal)
+  {
+    if (channelProps() != null)
+    {
+      if (channelProps().containsKey(key))
+      {
+        String val = channelProps().getProperty(key, "NOTFOUND");
+        return channelProps().getProperty(key, defaultVal);
+      }
+      else
+      {
+        System.err.println("Failed to get channel property '" + key + "'");
+      }
+    }
+    return null;
+  }
+
+  public static Image getImage(String key)
+  {
+    Image img = null;
+    if (imageMap().containsKey(key))
+    {
+      img = imageMap().get(key);
+    }
+    // Catch a previously untried or failed load
+    if (img == null)
+    {
+      String path = getProperty(key);
+      if (path == null)
+      {
+        return null;
+      }
+      URL imageURL = getChannelProperties().getClass().getResource(path);
+      img = new ImageIcon(imageURL).getImage();
+      if (img == null)
+      {
+        System.err.println(
+                "Failed to load channel image " + key + "=" + path);
+      }
+      else
+      {
+        imageMap().put(key, img);
+      }
+    }
+    return img;
+  }
+}
\ No newline at end of file
index ad4eb90..d3890a9 100644 (file)
Binary files a/utils/channels/develop/images/jalview_develop_getdown_background.xcf and b/utils/channels/develop/images/jalview_develop_getdown_background.xcf differ
index d487bbf..5216005 100644 (file)
@@ -1,11 +1,11 @@
-channel.app_name=Jalview
-channel.banner=images/jalview_banner.png
-channel.logo.512=images/jalview_logo-512.png
-channel.logo.256=images/jalview_logo-256.png
-channel.logo.128=images/jalview_logo-128.png
-channel.logo.64=images/jalview_logo-64.png
-channel.logo.48=images/jalview_logo-48.png
-channel.logo.32=images/jalview_logo-32.png
-channel.logo.16=images/jalview_logo-16.png
-channel.rotatable_logo.48=images/rotatable_jalview_logo-48.png
-channel.default_appbase=https://www.jalview.org/getdown/develop/11
+app_name=Jalview Develop
+banner=/images/jalview_develop_banner.png
+logo.16=/images/jalview_develop_logo-16.png
+logo.32=/images/jalview_develop_logo-32.png
+logo.48=/images/jalview_develop_logo-48.png
+logo.64=/images/jalview_develop_logo-64.png
+logo.128=/images/jalview_develop_logo-128.png
+logo.256=/images/jalview_develop_logo-256.png
+logo.512=/images/jalview_develop_logo-512.png
+rotatable_logo.48=/images/rotatable_jalview_develop_logo-48.png
+default_appbase=https://www.jalview.org/getdown/develop/11
index 9f1d244..01dd162 100644 (file)
Binary files a/utils/channels/develop/resources/images/jalview_develop_banner.png and b/utils/channels/develop/resources/images/jalview_develop_banner.png differ
index b175be4..9461b58 100644 (file)
@@ -11,6 +11,7 @@ getdown_icon = jalview_logo.png
 getdown_txt_allow_offline = true
 getdown_txt_max_concurrent_downloads = 10
 getdown_txt_ui.install_error = https://www.jalview.org/faq/getdownerror
+getdown_txt_ui.hide_decorations = true
 install4j_images_dir = utils/channels/release/images
 install4j_mac_icons_file = jalview_logo.icns
 install4j_windows_icons_file = jalview_logo.ico
index aa49a40..82a01a6 100644 (file)
Binary files a/utils/channels/release/images/jalview_getdown_background.png and b/utils/channels/release/images/jalview_getdown_background.png differ
index 35f7219..7dc7827 100644 (file)
Binary files a/utils/channels/release/images/jalview_getdown_background.xcf and b/utils/channels/release/images/jalview_getdown_background.xcf differ
index 9bfe37d..028dd14 100644 (file)
Binary files a/utils/channels/release/images/jalview_getdown_background_error.png and b/utils/channels/release/images/jalview_getdown_background_error.png differ
index 225950c..52f2bb3 100644 (file)
Binary files a/utils/channels/release/images/jalview_getdown_background_initialising.png and b/utils/channels/release/images/jalview_getdown_background_initialising.png differ
index e48375a..2f63a1c 100644 (file)
@@ -1,11 +1,11 @@
-channel.app_name=Jalview
-channel.banner=images/jalview_banner.png
-channel.logo.512=images/jalview_logo-512.png
-channel.logo.256=images/jalview_logo-256.png
-channel.logo.128=images/jalview_logo-128.png
-channel.logo.64=images/jalview_logo-64.png
-channel.logo.48=images/jalview_logo-48.png
-channel.logo.32=images/jalview_logo-32.png
-channel.logo.16=images/jalview_logo-16.png
-channel.rotatable_logo.48=images/rotatable_jalview_logo-48.png
-channel.default_appbase=https://www.jalview.org/getdown/release/1.8
+app_name=Jalview
+banner=/images/jalview_banner.png
+logo.16=/images/jalview_logo-16.png
+logo.32=/images/jalview_logo-32.png
+logo.48=/images/jalview_logo-48.png
+logo.64=/images/jalview_logo-64.png
+logo.128=/images/jalview_logo-128.png
+logo.256=/images/jalview_logo-256.png
+logo.512=/images/jalview_logo-512.png
+rotatable_logo.48=/images/rotatable_jalview_logo-48.png
+default_appbase=https://www.jalview.org/getdown/release/1.8
index 8e35408..a381b83 100644 (file)
Binary files a/utils/channels/release/resources/images/jalview_banner.png and b/utils/channels/release/resources/images/jalview_banner.png differ