JAL-3038 corrected code that reads editable JComboBox text input
[jalview.git] / src / jalview / gui / Desktop.java
index 7682ee6..abe1fad 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;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.GridLayout;
 import java.awt.Point;
 import java.awt.Rectangle;
@@ -78,6 +48,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.awt.geom.AffineTransform;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -123,6 +94,38 @@ 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.ChannelProperties;
+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,12 +137,35 @@ 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 CITATION;
+  static
+  {
+    URL bg_logo_url = ChannelProperties.getImageURL(
+            "bg_logo." + String.valueOf(SplashScreen.logoSize));
+    URL uod_logo_url = ChannelProperties.getImageURL(
+            "uod_banner." + String.valueOf(SplashScreen.logoSize));
+    boolean logo = (bg_logo_url != null || uod_logo_url != null);
+    StringBuilder sb = new StringBuilder();
+    sb.append(
+            "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.");
+    if (logo)
+    {
+      sb.append("<br>");
+    }
+    sb.append(bg_logo_url == null ? ""
+            : "<img alt=\"Barton Group logo\" src=\""
+                    + bg_logo_url.toString() + "\">");
+    sb.append(uod_logo_url == null ? ""
+            : "&nbsp;<img alt=\"University of Dundee shield\" src=\""
+                    + uod_logo_url.toString() + "\">");
+    sb.append(
+            "<br><br>For help, see the FAQ at <a href=\"https://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list");
+    sb.append("<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");
+    CITATION = sb.toString();
+  }
 
   private static final String DEFAULT_AUTHORS = "The Jalview Authors (See AUTHORS file for current list)";
 
@@ -155,10 +181,12 @@ 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();
 
+  public static boolean nosplash = false;
+
   /**
    * news reader - null if it was never started.
    */
@@ -364,7 +392,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     instance = this;
 
     doConfigureStructurePrefs();
-    setTitle("Jalview " + Cache.getProperty("VERSION"));
+    setTitle(ChannelProperties.getProperty("app_name") + " "
+            + Cache.getProperty("VERSION"));
     /*
     if (!Platform.isAMac())
     {
@@ -384,6 +413,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       System.out.println("Error setting APQHandlers: " + t.toString());
       // t.printStackTrace();
     }
+    setIconImages(ChannelProperties.getIconList());
 
     addWindowListener(new WindowAdapter()
     {
@@ -395,16 +425,16 @@ public class Desktop extends jalview.jbgui.GDesktop
       }
     });
 
-    boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE",
-            false);
+    boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false);
 
-    boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE",
-            false);
+    boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false);
     desktop = new MyDesktopPane(selmemusage);
 
     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();
@@ -462,15 +492,17 @@ public class Desktop extends jalview.jbgui.GDesktop
       checkURLLinks();
 
       // Spawn a thread that shows the splashscreen
-
-      SwingUtilities.invokeLater(new Runnable()
+      if (!nosplash)
       {
-        @Override
-        public void run()
+        SwingUtilities.invokeLater(new Runnable()
         {
-          new SplashScreen(true);
-        }
-      });
+          @Override
+          public void run()
+          {
+            new SplashScreen(true);
+          }
+        });
+      }
 
       // Thread off a new instance of the file chooser - this reduces the time
       // it
@@ -535,7 +567,6 @@ public class Desktop extends jalview.jbgui.GDesktop
       }
     });
     desktop.addMouseListener(ma);
-
   }
 
   /**
@@ -558,10 +589,10 @@ public class Desktop extends jalview.jbgui.GDesktop
             .getStructureSelectionManager(this);
     if (Cache.getDefault(Preferences.ADD_SS_ANN, true))
     {
-      ssm.setAddTempFacAnnot(Cache
-              .getDefault(Preferences.ADD_TEMPFACT_ANN, true));
-      ssm.setProcessSecondaryStructure(Cache
-              .getDefault(Preferences.STRUCT_FROM_PDB, true));
+      ssm.setAddTempFacAnnot(
+              Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true));
+      ssm.setProcessSecondaryStructure(
+              Cache.getDefault(Preferences.STRUCT_FROM_PDB, true));
       ssm.setSecStructServices(
               Cache.getDefault(Preferences.USE_RNAVIEW, true));
     }
@@ -610,7 +641,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
     }).start();
-    
+
   }
 
   @Override
@@ -655,10 +686,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     String x = Cache.getProperty(windowName + "SCREEN_X");
     String y = Cache.getProperty(windowName + "SCREEN_Y");
-    String width = Cache
-            .getProperty(windowName + "SCREEN_WIDTH");
-    String height = Cache
-            .getProperty(windowName + "SCREEN_HEIGHT");
+    String width = Cache.getProperty(windowName + "SCREEN_WIDTH");
+    String height = Cache.getProperty(windowName + "SCREEN_HEIGHT");
     if ((x != null) && (y != null) && (width != null) && (height != null))
     {
       int ix = Integer.parseInt(x), iy = Integer.parseInt(y),
@@ -668,10 +697,10 @@ public class Desktop extends jalview.jbgui.GDesktop
         // attempt #1 - try to cope with change in screen geometry - this
         // version doesn't preserve original jv aspect ratio.
         // take ratio of current screen size vs original screen size.
-        double sw = ((1f * screenSize.width) / (1f * Integer.parseInt(
-                Cache.getProperty("SCREENGEOMETRY_WIDTH"))));
-        double sh = ((1f * screenSize.height) / (1f * Integer.parseInt(
-                Cache.getProperty("SCREENGEOMETRY_HEIGHT"))));
+        double sw = ((1f * screenSize.width) / (1f * Integer
+                .parseInt(Cache.getProperty("SCREENGEOMETRY_WIDTH"))));
+        double sh = ((1f * screenSize.height) / (1f * Integer
+                .parseInt(Cache.getProperty("SCREENGEOMETRY_HEIGHT"))));
         // rescale the bounds depending upon the current screen geometry.
         ix = (int) (ix * sw);
         iw = (int) (iw * sw);
@@ -956,14 +985,14 @@ public class Desktop extends jalview.jbgui.GDesktop
     } catch (java.lang.ClassCastException cex)
     {
       Cache.log.warn(
-              "Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",
+              "Squashed a possible GUI implementation error. If you can recreate this, please look at https://issues.jalview.org/browse/JAL-869",
               cex);
     }
   }
 
   /**
-   * Add key bindings to a JInternalFrame so that Ctrl-W and Cmd-W will close the
-   * window
+   * Add key bindings to a JInternalFrame so that Ctrl-W and Cmd-W will close
+   * the window
    * 
    * @param frame
    */
@@ -1103,8 +1132,9 @@ public class Desktop extends jalview.jbgui.GDesktop
   public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
-    JalviewFileChooser chooser = JalviewFileChooser
-            .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, BackupFiles.getEnabled());
+    JalviewFileChooser chooser = JalviewFileChooser.forRead(
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat,
+            BackupFiles.getEnabled());
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
@@ -1162,12 +1192,12 @@ public class Desktop extends jalview.jbgui.GDesktop
     panel.add(label);
 
     /*
-     * the URL to fetch is
+     * the URL to fetch is input in
      * Java: an editable combobox with history
      * JS: (pending JAL-3038) a plain text field
      */
     JComponent history;
-    String urlBase = "http://www.";
+    String urlBase = "https://www.";
     if (Platform.isJS())
     {
       history = new JTextField(urlBase, 35);
@@ -1205,8 +1235,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         @SuppressWarnings("unchecked")
         String url = (history instanceof JTextField
                 ? ((JTextField) history).getText()
-                : ((JComboBox<String>) history).getSelectedItem()
-                        .toString());
+                : ((JComboBox<String>) history).getEditor().getItem()
+                        .toString().trim());
 
         if (url.toLowerCase().endsWith(".jar"))
         {
@@ -1290,10 +1320,8 @@ public class Desktop extends jalview.jbgui.GDesktop
   public void quit()
   {
     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
-    Cache.setProperty("SCREENGEOMETRY_WIDTH",
-            screen.width + "");
-    Cache.setProperty("SCREENGEOMETRY_HEIGHT",
-            screen.height + "");
+    Cache.setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
+    Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height + "");
     storeLastKnownDimensions("", new Rectangle(getBounds().x, getBounds().y,
             getWidth(), getHeight()));
 
@@ -1324,9 +1352,9 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   private void storeLastKnownDimensions(String string, Rectangle jc)
   {
-    Cache.log.debug("Storing last known dimensions for "
-            + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
-            + " height:" + jc.height);
+    Cache.log.debug("Storing last known dimensions for " + string + ": x:"
+            + jc.x + " y:" + jc.y + " width:" + jc.width + " height:"
+            + jc.height);
 
     Cache.setProperty(string + "SCREEN_X", jc.x + "");
     Cache.setProperty(string + "SCREEN_Y", jc.y + "");
@@ -1363,7 +1391,8 @@ public class Desktop extends jalview.jbgui.GDesktop
   public String getAboutMessage()
   {
     StringBuilder message = new StringBuilder(1024);
-    message.append("<h1><strong>Version: ")
+    message.append("<div style=\"font-family: sans-serif;\">")
+            .append("<h1><strong>Version: ")
             .append(Cache.getProperty("VERSION")).append("</strong></h1>")
             .append("<strong>Built: <em>")
             .append(Cache.getDefault("BUILD_DATE", "unknown"))
@@ -1392,7 +1421,7 @@ public class Desktop extends jalview.jbgui.GDesktop
               .append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
               .append(" is available for download from ")
               .append(Cache.getDefault("www.jalview.org",
-                      "http://www.jalview.org"))
+                      "https://www.jalview.org"))
               .append(" !!");
       if (red)
       {
@@ -1403,6 +1432,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     message.append(Cache.getDefault("AUTHORFNAMES", DEFAULT_AUTHORS));
     message.append(CITATION);
 
+    message.append("</div>");
+
     return message.toString();
   }
 
@@ -1416,7 +1447,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     {
       if (Platform.isJS())
       {
-        BrowserLauncher.openURL("http://www.jalview.org/help.html");
+        BrowserLauncher.openURL("https://www.jalview.org/help.html");
       }
       else
       /**
@@ -1625,7 +1656,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   protected void preferences_actionPerformed(ActionEvent e)
   {
-    new Preferences();
+    Preferences.openPreferences();
   }
 
   /**
@@ -1681,16 +1712,17 @@ public class Desktop extends jalview.jbgui.GDesktop
           setProgressBar(MessageManager.formatMessage(
                   "label.saving_jalview_project", new Object[]
                   { chosenFile.getName() }), chosenFile.hashCode());
-          Cache.setProperty("LAST_DIRECTORY",
-                  chosenFile.getParent());
+          Cache.setProperty("LAST_DIRECTORY", chosenFile.getParent());
           // TODO catch and handle errors for savestate
           // TODO prevent user from messing with the Desktop whilst we're saving
           try
           {
-               boolean doBackup = BackupFiles.getEnabled();
-            BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null;
+            boolean doBackup = BackupFiles.getEnabled();
+            BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile)
+                    : null;
 
-            new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile);
+            new Jalview2XML().saveState(
+                    doBackup ? backupfiles.getTempFile() : chosenFile);
 
             if (doBackup)
             {
@@ -1716,7 +1748,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           setProgressBar(null, chosenFile.hashCode());
         }
       }).start();
-      }
+    }
   }
 
   @Override
@@ -1747,8 +1779,10 @@ public class Desktop extends jalview.jbgui.GDesktop
         "Jalview Project (old)" };
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
-            "Jalview Project", true, BackupFiles.getEnabled()); // last two booleans: allFiles,
-                                            // allowBackupFiles
+            "Jalview Project", true, BackupFiles.getEnabled()); // last two
+                                                                // booleans:
+                                                                // allFiles,
+    // allowBackupFiles
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
     chooser.setResponseHandler(0, new Runnable()
@@ -1765,29 +1799,30 @@ public class Desktop extends jalview.jbgui.GDesktop
           @Override
           public void run()
           {
-               try 
+            try
             {
-              new Jalview2XML().loadJalviewAlign(choice);
+              new Jalview2XML().loadJalviewAlign(selectedFile);
             } catch (OutOfMemoryError oom)
-               {
-                 new OOMWarning("Whilst loading project from " + choice, oom);
-               } catch (Exception ex)
-               {
-                 Cache.log.error(
-                         "Problems whilst loading project from " + choice, ex);
-                 JvOptionPane.showMessageDialog(Desktop.desktop,
-                         MessageManager.formatMessage(
-                                 "label.error_whilst_loading_project_from",
-                               new Object[]
-                                   { choice }),
-                         MessageManager.getString("label.couldnt_load_project"),
-                         JvOptionPane.WARNING_MESSAGE);
-               }
+            {
+              new OOMWarning("Whilst loading project from " + choice, oom);
+            } catch (Exception ex)
+            {
+              Cache.log.error(
+                      "Problems whilst loading project from " + choice, ex);
+              JvOptionPane.showMessageDialog(Desktop.desktop,
+                      MessageManager.formatMessage(
+                              "label.error_whilst_loading_project_from",
+                              new Object[]
+                              { choice }),
+                      MessageManager
+                              .getString("label.couldnt_load_project"),
+                      JvOptionPane.WARNING_MESSAGE);
+            }
           }
-        }).start();
+        }, "Project Loader").start();
       }
     });
-    
+
     chooser.showOpenDialog(this);
   }
 
@@ -1974,11 +2009,26 @@ 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)
@@ -1994,8 +2044,18 @@ 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);
 
@@ -2003,9 +2063,9 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   /**
    * Gather expanded views (separate AlignFrame's) with the same sequence set
-   * identifier back in to this frame as additional views, and close the expanded
-   * views. Note the expanded frames may themselves have multiple views. We take
-   * the lot.
+   * identifier back in to this frame as additional views, and close the
+   * expanded views. Note the expanded frames may themselves have multiple
+   * views. We take the lot.
    * 
    * @param source
    */
@@ -2015,7 +2075,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)
@@ -2036,11 +2095,32 @@ 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()
@@ -2142,12 +2222,12 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   /**
    * Proxy class for JDesktopPane which optionally displays the current memory
-   * usage and highlights the desktop area with a red bar if free memory runs low.
+   * usage and highlights the desktop area with a red bar if free memory runs
+   * low.
    * 
    * @author AMW
    */
-  public class MyDesktopPane extends JDesktopPane
-          implements Runnable
+  public class MyDesktopPane extends JDesktopPane implements Runnable
   {
     private static final float ONE_MB = 1048576f;
 
@@ -2234,6 +2314,9 @@ public class Desktop extends jalview.jbgui.GDesktop
                   10, getHeight() - fm.getHeight());
         }
       }
+
+      // output debug scale message. Important for jalview.bin.HiDPISettingTest2
+      Desktop.debugScaleMessage(Desktop.getDesktop().getGraphics());
     }
   }
 
@@ -2384,14 +2467,17 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   /**
-   * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this binding
-   * when opened
+   * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this
+   * binding when opened
    */
   protected void addQuitHandler()
   {
-    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
-            .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
-                    jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()),
+    getRootPane()
+            .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+                    KeyStroke
+                            .getKeyStroke(KeyEvent.VK_Q,
+                                    jalview.util.ShortcutKeyMaskExWrapper
+                                            .getMenuShortcutKeyMaskEx()),
                     "Quit");
     getRootPane().getActionMap().put("Quit", new AbstractAction()
     {
@@ -2442,7 +2528,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)
     {
@@ -2520,8 +2606,9 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   /**
-   * This will return the first AlignFrame holding the given viewport instance. It
-   * will break if there are more than one AlignFrames viewing a particular av.
+   * This will return the first AlignFrame holding the given viewport instance.
+   * It will break if there are more than one AlignFrames viewing a particular
+   * av.
    * 
    * @param viewport
    * @return alignFrame for viewport
@@ -2898,8 +2985,8 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   /**
    * Explode the views in the given SplitFrame into separate SplitFrame windows.
-   * This respects (remembers) any previous 'exploded geometry' i.e. the size and
-   * location last time the view was expanded (if any). However it does not
+   * This respects (remembers) any previous 'exploded geometry' i.e. the size
+   * and location last time the view was expanded (if any). However it does not
    * remember the split pane divider location - this is set to match the
    * 'exploding' frame.
    * 
@@ -3070,7 +3157,8 @@ public class Desktop extends jalview.jbgui.GDesktop
           Transferable t) throws Exception
   {
 
-    // BH 2018 changed List<String> to List<Object> to allow for File from SwingJS
+    // BH 2018 changed List<String> to List<Object> to allow for File from
+    // SwingJS
 
     // DataFlavor[] flavors = t.getTransferDataFlavors();
     // for (int i = 0; i < flavors.length; i++) {
@@ -3082,7 +3170,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     // byte[] data = getDroppedFileBytes(file);
     // fileName.setText(file.getName() + " - " + data.length + " " +
     // evt.getLocation());
-    // JTextArea target = (JTextArea) ((DropTarget) evt.getSource()).getComponent();
+    // JTextArea target = (JTextArea) ((DropTarget)
+    // evt.getSource()).getComponent();
     // target.setText(new String(data));
     // }
     // dtde.dropComplete(true);
@@ -3282,10 +3371,10 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   /**
-   * Answers a (possibly empty) list of any structure viewer frames (currently for
-   * either Jmol or Chimera) which are currently open. This may optionally be
-   * restricted to viewers of a specified class, or viewers linked to a specified
-   * alignment panel.
+   * Answers a (possibly empty) list of any structure viewer frames (currently
+   * for either Jmol or Chimera) which are currently open. This may optionally
+   * be restricted to viewers of a specified class, or viewers linked to a
+   * specified alignment panel.
    * 
    * @param apanel
    *          if not null, only return viewers linked to this panel
@@ -3317,4 +3406,37 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     return result;
   }
+
+  public static final String debugScaleMessage = "Desktop graphics transform scale=";
+
+  private static boolean debugScaleMessageDone = false;
+
+  public static void debugScaleMessage(Graphics g)
+  {
+    if (debugScaleMessageDone)
+    {
+      return;
+    }
+    // output used by tests to check HiDPI scaling settings in action
+    try
+    {
+      Graphics2D gg = (Graphics2D) g;
+      if (gg != null)
+      {
+        AffineTransform t = gg.getTransform();
+        double scaleX = t.getScaleX();
+        double scaleY = t.getScaleY();
+        Cache.debug(debugScaleMessage + scaleX + " (X)");
+        Cache.debug(debugScaleMessage + scaleY + " (Y)");
+        debugScaleMessageDone = true;
+      }
+      else
+      {
+        Cache.debug("Desktop graphics null");
+      }
+    } catch (Exception e)
+    {
+      Cache.debug(Cache.getStackTraceString(e));
+    }
+  }
 }