JAL-1159 Merging 2.8.1 patches and Anne Menards work from 2012 into development branch
[jalview.git] / src / jalview / gui / Desktop.java
index 996aad1..345c529 100644 (file)
@@ -1,13 +1,13 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
@@ -23,6 +23,7 @@ import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
+import jalview.util.MessageManager;
 import jalview.ws.params.ParamManager;
 
 import java.awt.BorderLayout;
@@ -59,7 +60,6 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -83,7 +83,6 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JProgressBar;
-import javax.swing.JTextArea;
 import javax.swing.SwingUtilities;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.MenuEvent;
@@ -649,8 +648,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
     // IF JALVIEW IS RUNNING HEADLESS
     // ///////////////////////////////////////////////
-    if (System.getProperty("java.awt.headless") != null
-            && System.getProperty("java.awt.headless").equals("true"))
+    if (instance == null || (System.getProperty("java.awt.headless") != null
+            && System.getProperty("java.awt.headless").equals("true")))
     {
       return;
     }
@@ -914,7 +913,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
               .getSelectedFile().getParent());
 
       String format = null;
-      if (chooser.getSelectedFormat().equals("Jalview"))
+      if (chooser.getSelectedFormat()!=null && chooser.getSelectedFormat().equals("Jalview"))
       {
         format = "Jalview";
       }
@@ -945,7 +944,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     // This construct allows us to have a wider textfield
     // for viewing
-    JLabel label = new JLabel("Enter URL of Input File");
+    JLabel label = new JLabel(MessageManager.getString("label.input_file_url"));
     final JComboBox history = new JComboBox();
 
     JPanel panel = new JPanel(new GridLayout(2, 1));
@@ -970,7 +969,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
 
     int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
-            "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
+            MessageManager.getString("label.input_alignment_from_url"), JOptionPane.OK_CANCEL_OPTION);
 
     if (reply != JOptionPane.OK_OPTION)
     {
@@ -1511,6 +1510,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     if (progressPanel != null)
     {
+      synchronized(progressPanel) {
       progressPanel.remove(progbar);
       GridLayout gl = (GridLayout) progressPanel.getLayout();
       gl.setRows(gl.getRows() - 1);
@@ -1519,6 +1519,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         this.getContentPane().remove(progressPanel);
         progressPanel = null;
       }
+      }
     }
     validate();
   }
@@ -1528,9 +1529,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     fileLoadingCount--;
     if (fileLoadingCount < 1)
     {
-      for (JPanel flp : fileLoadingPanels)
+      while (fileLoadingPanels.size()>0)
       {
-        removeProgressPanel(flp);
+        removeProgressPanel(fileLoadingPanels.remove(0));
       }
       fileLoadingPanels.clear();
       fileLoadingCount = 0;
@@ -1723,8 +1724,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         if (!vamsasImport(chooser.getSelectedFile()))
         {
           JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                  "Couldn't import '" + fle + "' as a new vamsas session.",
-                  "Vamsas Document Import Failed",
+                  MessageManager.formatMessage("label.couldnt_import_as_vamsas_session", new String[]{fle}),
+                  MessageManager.getString("label.vamsas_document_import_failed"),
                   JOptionPane.ERROR_MESSAGE);
         }
       }
@@ -1867,7 +1868,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
   protected void setupVamsasConnectedGui()
   {
-    vamsasStart.setText("Session Update");
+    vamsasStart.setText(MessageManager.getString("label.session_update"));
     vamsasSave.setVisible(true);
     vamsasStop.setVisible(true);
     vamsasImport.setVisible(false); // Document import to existing session is
@@ -1879,7 +1880,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     vamsasSave.setVisible(false);
     vamsasStop.setVisible(false);
     vamsasImport.setVisible(true);
-    vamsasStart.setText("New Vamsas Session");
+    vamsasStart.setText(MessageManager.getString("label.new_vamsas_session"));
   }
 
   public void vamsasStop_actionPerformed(ActionEvent e)
@@ -2138,9 +2139,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         if (fm != null)
         {
           g.drawString(
-                  "Total Free Memory: " + df.format(totalFreeMemory)
-                          + "MB; Max Memory: " + df.format(maxMemory)
-                          + "MB; " + df.format(percentUsage) + "%", 10,
+                         MessageManager.formatMessage("label.memory_stats", new String[]{df.format(totalFreeMemory),df.format(maxMemory),df.format(percentUsage)}), 10,
                   getHeight() - fm.getHeight());
         }
       }
@@ -2163,7 +2162,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     if (jalview.bin.Cache.groovyJarsPresent())
     {
       groovyShell = new JMenuItem();
-      groovyShell.setText("Groovy Console...");
+      groovyShell.setText(MessageManager.getString("label.groovy_console"));
       groovyShell.addActionListener(new ActionListener()
       {
         public void actionPerformed(ActionEvent e)
@@ -2343,7 +2342,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
     if (handler.canCancel())
     {
-      JButton cancel = new JButton("Cancel");
+      JButton cancel = new JButton(MessageManager.getString("action.cancel"));
       final IProgressIndicator us = this;
       cancel.addActionListener(new ActionListener()
       {
@@ -2438,7 +2437,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     boolean alive = true;
     Thread t0 = null, t1 = null, t2 = null;
-
+    // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
+    if (true)
+    {
     // todo: changesupport handlers need to be transferred
     if (discoverer == null)
     {
@@ -2448,28 +2449,31 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
     // JAL-940 - disabled JWS1 service configuration - always start discoverer
     // until we phase out completely
-    if (true)
-    {
       (t0 = new Thread(discoverer)).start();
     }
 
-    try
+    // ENFIN services are EOLed as of Jalview 2.8.1 release
+    if (false)
     {
-      if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
+      try
       {
-        // EnfinEnvision web service menu entries are rebuild every time the
-        // menu is shown, so no changeSupport events are needed.
-        jalview.ws.EnfinEnvision2OneWay.getInstance();
-        (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
-                .start();
+        if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
+        {
+          // EnfinEnvision web service menu entries are rebuild every time the
+          // menu is shown, so no changeSupport events are needed.
+          jalview.ws.EnfinEnvision2OneWay.getInstance();
+          (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
+                  .start();
+        }
+      } catch (Exception e)
+      {
+        Cache.log
+                .info("Exception when trying to launch Envision2 workflow discovery.",
+                        e);
+        Cache.log.info(e.getStackTrace());
       }
-    } catch (Exception e)
-    {
-      Cache.log
-              .info("Exception when trying to launch Envision2 workflow discovery.",
-                      e);
-      Cache.log.info(e.getStackTrace());
     }
+
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
       if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
@@ -2526,43 +2530,43 @@ public class Desktop extends jalview.jbgui.GDesktop implements
               {
 
                 /*
-                JalviewDialog jd =new JalviewDialog() {
-                  @Override
-                  protected void cancelPressed()
-                  {
-                    // TODO Auto-generated method stub
-                    
-                  }@Override
-                  protected void okPressed()
-                  {
-                    // TODO Auto-generated method stub
-                    
-                  }@Override
-                  protected void raiseClosed()
-                  {
-                    // TODO Auto-generated method stub
-                    
-                  }
-                };
-                jd.initDialogFrame(new JLabel("<html><table width=\"450\"><tr><td>"
-                                        + ermsg
-                                        + "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
-                                        + " or mis-configured HTTP proxy settings.<br/>"
-                                        + "Check the <em>Connections</em> and <em>Web services</em> tab of the"
-                                        + " Tools->Preferences dialog box to change them.</td></tr></table></html>"), true, true, "Web Service Configuration Problem", 450, 400);
-                
-                jd.waitForInput();
-                */
-                JOptionPane.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,"
-                                + " or mis-configured HTTP proxy settings.</p>"
-                                + "<p>Check the <em>Connections</em> and <em>Web services</em> tab<br/>of the"
-                                + " Tools->Preferences dialog box to change them.</p></html>"), "Web Service Configuration Problem",
+                 * JalviewDialog jd =new JalviewDialog() {
+                 * 
+                 * @Override protected void cancelPressed() { // TODO
+                 * Auto-generated method stub
+                 * 
+                 * }@Override protected void okPressed() { // TODO
+                 * Auto-generated method stub
+                 * 
+                 * }@Override protected void raiseClosed() { // TODO
+                 * Auto-generated method stub
+                 * 
+                 * } }; jd.initDialogFrame(new
+                 * JLabel("<html><table width=\"450\"><tr><td>" + ermsg +
+                 * "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
+                 * + " or mis-configured HTTP proxy settings.<br/>" +
+                 * "Check the <em>Connections</em> and <em>Web services</em> tab of the"
+                 * +
+                 * " Tools->Preferences dialog box to change them.</td></tr></table></html>"
+                 * ), true, true, "Web Service Configuration Problem", 450,
+                 * 400);
+                 * 
+                 * jd.waitForInput();
+                 */
+                JOptionPane
+                        .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,"
+                                                + " or mis-configured HTTP proxy settings.</p>"
+                                                + "<p>Check the <em>Connections</em> and <em>Web services</em> tab<br/>of the"
+                                                + " Tools->Preferences dialog box to change them.</p></html>"),
+                                "Web Service Configuration Problem",
                                 JOptionPane.DEFAULT_OPTION,
-                        JOptionPane.ERROR_MESSAGE);
+                                JOptionPane.ERROR_MESSAGE);
                 serviceChangedDialog = null;
 
               }