JAL-3409 Add newline back into Buffered Reader in getdown launcher.log
[jalview.git] / getdown / src / getdown / launcher / src / main / java / com / threerings / getdown / launcher / GetdownApp.java
index 32890fa..31b2538 100644 (file)
@@ -7,7 +7,6 @@ package com.threerings.getdown.launcher;
 
 import java.awt.Color;
 import java.awt.Container;
-import java.awt.EventQueue;
 import java.awt.Image;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
@@ -27,20 +26,23 @@ import javax.swing.JFrame;
 import javax.swing.KeyStroke;
 import javax.swing.WindowConstants;
 
-import com.install4j.api.launcher.StartupNotification;
 import com.samskivert.swing.util.SwingUtil;
+import com.threerings.getdown.data.Application;
+import com.threerings.getdown.data.Build;
 import com.threerings.getdown.data.EnvConfig;
 import com.threerings.getdown.data.SysProps;
 import com.threerings.getdown.util.LaunchUtil;
 import com.threerings.getdown.util.StringUtil;
 import static com.threerings.getdown.Log.log;
+import jalview.bin.StartupNotificationListener;
+import jalview.util.HttpUtils;
 
 /**
  * The main application entry point for Getdown.
  */
 public class GetdownApp
 {
-  public static String startupFilesParameterString = "";
+  public static List<String> startupFilesParameters = new ArrayList<>();
   /**
    * The main entry point of the Getdown launcher application.
    */
@@ -91,23 +93,21 @@ public class GetdownApp
     }
     if (abort) System.exit(-1);
 
+    log.info("Starting ...");
     try
     {
-      StartupNotification.registerStartupListener(
-              new StartupNotification.Listener() {
-                @Override
-                public void startupPerformed(String parameters)
-                {
-                  GetdownApp.setStartupFilesParameterString(parameters);
-                }
-              });
+      jalview.bin.StartupNotificationListener.setListener();
     } catch (Exception e)
     {
       e.printStackTrace();
+    } catch (NoClassDefFoundError e)
+    {
+      log.warning("Starting without install4j classes");
+    } catch (Throwable t)
+    {
+      t.printStackTrace();
     }
     
-    //Thread.sleep(200);
-
     // record a few things for posterity
     log.info("------------------ VM Info ------------------");
     log.info("-- OS Name: " + System.getProperty("os.name"));
@@ -115,10 +115,14 @@ public class GetdownApp
     log.info("-- OS Vers: " + System.getProperty("os.version"));
     log.info("-- Java Vers: " + System.getProperty("java.version"));
     log.info("-- Java Home: " + System.getProperty("java.home"));
+    log.info("-- Install4j Vers: " + Application.i4jVersion);
+    log.info("-- Install4j Template Vers: " + System.getProperty("installer_template_version"));
     log.info("-- User Name: " + System.getProperty("user.name"));
     log.info("-- User Home: " + System.getProperty("user.home"));
     log.info("-- Cur dir: " + System.getProperty("user.dir"));
-    log.info("-- startupFilesParameterString: " + startupFilesParameterString);
+    log.info("-- Launcher version: "+Build.version());
+    log.info("-- startupFilesParameterString: " + getStartupFilesParameterString(getStartupFilesParameters(), false));
+    log.info("-- getStartupFilesParameterString(): " + getStartupFilesParameterString(getStartupFilesParameters(), true));
     log.info("---------------------------------------------");
 
     Getdown app = new Getdown(envc) {
@@ -133,6 +137,19 @@ public class GetdownApp
               handleWindowClose();
             }
           });
+          
+          // keep_on_top
+          try {
+                 readConfig(false);
+          } catch (Exception e) {
+                 log.warning("Error reading config for keep_on_top");
+          }
+          // move window to top, always on top
+          if (_ifc.keepOnTop) {
+                 log.info("Keep on top set to ", "keep_on_top", _ifc.keepOnTop);
+                         _frame.setAlwaysOnTop(true);
+          }
+
           // handle close on ESC
           String cancelId = "Cancel"; // $NON-NLS-1$
           _frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
@@ -165,7 +182,7 @@ public class GetdownApp
           log.warning("Failed to set background", "bg", _ifc.background, e);
         }
 
-        if (_ifc.iconImages != null) {
+        if (_ifc.iconImages != null && _ifc.iconImages.size() > 0) {
           ArrayList<Image> icons = new ArrayList<>();
           for (String path : _ifc.iconImages) {
             Image img = loadImage(path);
@@ -190,6 +207,7 @@ public class GetdownApp
           SwingUtil.centerWindow(_frame);
           _frame.setVisible(true);
         }
+        _shownContainer = true;
       }
 
       @Override
@@ -245,7 +263,7 @@ public class GetdownApp
         super.fail(message);
         // super.fail causes the UI to be created (if needed) on the next UI tick, so we
         // want to wait until that happens before we attempt to redecorate the window
-        EventQueue.invokeLater(new Runnable() {
+        EQinvoke(new Runnable() {
           @Override
           public void run() {
             // if the frame was set to be undecorated, make window decoration available
@@ -267,18 +285,41 @@ public class GetdownApp
 
       protected JFrame _frame;
     };
-    if (getStartupFilesParameterString() != null) {
-      app.setStartupFilesFromParameterString(getStartupFilesParameterString());
+    
+    if (getStartupFilesParameters().size() > 0) {
+      Application.setStartupFilesFromParameters(getStartupFilesParameters());
     }
     app.start();
     return app;
   }
   
-  public static void setStartupFilesParameterString(String parameters) {
-    startupFilesParameterString = parameters;
+  public static void addStartupFilesParameter(String parameter) {
+    startupFilesParameters.add(parameter);
+  }
+  
+  public static List<String> getStartupFilesParameters() {
+    return startupFilesParameters;
   }
   
-  public static String getStartupFilesParameterString() {
-    return startupFilesParameterString;
+  public static String getStartupFilesParameterString(List<String> parameters, boolean changeJalviewSchemeUris) {
+    StringBuilder sb = new StringBuilder();
+    boolean first = true;
+    for(String f : parameters) {
+      if (first) {
+        first = false;
+      } else {
+        sb.append(' ');
+      }
+      String p = changeJalviewSchemeUris && HttpUtils.isJalviewSchemeUri(f) ? HttpUtils.equivalentJalviewUrl(f) : f;
+      if (p.contains(" ")) {
+        sb.append('"');
+        sb.append(p);
+        sb.append('"');
+      } else {
+        sb.append(p);
+      }
+    }
+    return sb.toString();
   }
 }