Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / gui / WsPreferences.java
index 32671d5..cf88718 100644 (file)
  */
 package jalview.gui;
 
-import jalview.bin.Cache;
-import jalview.jbgui.GWsPreferences;
-import jalview.util.MessageManager;
-import jalview.ws.jws2.Jws2Discoverer;
-import jalview.ws.rest.RestServiceDescription;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -33,17 +28,24 @@ import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.table.AbstractTableModel;
 import javax.swing.table.TableCellRenderer;
 
+import jalview.bin.Cache;
+import jalview.jbgui.GWsPreferences;
+import jalview.util.MessageManager;
+import jalview.ws.WSDiscovererI;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.rest.RestServiceDescription;
+
 public class WsPreferences extends GWsPreferences
 {
 
@@ -65,7 +67,7 @@ public class WsPreferences extends GWsPreferences
   private void initFromPreferences()
   {
 
-    wsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls();
+    wsUrls = Jws2Discoverer.getInstance().getServiceUrls();
     if (!wsUrls.isEmpty())
     {
       oldUrls = new Vector<String>(wsUrls);
@@ -89,20 +91,20 @@ public class WsPreferences extends GWsPreferences
       rsbsUrls = new Vector<String>();
     }
     updateRsbsList();
-    enableEnfinServices.setSelected(oldEnfin = Cache.getDefault(
-            "SHOW_ENFIN_SERVICES", true));
+    enableEnfinServices.setSelected(
+            oldEnfin = Cache.getDefault("SHOW_ENFIN_SERVICES", true));
     enableEnfinServices.addActionListener(updateAction);
-    enableJws2Services.setSelected(oldJws2 = Cache.getDefault(
-            "SHOW_JWS2_SERVICES", true));
+    enableJws2Services.setSelected(
+            oldJws2 = Cache.getDefault("SHOW_JWS2_SERVICES", true));
     enableJws2Services.addActionListener(updateAction);
-    indexByHost.setSelected(oldIndexByHost = Cache.getDefault(
-            "WSMENU_BYHOST", false));
+    indexByHost.setSelected(
+            oldIndexByHost = Cache.getDefault("WSMENU_BYHOST", false));
     indexByHost.addActionListener(updateAction);
-    indexByType.setSelected(oldIndexByType = Cache.getDefault(
-            "WSMENU_BYTYPE", false));
+    indexByType.setSelected(
+            oldIndexByType = Cache.getDefault("WSMENU_BYTYPE", false));
     indexByType.addActionListener(updateAction);
-    displayWsWarning.setSelected(oldWsWarning = Cache.getDefault(
-            "SHOW_WSDISCOVERY_ERRORS", true));
+    displayWsWarning.setSelected(oldWsWarning = Cache
+            .getDefault("SHOW_WSDISCOVERY_ERRORS", true));
   }
 
   ActionListener updateAction = new ActionListener()
@@ -122,18 +124,18 @@ public class WsPreferences extends GWsPreferences
     int r = 0;
     for (String url : wsUrls)
     {
-      int status = Jws2Discoverer.getDiscoverer().getServerStatusFor(url);
-      tdat[r][1] = new Integer(status);
+      int status = Jws2Discoverer.getInstance().getServerStatusFor(url);
+      tdat[r][1] = Integer.valueOf(status);
       tdat[r++][0] = url;
     }
 
     wsList.setModel(new WsUrlTableModel(tdat));
-    wsList.getColumn(MessageManager.getString("label.status")).setMinWidth(
-            10);
+    wsList.getColumn(MessageManager.getString("label.status"))
+            .setMinWidth(10);
   }
 
-  private class JabaWSStatusRenderer extends JPanel implements
-          TableCellRenderer
+  private class JabaWSStatusRenderer extends JPanel
+          implements TableCellRenderer
   {
     public JabaWSStatusRenderer()
     {
@@ -156,21 +158,22 @@ public class WsPreferences extends GWsPreferences
       String t = new String("");
       switch (((Integer) status).intValue())
       {
-      case 1:
+      case WSDiscovererI.STATUS_OK:
         // cb.setSelected(true);
         // cb.setBackground(
         c = Color.green;
         break;
-      case 0:
+      case WSDiscovererI.STATUS_NO_SERVICES:
         // cb.setSelected(true);
         // cb.setBackground(
         c = Color.lightGray;
         break;
-      case -1:
+      case WSDiscovererI.STATUS_INVALID:
         // cb.setSelected(false);
         // cb.setBackground(
         c = Color.red;
         break;
+      case WSDiscovererI.STATUS_UNKNOWN:
       default:
         // cb.setSelected(false);
         // cb.setBackground(
@@ -241,7 +244,7 @@ public class WsPreferences extends GWsPreferences
 
   private void updateServiceList()
   {
-    Jws2Discoverer.getDiscoverer().setServiceUrls(wsUrls);
+    Jws2Discoverer.getInstance().setServiceUrls(wsUrls);
   }
 
   private void updateRsbsServiceList()
@@ -353,16 +356,14 @@ public class WsPreferences extends GWsPreferences
   {
     if (old)
     {
-      if (oldUrls != wsUrls
-              || (wsUrls != null && oldUrls != null && !wsUrls
-                      .equals(oldUrls)))
+      if (oldUrls != wsUrls || (wsUrls != null && oldUrls != null
+              && !wsUrls.equals(oldUrls)))
       {
         update++;
       }
       wsUrls = (oldUrls == null) ? null : new Vector(oldUrls);
-      if (oldRsbsUrls != rsbsUrls
-              || (rsbsUrls != null && oldRsbsUrls != null && !oldRsbsUrls
-                      .equals(rsbsUrls)))
+      if (oldRsbsUrls != rsbsUrls || (rsbsUrls != null
+              && oldRsbsUrls != null && !oldRsbsUrls.equals(rsbsUrls)))
       {
         update++;
       }
@@ -372,26 +373,21 @@ public class WsPreferences extends GWsPreferences
     {
 
     }
-    Cache.setProperty(
-            "SHOW_ENFIN_SERVICES",
+    Cache.setProperty("SHOW_ENFIN_SERVICES",
             Boolean.valueOf(
                     old ? oldEnfin : enableEnfinServices.isSelected())
                     .toString());
-    Cache.setProperty(
-            "SHOW_JWS2_SERVICES",
+    Cache.setProperty("SHOW_JWS2_SERVICES",
             Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected())
                     .toString());
-    Cache.setProperty(
-            "WSMENU_BYHOST",
+    Cache.setProperty("WSMENU_BYHOST",
             Boolean.valueOf(old ? oldIndexByHost : indexByHost.isSelected())
                     .toString());
-    Cache.setProperty(
-            "WSMENU_BYTYPE",
+    Cache.setProperty("WSMENU_BYTYPE",
             Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected())
                     .toString());
 
-    Cache.setProperty(
-            "SHOW_WSDISCOVERY_ERRORS",
+    Cache.setProperty("SHOW_WSDISCOVERY_ERRORS",
             Boolean.valueOf(
                     old ? oldWsWarning : displayWsWarning.isSelected())
                     .toString());
@@ -460,10 +456,9 @@ public class WsPreferences extends GWsPreferences
     panel.add(pane12, BorderLayout.NORTH);
     boolean valid = false;
     int resp = JvOptionPane.CANCEL_OPTION;
-    while (!valid
-            && (resp = JvOptionPane.showInternalConfirmDialog(
-                    Desktop.desktop, panel, title,
-                    JvOptionPane.OK_CANCEL_OPTION)) == JvOptionPane.OK_OPTION)
+    while (!valid && (resp = JvOptionPane.showInternalConfirmDialog(
+            Desktop.getDesktopPane(), panel, title,
+            JvOptionPane.OK_CANCEL_OPTION)) == JvOptionPane.OK_OPTION)
     {
       try
       {
@@ -480,45 +475,39 @@ public class WsPreferences extends GWsPreferences
       } catch (Exception e)
       {
         valid = false;
-        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+        JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
                 MessageManager.getString("label.invalid_url"));
       }
     }
     if (valid && resp == JvOptionPane.OK_OPTION)
     {
-      int validate = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
+      int validate = JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(),
               MessageManager.getString("info.validate_jabaws_server"),
               MessageManager.getString("label.test_server"),
               JvOptionPane.YES_NO_OPTION);
 
       if (validate == JvOptionPane.OK_OPTION)
       {
-        if (Jws2Discoverer.testServiceUrl(foo))
+        if (Jws2Discoverer.getInstance().testServiceUrl(foo))
         {
           return foo.toString();
         }
         else
         {
-          int opt = JvOptionPane
-                  .showInternalOptionDialog(
-                          Desktop.desktop,
-                          "The Server  '"
-                                  + foo.toString()
-                                  + "' failed validation,\ndo you want to add it anyway? ",
-                          "Server Validation Failed",
-                          JvOptionPane.YES_NO_OPTION,
-                          JvOptionPane.INFORMATION_MESSAGE, null, null, null);
+          int opt = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
+                  "The Server  '" + foo.toString()
+                          + "' failed validation,\ndo you want to add it anyway? ",
+                  "Server Validation Failed", JvOptionPane.YES_NO_OPTION,
+                  JvOptionPane.INFORMATION_MESSAGE, null, null, null);
           if (opt == JvOptionPane.YES_OPTION)
           {
             return foo.toString();
           }
           else
           {
-            JvOptionPane
-                    .showInternalMessageDialog(
-                            Desktop.desktop,
-                            MessageManager
-                                    .getString("warn.server_didnt_pass_validation"));
+            JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+                    MessageManager.getString(
+                            "warn.server_didnt_pass_validation"));
           }
 
         }
@@ -609,7 +598,7 @@ public class WsPreferences extends GWsPreferences
           if (lastrefresh != update)
           {
             lastrefresh = update;
-            Desktop.instance.startServiceDiscovery(true); // wait around for all
+            Desktop.getInstance().startServiceDiscovery(true); // wait around for all
                                                           // threads to complete
             updateList();
 
@@ -630,15 +619,15 @@ public class WsPreferences extends GWsPreferences
         public void run()
         {
           long ct = System.currentTimeMillis();
-          Desktop.instance.setProgressBar(MessageManager
+          Desktop.getInstance().setProgressBar(MessageManager
                   .getString("status.refreshing_web_service_menus"), ct);
           if (lastrefresh != update)
           {
             lastrefresh = update;
-            Desktop.instance.startServiceDiscovery(true);
+            Desktop.getInstance().startServiceDiscovery(true);
             updateList();
           }
-          Desktop.instance.setProgressBar(null, ct);
+          Desktop.getInstance().setProgressBar(null, ct);
         }
 
       }).start();
@@ -660,8 +649,8 @@ public class WsPreferences extends GWsPreferences
   @Override
   protected void resetWs_actionPerformed(ActionEvent e)
   {
-    Jws2Discoverer.getDiscoverer().setServiceUrls(null);
-    List<String> nwsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls();
+    Jws2Discoverer.getInstance().setServiceUrls(null);
+    List<String> nwsUrls = Jws2Discoverer.getInstance().getServiceUrls();
     if (!wsUrls.equals(nwsUrls))
     {
       update++;