Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / gui / Desktop.java
index d4f479a..88c94f6 100644 (file)
@@ -59,8 +59,11 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Vector;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
 import java.util.concurrent.Semaphore;
 
 import javax.swing.AbstractAction;
@@ -121,9 +124,9 @@ 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.WSDiscovererI;
 import jalview.ws.params.ParamManager;
 import jalview.ws.utils.UrlDownloadClient;
 
@@ -163,6 +166,7 @@ public class Desktop extends GDesktop
 
   public static HashMap<String, FileWriter> savingFiles = new HashMap<String, FileWriter>();
 
+  @SuppressWarnings("deprecation")
   private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
 
   /**
@@ -176,6 +180,7 @@ public class Desktop extends GDesktop
    * @param listener
    * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
    */
+  @Deprecated
   public void addJalviewPropertyChangeListener(
           PropertyChangeListener listener)
   {
@@ -188,6 +193,7 @@ public class Desktop extends GDesktop
    * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
    *      java.beans.PropertyChangeListener)
    */
+  @Deprecated
   public void addJalviewPropertyChangeListener(String propertyName,
           PropertyChangeListener listener)
   {
@@ -200,6 +206,7 @@ public class Desktop extends GDesktop
    * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
    *      java.beans.PropertyChangeListener)
    */
+  @Deprecated
   public void removeJalviewPropertyChangeListener(String propertyName,
           PropertyChangeListener listener)
   {
@@ -487,8 +494,6 @@ public class Desktop extends GDesktop
           // disabled for SeqCanvasTest
           checkURLLinks();
 
-          checkURLLinks();
-
           // Spawn a thread that shows the splashscreen
 
           SwingUtilities.invokeLater(new Runnable()
@@ -842,12 +847,7 @@ public class Desktop extends GDesktop
   {
     // 58 classes
     
-    setFrame(frame, title, w, h);
-
-    // Headless operation has no Desktop instance, only the static class.
-
-    if (getInstance() != null)
-      getInstance().addFrame(frame, Desktop.FRAME_MAKE_VISIBLE,
+    addInternalFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h, 
             FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300);
   }
 
@@ -875,9 +875,18 @@ public class Desktop extends GDesktop
           final JInternalFrame frame, String title, boolean makeVisible,
           int w, int h, boolean resizable, boolean ignoreMinSize)
   {
-    // 15 classes
-    setFrame(frame, title, w, h);
+    // 15 classes call this method directly.
+    
+    // TODO: allow callers to determine X and Y position of frame (eg. via
+    // bounds object).
+    // TODO: consider fixing method to update entries in the window submenu with
+    // the current window title
 
+    frame.setTitle(title);
+    if (frame.getWidth() < 1 || frame.getHeight() < 1)
+    {
+      frame.setSize(w, h);
+    }
     if (getInstance() != null)
       getInstance().addFrame(frame, makeVisible, resizable,
             ignoreMinSize);
@@ -896,21 +905,6 @@ public class Desktop extends GDesktop
   public final static boolean FRAME_ALLOW_ANY_SIZE = true;
 
   public final static boolean FRAME_SET_MIN_SIZE_300 = false;
-
-  private static void setFrame(JInternalFrame frame, String title,
-          int w, int h)
-  {
-    // TODO: allow callers to determine X and Y position of frame (eg. via
-    // bounds object).
-    // TODO: consider fixing method to update entries in the window submenu with
-    // the current window title
-
-    frame.setTitle(title);
-    if (frame.getWidth() < 1 || frame.getHeight() < 1)
-    {
-      frame.setSize(w, h);
-    }
-  }
   
   private void addFrame(JInternalFrame frame,
           boolean makeVisible, boolean resizable,
@@ -1621,7 +1615,8 @@ public class Desktop extends GDesktop
       return;
     }
 
-    AlignmentViewport source = null, target = null;
+    AlignViewportI source = null;
+    AlignViewportI target = null;
     if (frames[0] instanceof AlignFrame)
     {
       source = ((AlignFrame) frames[0]).getCurrentView();
@@ -2587,6 +2582,13 @@ public class Desktop extends GDesktop
       progressBars.put(Long.valueOf(id), addProgressPanel(message));
     }
   }
+  
+  @Override
+  public void removeProgressBar(long id)
+  {
+    //TODO
+    throw new UnsupportedOperationException("not implemented");
+  }
 
   /*
    * (non-Javadoc)
@@ -2706,10 +2708,13 @@ public class Desktop extends GDesktop
 
   public void startServiceDiscovery(boolean blocking)
   {
-    boolean alive = true;
-    Thread t0 = null, t1 = null, t2 = null;
+    System.out.println("Starting service discovery");
+    var tasks = new ArrayList<Future<?>>();
     // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
-    if (true)
+
+    System.out.println("loading services");
+    
+    /** @j2sIgnore */
     {
       // todo: changesupport handlers need to be transferred
       if (discoverer == null)
@@ -2720,31 +2725,30 @@ public class Desktop extends GDesktop
       }
       // JAL-940 - disabled JWS1 service configuration - always start discoverer
       // until we phase out completely
-      (t0 = new Thread(discoverer)).start();
+      var f = new FutureTask<Void>(discoverer, null);
+      new Thread(f).start();
+      tasks.add(f);
     }
 
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
-      t2 = jalview.ws.jws2.Jws2Discoverer.getInstance()
-              .startDiscoverer(changeSupport);
+      tasks.add(jalview.ws.jws2.Jws2Discoverer.getInstance().startDiscoverer());
     }
-    Thread t3 = null;
+    if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
     {
-      // TODO: do rest service discovery
+      tasks.add(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance().startDiscoverer());
     }
     if (blocking)
     {
-      while (alive)
-      {
+      for (Future<?> task : tasks) {
         try
         {
-          Thread.sleep(15);
+          // block until all discovery tasks are done
+          task.get();
         } catch (Exception e)
         {
+          e.printStackTrace();
         }
-        alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive())
-                || (t3 != null && t3.isAlive())
-                || (t0 != null && t0.isAlive());
       }
     }
   }
@@ -2758,8 +2762,10 @@ public class Desktop extends GDesktop
   {
     if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
     {
-      final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance()
-              .getErrorMessages();
+      final WSDiscovererI discoverer = jalview.ws.jws2.Jws2Discoverer
+          .getInstance();
+      final String ermsg = discoverer.getErrorMessages();
+      // CONFLICT:ALT:?     final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance()
       if (ermsg != null)
       {
         if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))