JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / gui / Desktop.java
index d2967d7..9dd46d6 100644 (file)
@@ -82,9 +82,11 @@ import java.beans.PropertyChangeListener;
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.ListIterator;
@@ -106,7 +108,6 @@ import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.JDesktopPane;
-import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuItem;
@@ -132,27 +133,30 @@ import org.stackoverflowusers.file.WindowsShortcut;
  * @author $author$
  * @version $Revision: 1.155 $
  */
-@SuppressWarnings("serial")
 public class Desktop extends jalview.jbgui.GDesktop
         implements DropTargetListener, ClipboardOwner, IProgressIndicator,
         jalview.api.StructureSelectionManagerProvider
 {
-  private final static int DEFAULT_MIN_WIDTH = 300;
+  private static int DEFAULT_MIN_WIDTH = 300;
 
-  private final static int DEFAULT_MIN_HEIGHT = 250;
+  private static int DEFAULT_MIN_HEIGHT = 250;
 
-  private final static int ALIGN_FRAME_DEFAULT_MIN_WIDTH = 600;
+  private static int ALIGN_FRAME_DEFAULT_MIN_WIDTH = 600;
 
-  private final static int ALIGN_FRAME_DEFAULT_MIN_HEIGHT = 70;
+  private static int ALIGN_FRAME_DEFAULT_MIN_HEIGHT = 70;
 
-  private final static String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES";
+  private static final String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES";
+
+  protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT";
+
+  public static HashMap<String, FileWriter> savingFiles = new HashMap<>();
 
   private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
 
   /**
    * news reader - null if it was never started.
    */
-  BlogReader jvnews = null;
+  private BlogReader jvnews = null;
 
   private File projectFile;
 
@@ -191,47 +195,16 @@ public class Desktop extends jalview.jbgui.GDesktop
             listener);
   }
 
-  /**
-   * Singleton Desktop instance only in Java;
-   */
-  private static Desktop instance;
+  /** Singleton Desktop instance */
+  public static Desktop instance;
 
-  public static Desktop getInstance()
-  {
-    Desktop d;
-    @SuppressWarnings("unused")
-    ThreadGroup g = Thread.currentThread().getThreadGroup();
-    /**
-     * @j2sNative d = g._jalviewDesktopInstance;
-     */
-    {
-      d = instance;
-    }
-    return d;
-  }
+  public static MyDesktopPane desktop;
 
-  private static void setInstance(Desktop d)
+  public static MyDesktopPane getDesktop()
   {
-    @SuppressWarnings("unused")
-    ThreadGroup g = Thread.currentThread().getThreadGroup();
-    /**
-     * @j2s g._jalviewDesktopInstance = d;
-     */
-    {
-      instance = d;
-    }
-  }
-
-  private MyDesktopPane desktopPane;
-
-  public static MyDesktopPane getDesktopPane()
-  {
-    return getInstance().desktopPane;
-  }
-
-  private void setDesktopPane(MyDesktopPane pane)
-  {
-    getInstance().desktopPane = pane;
+    // BH 2018 could use currentThread() here as a reference to a
+    // Hashtable<Thread, MyDesktopPane> in JavaScript
+    return desktop;
   }
 
   static int openFrameCount = 0;
@@ -267,7 +240,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       } catch (NullPointerException npe)
       {
         Point p = getMousePosition();
-        getInstance().showPasteMenu(p.x, p.y);
+        instance.showPasteMenu(p.x, p.y);
       }
     }
 
@@ -315,14 +288,14 @@ public class Desktop extends jalview.jbgui.GDesktop
     public void endDraggingFrame(JComponent f)
     {
       delegate.endDraggingFrame(f);
-      getDesktopPane().repaint();
+      desktop.repaint();
     }
 
     @Override
     public void endResizingFrame(JComponent f)
     {
       delegate.endResizingFrame(f);
-      getDesktopPane().repaint();
+      desktop.repaint();
     }
 
     @Override
@@ -382,7 +355,7 @@ public class Desktop extends jalview.jbgui.GDesktop
      * block are spawned off as threads rather than waited for during this
      * constructor.
      */
-    setInstance(this);
+    instance = this;
     if (!Platform.isJS())
     {
       doVamsasClientCheck();
@@ -390,15 +363,57 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     doConfigureStructurePrefs();
     setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
-    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    /*
+    if (!Platform.isAMac())
+    {
+      // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+    }
+    else
+    {
+     this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+    }
+    */
+
+    try
+    {
+           if (!Platform.isJS())
+                   /*
+                    * @j2sIgnore
+                    */
+           {
+             APQHandlers.setAPQHandlers(this);
+           }
+    } catch (Exception e)
+    {
+      System.out.println("Cannot set APQHandlers");
+      // e.printStackTrace();
+    } catch (Throwable t)
+    {
+      System.out.println("Cannot set APQHandlers");
+      // t.printStackTrace();
+    }
+
+
+    addWindowListener(new WindowAdapter()
+    {
+
+      @Override
+      public void windowClosing(WindowEvent ev)
+      {
+        quit();
+      }
+    });
+
     boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
             false);
+
     boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE",
             false);
-    setDesktopPane(new MyDesktopPane(selmemusage));
+    desktop = new MyDesktopPane(selmemusage);
 
     showMemusage.setSelected(selmemusage);
-    getDesktopPane().setBackground(Color.white);
+    desktop.setBackground(Color.white);
+
     getContentPane().setLayout(new BorderLayout());
     // alternate config - have scrollbars - see notes in JAL-153
     // JScrollPane sp = new JScrollPane();
@@ -411,17 +426,17 @@ public class Desktop extends jalview.jbgui.GDesktop
       getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
     }
 
-    getContentPane().add(getDesktopPane(), BorderLayout.CENTER);
-    getDesktopPane().setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
+    getContentPane().add(desktop, BorderLayout.CENTER);
+    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
 
     // This line prevents Windows Look&Feel resizing all new windows to maximum
     // if previous window was maximised
-    getDesktopPane().setDesktopManager(new MyDesktopManager(
+    desktop.setDesktopManager(new MyDesktopManager(
             (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
                     : Platform.isAMacAndNotJS()
                             ? new AquaInternalFrameManager(
-                                    getDesktopPane().getDesktopManager())
-                            : getDesktopPane().getDesktopManager())));
+                                    desktop.getDesktopManager())
+                            : desktop.getDesktopManager())));
 
     Rectangle dims = getLastKnownDimensions("");
     if (dims != null)
@@ -455,7 +470,14 @@ public class Desktop extends jalview.jbgui.GDesktop
               + "Java version: " + System.getProperty("java.version") + "\n"
               + System.getProperty("os.arch") + " "
               + System.getProperty("os.name") + " "
-              + System.getProperty("os.version"));
+              + System.getProperty("os.version")
+              + (jalview.bin.Cache.getProperty("VERSION").equals("DEVELOPMENT")
+                              ? "\nJava path:"
+                                      + System.getProperty(
+                                              "java.home")
+                                      + File.separator + "bin"
+                                      + File.separator + "java"
+                              : ""));
 
       showConsole(showjconsole);
 
@@ -479,8 +501,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       });
 
       // Thread off a new instance of the file chooser - this reduces the time
-      // it
-      // takes to open it later on.
+      // it takes to open it later on.
       new Thread(new Runnable()
       {
         @Override
@@ -510,7 +531,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     }
 
-    this.setDropTarget(new java.awt.dnd.DropTarget(getDesktopPane(), this));
+    this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
 
     this.addWindowListener(new WindowAdapter()
     {
@@ -542,7 +563,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
     });
-    getDesktopPane().addMouseListener(ma);
+    desktop.addMouseListener(ma);
 
   }
 
@@ -607,10 +628,10 @@ public class Desktop extends jalview.jbgui.GDesktop
       public void run()
       {
         Cache.log.debug("Downloading data from identifiers.org");
-        // UrlDownloadClient client = new UrlDownloadClient();
+        UrlDownloadClient client = new UrlDownloadClient();
         try
         {
-          UrlDownloadClient.download(IdOrgSettings.getUrl(),
+          client.download(IdOrgSettings.getUrl(),
                   IdOrgSettings.getDownloadLocation());
         } catch (IOException e)
         {
@@ -619,7 +640,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
     }).start();
-    ;
+    
   }
 
   @Override
@@ -628,7 +649,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     showNews(showNews.isSelected());
   }
 
-  protected void showNews(boolean visible)
+  void showNews(boolean visible)
   {
     Cache.log.debug((visible ? "Showing" : "Hiding") + " news.");
     showNews.setSelected(visible);
@@ -640,10 +661,10 @@ public class Desktop extends jalview.jbgui.GDesktop
         public void run()
         {
           long now = System.currentTimeMillis();
-          Desktop.getInstance().setProgressBar(
+          Desktop.instance.setProgressBar(
                   MessageManager.getString("status.refreshing_news"), now);
           jvnews.refreshNews();
-          Desktop.getInstance().setProgressBar(null, now);
+          Desktop.instance.setProgressBar(null, now);
           jvnews.showNews();
         }
       }).start();
@@ -748,7 +769,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
   }
 
-  protected void showPasteMenu(int x, int y)
+  void showPasteMenu(int x, int y)
   {
     JPopupMenu popup = new JPopupMenu();
     JMenuItem item = new JMenuItem(
@@ -890,7 +911,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
     // IF JALVIEW IS RUNNING HEADLESS
     // ///////////////////////////////////////////////
-    if (instance == null || Jalview.isHeadlessMode())
+    if (instance == null || (System.getProperty("java.awt.headless") != null
+            && System.getProperty("java.awt.headless").equals("true")))
     {
       return;
     }
@@ -930,13 +952,13 @@ public class Desktop extends jalview.jbgui.GDesktop
      * add an entry for the new frame in the Window menu 
      * (and remove it when the frame is closed)
      */
-    JMenuItem menuItem = new JMenuItem(title);
+    final JMenuItem menuItem = new JMenuItem(title);
     frame.addInternalFrameListener(new InternalFrameAdapter()
     {
       @Override
       public void internalFrameActivated(InternalFrameEvent evt)
       {
-        JInternalFrame itf = getDesktopPane().getSelectedFrame();
+        JInternalFrame itf = desktop.getSelectedFrame();
         if (itf != null)
         {
           if (itf instanceof AlignFrame)
@@ -968,8 +990,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         {
           menuItem.removeActionListener(menuItem.getActionListeners()[0]);
         }
-        getInstance().windowMenu.remove(menuItem);
-      };
+        windowMenu.remove(menuItem);
+      }
     });
 
     menuItem.addActionListener(new ActionListener()
@@ -990,9 +1012,9 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     setKeyBindings(frame);
 
-    getDesktopPane().add(frame);
+    desktop.add(frame);
 
-    getInstance().windowMenu.add(menuItem);
+    windowMenu.add(menuItem);
 
     frame.toFront();
     try
@@ -1017,6 +1039,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   private static void setKeyBindings(JInternalFrame frame)
   {
+    @SuppressWarnings("serial")
     final Action closeAction = new AbstractAction()
     {
       @Override
@@ -1032,7 +1055,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
             InputEvent.CTRL_DOWN_MASK);
     KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx());
 
     InputMap inputMap = frame
             .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
@@ -1151,7 +1174,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser
-            .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, true);
+            .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, BackupFiles.getEnabled());
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
@@ -1284,8 +1307,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           {
             String msg = MessageManager
                     .formatMessage("label.couldnt_locate", url);
-            JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
-                    msg,
+            JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
                     MessageManager.getString("label.url_not_found"),
                     JvOptionPane.WARNING_MESSAGE);
 
@@ -1306,8 +1328,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     };
     String dialogOption = MessageManager
             .getString("label.input_alignment_from_url");
-    JvOptionPane.newOptionDialog(getDesktopPane())
-            .setResponseHandler(0, action)
+    JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
             .showInternalDialog(panel, dialogOption,
                     JvOptionPane.YES_NO_CANCEL_OPTION,
                     JvOptionPane.PLAIN_MESSAGE, null, options,
@@ -1393,7 +1414,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   public void aboutMenuItem_actionPerformed(ActionEvent e)
   {
     // StringBuffer message = getAboutMessage(false);
-    // JvOptionPane.showInternalMessageDialog(Desktop.getDesktop(),
+    // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
     //
     // message.toString(), "About Jalview", JvOptionPane.INFORMATION_MESSAGE);
     new Thread(new Runnable()
@@ -1503,7 +1524,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   public void closeAll_actionPerformed(ActionEvent e)
   {
     // TODO show a progress bar while closing?
-    JInternalFrame[] frames = getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = desktop.getAllFrames();
     for (int i = 0; i < frames.length; i++)
     {
       try
@@ -1574,7 +1595,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   protected void showMemusage_actionPerformed(ActionEvent e)
   {
-    getDesktopPane().showMemoryUsage(showMemusage.isSelected());
+    desktop.showMemoryUsage(showMemusage.isSelected());
   }
 
   /*
@@ -1611,7 +1632,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   void reorderAssociatedWindows(boolean minimize, boolean close)
   {
-    JInternalFrame[] frames = getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = desktop.getAllFrames();
     if (frames == null || frames.length < 1)
     {
       return;
@@ -1795,7 +1816,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     saveState_actionPerformed(true);
   }
 
-  protected void setProjectFile(File choice)
+  private void setProjectFile(File choice)
   {
     this.projectFile = choice;
   }
@@ -1817,7 +1838,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         "Jalview Project (old)" };
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
-            "Jalview Project", true, true); // last two booleans: allFiles,
+            "Jalview Project", true, BackupFiles.getEnabled()); // last two booleans: allFiles,
                                             // allowBackupFiles
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
@@ -1845,7 +1866,7 @@ public class Desktop extends jalview.jbgui.GDesktop
                {
                  Cache.log.error(
                          "Problems whilst loading project from " + choice, ex);
-              JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
+                 JvOptionPane.showMessageDialog(Desktop.desktop,
                          MessageManager.formatMessage(
                                  "label.error_whilst_loading_project_from",
                                new Object[]
@@ -1955,7 +1976,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
   {
-    if (Desktop.getDesktopPane() == null)
+    if (Desktop.desktop == null)
     {
       // no frames created and in headless mode
       // TODO: verify that frames are recoverable when in headless mode
@@ -1997,7 +2018,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   public static AlignmentViewport[] getViewports(String sequenceSetId)
   {
     List<AlignmentViewport> viewp = new ArrayList<>();
-    if (getDesktopPane() != null)
+    if (desktop != null)
     {
       AlignFrame[] frames = Desktop.getAlignFrames();
 
@@ -2083,7 +2104,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     source.viewport.setGatherViewsHere(true);
     source.viewport.setExplodedGeometry(source.getBounds());
-    JInternalFrame[] frames = getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = desktop.getAllFrames();
     String viewId = source.viewport.getSequenceSetId();
 
     for (int t = 0; t < frames.length; t++)
@@ -2140,7 +2161,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         String fle = chooser.getSelectedFile().toString();
         if (!vamsasImport(chooser.getSelectedFile()))
         {
-          JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+          JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                   MessageManager.formatMessage(
                           "label.couldnt_import_as_vamsas_session",
                           new Object[]
@@ -2372,7 +2393,7 @@ public class Desktop extends jalview.jbgui.GDesktop
                 });
                 rthr.start();
               }
-            };
+            }
           });
           VamsasStMenu.add(sessit);
         }
@@ -2441,7 +2462,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         removeProgressPanel(progpanel);
         if (warnmsg != null)
         {
-          JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+          JvOptionPane.showInternalMessageDialog(Desktop.desktop,
 
                   warnmsg, warnttl, JvOptionPane.ERROR_MESSAGE);
         }
@@ -2478,7 +2499,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   public JInternalFrame[] getAllFrames()
   {
-    return getDesktopPane().getAllFrames();
+    return desktop.getAllFrames();
   }
 
   /**
@@ -2517,7 +2538,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           while (li.hasNext())
           {
             String link = li.next();
-            if (link.contains(UrlConstants.SEQUENCE_ID)
+            if (link.contains(jalview.util.UrlConstants.SEQUENCE_ID)
                     && !UrlConstants.isDefaultString(link))
             {
               check = true;
@@ -2564,7 +2585,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           });
           msgPanel.add(jcb);
 
-          JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msgPanel,
+          JvOptionPane.showMessageDialog(Desktop.desktop, msgPanel,
                   MessageManager
                           .getString("label.SEQUENCE_ID_no_longer_used"),
                   JvOptionPane.WARNING_MESSAGE);
@@ -2679,11 +2700,11 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     if (Jalview.isHeadlessMode())
     {
-      // Desktop.getDesktop() is null in headless mode
-      return new AlignFrame[] { Jalview.getCurrentAlignFrame() };
+      // Desktop.desktop is null in headless mode
+      return new AlignFrame[] { Jalview.currentAlignFrame };
     }
 
-    JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
 
     if (frames == null)
     {
@@ -2728,7 +2749,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   public GStructureViewer[] getJmols()
   {
-    JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
 
     if (frames == null)
     {
@@ -2764,7 +2785,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     } catch (Exception ex)
     {
       jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
-      JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
 
               MessageManager.getString("label.couldnt_create_groovy_shell"),
               MessageManager.getString("label.groovy_support_failed"),
@@ -2775,7 +2796,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   /**
    * Open the Groovy console
    */
-  private void openGroovyConsole()
+  void openGroovyConsole()
   {
     if (groovyConsole == null)
     {
@@ -2824,7 +2845,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
             .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
-                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
+                    jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()),
                     "Quit");
     getRootPane().getActionMap().put("Quit", new AbstractAction()
     {
@@ -2883,18 +2904,18 @@ public class Desktop extends jalview.jbgui.GDesktop
       progressBarHandlers = new Hashtable<>();
     }
 
-    if (progressBars.get(new Long(id)) != null)
+    if (progressBars.get(Long.valueOf(id)) != null)
     {
-      JPanel panel = progressBars.remove(new Long(id));
-      if (progressBarHandlers.contains(new Long(id)))
+      JPanel panel = progressBars.remove(Long.valueOf(id));
+      if (progressBarHandlers.contains(Long.valueOf(id)))
       {
-        progressBarHandlers.remove(new Long(id));
+        progressBarHandlers.remove(Long.valueOf(id));
       }
       removeProgressPanel(panel);
     }
     else
     {
-      progressBars.put(new Long(id), addProgressPanel(message));
+      progressBars.put(Long.valueOf(id), addProgressPanel(message));
     }
   }
 
@@ -2909,13 +2930,13 @@ public class Desktop extends jalview.jbgui.GDesktop
           final IProgressIndicatorHandler handler)
   {
     if (progressBarHandlers == null
-            || !progressBars.containsKey(new Long(id)))
+            || !progressBars.containsKey(Long.valueOf(id)))
     {
       throw new Error(MessageManager.getString(
               "error.call_setprogressbar_before_registering_handler"));
     }
-    progressBarHandlers.put(new Long(id), handler);
-    final JPanel progressPanel = progressBars.get(new Long(id));
+    progressBarHandlers.put(Long.valueOf(id), handler);
+    final JPanel progressPanel = progressBars.get(Long.valueOf(id));
     if (handler.canCancel())
     {
       JButton cancel = new JButton(
@@ -2961,7 +2982,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
   {
-    if (getDesktopPane() != null)
+    if (desktop != null)
     {
       AlignmentPanel[] aps = getAlignmentPanels(
               viewport.getSequenceSetId());
@@ -3023,7 +3044,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       if (discoverer == null)
       {
         discoverer = new jalview.ws.jws1.Discoverer();
-        // register PCS handler for getDesktop().
+        // register PCS handler for desktop.
         discoverer.addPropertyChangeListener(changeSupport);
       }
       // JAL-940 - disabled JWS1 service configuration - always start discoverer
@@ -3105,7 +3126,7 @@ public class Desktop extends jalview.jbgui.GDesktop
                  * 
                  * jd.waitForInput();
                  */
-                JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
+                JvOptionPane.showConfirmDialog(Desktop.desktop,
                         new JLabel("<html><table width=\"450\"><tr><td>"
                                 + ermsg + "</td></tr></table>"
                                 + "<p>It may be that you have invalid JABA URLs<br/>in your web service preferences,"
@@ -3131,7 +3152,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
   }
 
-  Runnable serviceChangedDialog = null;
+  private Runnable serviceChangedDialog = null;
 
   /**
    * start a thread to open a URL in the configured browser. Pops up a warning
@@ -3142,7 +3163,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    */
   public static void showUrl(final String url)
   {
-    showUrl(url, Desktop.getInstance());
+    showUrl(url, Desktop.instance);
   }
 
   /**
@@ -3171,7 +3192,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           jalview.util.BrowserLauncher.openURL(url);
         } catch (Exception ex)
         {
-          JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+          JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                   MessageManager
                           .getString("label.web_browser_not_found_unix"),
                   MessageManager.getString("label.web_browser_not_found"),
@@ -3187,16 +3208,15 @@ public class Desktop extends jalview.jbgui.GDesktop
     }).start();
   }
 
-  private WsParamSetManager wsparamManager = null;
+  public static WsParamSetManager wsparamManager = null;
 
   public static ParamManager getUserParameterStore()
   {
-    Desktop d = getInstance();
-    if (d.wsparamManager == null)
+    if (wsparamManager == null)
     {
-      d.wsparamManager = new WsParamSetManager();
+      wsparamManager = new WsParamSetManager();
     }
-    return d.wsparamManager;
+    return wsparamManager;
   }
 
   /**
@@ -3241,12 +3261,12 @@ public class Desktop extends jalview.jbgui.GDesktop
   /**
    * flag indicating if dialogExecutor should try to acquire a permit
    */
-  volatile boolean dialogPause = true;
+  private volatile boolean dialogPause = true;
 
   /**
    * pause the queue
    */
-  java.util.concurrent.Semaphore block = new Semaphore(0);
+  private java.util.concurrent.Semaphore block = new Semaphore(0);
 
   private static groovy.ui.Console groovyConsole;
 
@@ -3270,9 +3290,8 @@ public class Desktop extends jalview.jbgui.GDesktop
           } catch (InterruptedException x)
           {
           }
-          ;
         }
-        if (getInstance() == null)
+        if (instance == null)
         {
           return;
         }
@@ -3436,7 +3455,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     String topViewId = myTopFrame.viewport.getSequenceSetId();
     String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
 
-    JInternalFrame[] frames = getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = desktop.getAllFrames();
     for (JInternalFrame frame : frames)
     {
       if (frame instanceof SplitFrame && frame != source)
@@ -3499,7 +3518,6 @@ public class Desktop extends jalview.jbgui.GDesktop
    *          - the payload from the drop event
    * @throws Exception
    */
-  @SuppressWarnings("unchecked")
   public static void transferFromDropTarget(List<Object> files,
           List<DataSourceType> protocols, DropTargetDropEvent evt,
           Transferable t) throws Exception
@@ -3559,7 +3577,6 @@ public class Desktop extends jalview.jbgui.GDesktop
             System.err.println(
                     "Please ignore plist error - occurs due to problem with java 8 on OSX");
           }
-          ;
         }
       } catch (Throwable ex)
       {
@@ -3570,7 +3587,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     {
       // Works on Windows and MacOSX
       Cache.log.debug("Drop handled as javaFileListFlavor");
-      for (Object file : (List<Object>) t
+      for (Object file : (List) t
               .getTransferData(DataFlavor.javaFileListFlavor))
       {
         files.add(file);
@@ -3734,7 +3751,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           Class<? extends StructureViewerBase> structureViewerClass)
   {
     List<StructureViewerBase> result = new ArrayList<>();
-    JInternalFrame[] frames = Desktop.getInstance().getAllFrames();
+    JInternalFrame[] frames = Desktop.instance.getAllFrames();
 
     for (JInternalFrame frame : frames)
     {
@@ -3753,5 +3770,4 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     return result;
   }
-
 }