Merge branch 'develop' into trialMerge
[jalview.git] / src / jalview / gui / Desktop.java
index cd8330a..e6d7a15 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import static jalview.util.UrlConstants.SEQUENCE_ID;
-
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
@@ -84,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;
@@ -108,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;
@@ -148,6 +147,10 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   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();
 
   /**
@@ -360,15 +363,51 @@ 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
+    {
+      APQHandlers.setAPQHandlers(this);
+    } catch (Exception e)
+    {
+      System.out.println("Exception when trying to set APQHandlers");
+      e.printStackTrace();
+    } catch (Throwable t)
+    {
+      System.out.println("Throwable when trying to 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);
     desktop = new MyDesktopPane(selmemusage);
 
     showMemusage.setSelected(selmemusage);
     desktop.setBackground(Color.white);
+
     getContentPane().setLayout(new BorderLayout());
     // alternate config - have scrollbars - see notes in JAL-153
     // JScrollPane sp = new JScrollPane();
@@ -425,7 +464,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);
 
@@ -449,8 +495,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
@@ -589,7 +634,7 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
     }).start();
-    ;
+    
   }
 
   @Override
@@ -940,7 +985,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           menuItem.removeActionListener(menuItem.getActionListeners()[0]);
         }
         windowMenu.remove(menuItem);
-      };
+      }
     });
 
     menuItem.addActionListener(new ActionListener()
@@ -1004,7 +1049,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);
@@ -1308,6 +1353,8 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   public void quit()
   {
+    //System.out.println("********** Desktop.quit()");
+    //System.out.println(savingFiles.toString());
     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
     jalview.bin.Cache.setProperty("SCREENGEOMETRY_WIDTH",
             screen.width + "");
@@ -2342,7 +2389,7 @@ public class Desktop extends jalview.jbgui.GDesktop
                 });
                 rthr.start();
               }
-            };
+            }
           });
           VamsasStMenu.add(sessit);
         }
@@ -2487,7 +2534,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           while (li.hasNext())
           {
             String link = li.next();
-            if (link.contains(SEQUENCE_ID)
+            if (link.contains(jalview.util.UrlConstants.SEQUENCE_ID)
                     && !UrlConstants.isDefaultString(link))
             {
               check = true;
@@ -2794,7 +2841,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()
     {
@@ -2853,18 +2900,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));
     }
   }
 
@@ -2879,13 +2926,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(
@@ -3239,7 +3286,6 @@ public class Desktop extends jalview.jbgui.GDesktop
           } catch (InterruptedException x)
           {
           }
-          ;
         }
         if (instance == null)
         {
@@ -3527,7 +3573,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)
       {