JAL-3626 from JAL-3253-applet web page embedding
[jalview.git] / src / jalview / gui / Desktop.java
index 6bb9b36..1b85dd5 100644 (file)
  */
 package jalview.gui;
 
-import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
-import jalview.bin.Cache;
-import jalview.bin.Jalview;
-import jalview.gui.ImageExporter.ImageWriterI;
-import jalview.io.BackupFiles;
-import jalview.io.DataSourceType;
-import jalview.io.FileFormat;
-import jalview.io.FileFormatException;
-import jalview.io.FileFormatI;
-import jalview.io.FileFormats;
-import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
-import jalview.io.IdentifyFile;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.jbgui.GSplitFrame;
-import jalview.jbgui.GStructureViewer;
-import jalview.project.Jalview2XML;
-import jalview.structure.StructureSelectionManager;
-import jalview.urls.IdOrgSettings;
-import jalview.util.BrowserLauncher;
-import jalview.util.ImageMaker.TYPE;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-import jalview.util.ShortcutKeyMaskExWrapper;
-import jalview.util.UrlConstants;
-import jalview.viewmodel.AlignmentViewport;
-import jalview.ws.params.ParamManager;
-import jalview.ws.utils.UrlDownloadClient;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -123,6 +92,37 @@ import javax.swing.event.InternalFrameEvent;
 
 import org.stackoverflowusers.file.WindowsShortcut;
 
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.gui.ImageExporter.ImageWriterI;
+import jalview.io.BackupFiles;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
+import jalview.io.FileLoader;
+import jalview.io.FormatAdapter;
+import jalview.io.IdentifyFile;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.jbgui.GSplitFrame;
+import jalview.jbgui.GStructureViewer;
+import jalview.project.Jalview2XML;
+import jalview.structure.StructureSelectionManager;
+import jalview.urls.IdOrgSettings;
+import jalview.util.BrowserLauncher;
+import jalview.util.ImageMaker.TYPE;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.ShortcutKeyMaskExWrapper;
+import jalview.util.UrlConstants;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.params.ParamManager;
+import jalview.ws.utils.UrlDownloadClient;
+
 /**
  * Jalview Desktop
  * 
@@ -134,6 +134,15 @@ public class Desktop extends jalview.jbgui.GDesktop
         implements DropTargetListener, ClipboardOwner, IProgressIndicator,
         jalview.api.StructureSelectionManagerProvider
 {
+  private static final String CITATION = "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
+          + "<br><br>For help, see the FAQ at <a href=\"http://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list"
+          + "<br><br>If  you use Jalview, please cite:"
+          + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
+          + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
+          + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033";
+
+  private static final String DEFAULT_AUTHORS = "The Jalview Authors (See AUTHORS file for current list)";
+
   private static int DEFAULT_MIN_WIDTH = 300;
 
   private static int DEFAULT_MIN_HEIGHT = 250;
@@ -146,7 +155,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT";
 
-  public static HashMap<String, FileWriter> savingFiles = new HashMap<>();
+  public static HashMap<String, FileWriter> savingFiles = new HashMap<String, FileWriter>();
 
   private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
 
@@ -195,6 +204,16 @@ public class Desktop extends jalview.jbgui.GDesktop
   /** Singleton Desktop instance */
   public static Desktop instance;
 
+  /**
+   * BH TEMPORARY ONLY -- should use ApplicationSingleton
+   * 
+   * @return
+   */
+  public static Desktop getInstance()
+  {
+    return instance;
+  }
+
   public static MyDesktopPane desktop;
 
   public static MyDesktopPane getDesktop()
@@ -440,20 +459,8 @@ public class Desktop extends jalview.jbgui.GDesktop
      * @j2sIgnore
      */
     {
-
       jconsole = new Console(this, showjconsole);
-      // add essential build information
-      jconsole.setHeader("Jalview Version: "
-              + Cache.getProperty("VERSION") + "\n"
-              + "Jalview Installation: "
-              + Cache.getDefault("INSTALLATION", "unknown")
-              + "\n" + "Build Date: "
-              + Cache.getDefault("BUILD_DATE", "unknown") + "\n"
-              + "Java version: " + System.getProperty("java.version") + "\n"
-              + System.getProperty("os.arch") + " "
-              + System.getProperty("os.name") + " "
-              + System.getProperty("os.version"));
-
+      jconsole.setHeader(Cache.getVersionDetailsForConsole());
       showConsole(showjconsole);
 
       showNews.setVisible(false);
@@ -471,7 +478,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         @Override
         public void run()
         {
-          new SplashScreen();
+          new SplashScreen(true);
         }
       });
 
@@ -874,8 +881,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     frame.setMaximizable(resizable);
     frame.setIconifiable(resizable);
     frame.setOpaque(Platform.isJS());
-
-    if (frame.getX() < 1 && frame.getY() < 1)
+    boolean isEmbedded = (Platform.getDimIfEmbedded(frame, -1, -1) != null);
+    if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1)
     {
       frame.setLocation(xOffset * openFrameCount,
               yOffset * ((openFrameCount - 1) % 10) + yOffset);
@@ -1346,52 +1353,40 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   public void aboutMenuItem_actionPerformed(ActionEvent e)
   {
-    // StringBuffer message = getAboutMessage(false);
-    // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-    //
-    // message.toString(), "About Jalview", JvOptionPane.INFORMATION_MESSAGE);
     new Thread(new Runnable()
     {
       @Override
       public void run()
       {
-        new SplashScreen(true);
+        new SplashScreen(false);
       }
     }).start();
   }
 
-  public StringBuffer getAboutMessage(boolean shortv)
+  /**
+   * Returns the html text for the About screen, including any available version
+   * number, build details, author details and citation reference, but without
+   * the enclosing {@code html} tags
+   * 
+   * @return
+   */
+  public String getAboutMessage()
   {
-    StringBuffer message = new StringBuffer();
-    message.append("<html>");
-    if (shortv)
-    {
-      message.append("<h1><strong>Version: "
-              + Cache.getProperty("VERSION")
-              + "</strong></h1>");
-      message.append("<strong>Built: <em>"
-              + Cache.getDefault("BUILD_DATE", "unknown") + "</em> from "
-              + Cache.getBuildDetailsForSplash()
-              + "</strong>");
+    StringBuilder message = new StringBuilder(1024);
+    message.append("<h1><strong>Version: ")
+            .append(Cache.getProperty("VERSION")).append("</strong></h1>")
+            .append("<strong>Built: <em>")
+            .append(Cache.getDefault("BUILD_DATE", "unknown"))
+            .append("</em> from ").append(Cache.getBuildDetailsForSplash())
+            .append("</strong>");
 
-    }
-    else
-    {
-
-      message.append("<strong>Version "
-              + Cache.getProperty("VERSION")
-              + "; last updated: "
-              + Cache.getDefault("BUILD_DATE", "unknown"));
-    }
-
-    if (Cache.getDefault("LATEST_VERSION", "Checking")
-            .equals("Checking"))
+    String latestVersion = Cache.getDefault("LATEST_VERSION", "Checking");
+    if (latestVersion.equals("Checking"))
     {
       // JBP removed this message for 2.11: May be reinstated in future version
       // message.append("<br>...Checking latest version...</br>");
     }
-    else if (!Cache.getDefault("LATEST_VERSION", "Checking")
-            .equals(Cache.getProperty("VERSION")))
+    else if (!latestVersion.equals(Cache.getProperty("VERSION")))
     {
       boolean red = false;
       if (Cache.getProperty("VERSION").toLowerCase()
@@ -1403,29 +1398,22 @@ public class Desktop extends jalview.jbgui.GDesktop
         message.append("<div style=\"color: #FF0000;font-style: bold;\">");
       }
 
-      message.append("<br>!! Version "
-              + Cache.getDefault("LATEST_VERSION",
-                      "..Checking..")
-              + " is available for download from "
-              + Cache.getDefault("www.jalview.org",
-                      "http://www.jalview.org")
-              + " !!");
+      message.append("<br>!! Version ")
+              .append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
+              .append(" is available for download from ")
+              .append(Cache.getDefault("www.jalview.org",
+                      "http://www.jalview.org"))
+              .append(" !!");
       if (red)
       {
         message.append("</div>");
       }
     }
-    message.append("<br>Authors:  " + Cache.getDefault(
-            "AUTHORFNAMES",
-            "The Jalview Authors (See AUTHORS file for current list)")
-            + "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
-            + "<br><br>For help, see the FAQ at <a href=\"http://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list"
-            + "<br><br>If  you use Jalview, please cite:"
-            + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
-            + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
-            + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
-            + "</html>");
-    return message;
+    message.append("<br>Authors:  ");
+    message.append(Cache.getDefault("AUTHORFNAMES", DEFAULT_AUTHORS));
+    message.append(CITATION);
+
+    return message.toString();
   }
 
   /**
@@ -1789,7 +1777,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           {
                try 
             {
-              new Jalview2XML().loadJalviewAlign(choice);
+              new Jalview2XML().loadJalviewAlign(selectedFile);
             } catch (OutOfMemoryError oom)
                {
                  new OOMWarning("Whilst loading project from " + choice, oom);
@@ -1996,11 +1984,28 @@ public class Desktop extends jalview.jbgui.GDesktop
       return;
     }
 
+    // FIXME: ideally should use UI interface API
+    FeatureSettings viewFeatureSettings = (af.featureSettings != null
+            && af.featureSettings.isOpen())
+            ? af.featureSettings
+            : null;
+    Rectangle fsBounds = af.getFeatureSettingsGeometry();
     for (int i = 0; i < size; i++)
     {
       AlignmentPanel ap = af.alignPanels.get(i);
+
       AlignFrame newaf = new AlignFrame(ap);
 
+      // transfer reference for existing feature settings to new alignFrame
+      if (ap == af.alignPanel)
+      {
+        if (viewFeatureSettings != null && viewFeatureSettings.fr.ap == ap)
+        {
+          newaf.featureSettings = viewFeatureSettings;
+        }
+        newaf.setFeatureSettingsGeometry(fsBounds);
+      }
+
       /*
        * Restore the view's last exploded frame geometry if known. Multiple
        * views from one exploded frame share and restore the same (frame)
@@ -2016,8 +2021,17 @@ public class Desktop extends jalview.jbgui.GDesktop
 
       addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
               AlignFrame.DEFAULT_HEIGHT);
+      // and materialise a new feature settings dialog instance for the new alignframe
+      // (closes the old as if 'OK' was pressed)
+      if (ap == af.alignPanel && newaf.featureSettings != null
+              && newaf.featureSettings.isOpen()
+              && af.alignPanel.getAlignViewport().isShowSequenceFeatures())
+      {
+        newaf.showFeatureSettingsUI();
+      }
     }
 
+    af.featureSettings = null;
     af.alignPanels.clear();
     af.closeMenuItem_actionPerformed(true);
 
@@ -2037,7 +2051,6 @@ public class Desktop extends jalview.jbgui.GDesktop
     source.viewport.setExplodedGeometry(source.getBounds());
     JInternalFrame[] frames = desktop.getAllFrames();
     String viewId = source.viewport.getSequenceSetId();
-
     for (int t = 0; t < frames.length; t++)
     {
       if (frames[t] instanceof AlignFrame && frames[t] != source)
@@ -2058,11 +2071,33 @@ public class Desktop extends jalview.jbgui.GDesktop
 
         if (gatherThis)
         {
+          if (af.featureSettings != null && af.featureSettings.isOpen())
+          {
+            if (source.featureSettings == null)
+            {
+              // preserve the feature settings geometry for this frame
+              source.featureSettings = af.featureSettings;
+              source.setFeatureSettingsGeometry(
+                      af.getFeatureSettingsGeometry());
+            }
+            else
+            {
+              // close it and forget
+              af.featureSettings.close();
+            }
+          }
           af.alignPanels.clear();
           af.closeMenuItem_actionPerformed(true);
         }
       }
     }
+
+    // refresh the feature setting UI for the source frame if it exists
+    if (source.featureSettings != null
+            && source.featureSettings.isOpen())
+    {
+      source.showFeatureSettingsUI();
+    }
   }
 
   public JInternalFrame[] getAllFrames()
@@ -2464,7 +2499,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   public void setProgressBar(String message, long id)
   {
-           Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);     
+    // Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);
 
     if (progressBars == null)
     {
@@ -3339,4 +3374,5 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     return result;
   }
+
 }