Merge branch 'patch/JAL-4196_structure_viewer_synchronising' into develop patch/JAL-4196_structure_viewer_synchronising
authorJames Procter <j.procter@dundee.ac.uk>
Wed, 21 Jun 2023 11:24:27 +0000 (13:24 +0200)
committerJames Procter <j.procter@dundee.ac.uk>
Wed, 21 Jun 2023 11:24:27 +0000 (13:24 +0200)
1  2 
src/jalview/gui/Desktop.java

@@@ -536,9 -536,6 +536,9 @@@ public class Desktop extends jalview.jb
        setBounds(xPos, yPos, 900, 650);
      }
  
 +    // start dialogue queue for single dialogues
 +    startDialogQueue();
 +
      if (!Platform.isJS())
      /**
       * Java only
        }
      });
      desktop.addMouseListener(ma);
 +
 +    if (Platform.isJS())
 +    {
 +      // used for jalviewjsTest
 +      jalview.bin.Console.info("JALVIEWJS: CREATED DESKTOP");
 +    }
    }
  
    /**
    /**
     * pause the queue
     */
 -  private java.util.concurrent.Semaphore block = new Semaphore(0);
 +  private Semaphore block = new Semaphore(0);
  
    private static groovy.ui.Console groovyConsole;
  
        {
          if (dialogPause)
          {
 -          try
 -          {
 -            block.acquire();
 -          } catch (InterruptedException x)
 -          {
 -          }
 +          acquireDialogQueue();
          }
          if (instance == null)
          {
      });
    }
  
 +  private boolean dialogQueueStarted = false;
 +
    public void startDialogQueue()
    {
 +    if (dialogQueueStarted)
 +    {
 +      return;
 +    }
      // set the flag so we don't pause waiting for another permit and semaphore
      // the current task to begin
 -    dialogPause = false;
 +    releaseDialogQueue();
 +    dialogQueueStarted = true;
 +  }
 +
 +  public void acquireDialogQueue()
 +  {
 +    try
 +    {
 +      block.acquire();
 +      dialogPause = true;
 +    } catch (InterruptedException e)
 +    {
 +      jalview.bin.Console.debug("Interruption when acquiring DialogueQueue",
 +              e);
 +    }
 +  }
 +
 +  public void releaseDialogQueue()
 +  {
 +    if (!dialogPause)
 +    {
 +      return;
 +    }
      block.release();
 +    dialogPause = false;
    }
  
    /**
      String title = "View of desktop";
      ImageExporter exporter = new ImageExporter(writer, null, TYPE.EPS,
              title);
 -    try {
 +    try
 +    {
        exporter.doExport(of, this, width, height, title);
 -    } catch (ImageOutputException ioex) {
 -      jalview.bin.Console.error("Unexpected error whilst writing Jalview desktop snapshot as EPS",ioex);
 +    } catch (ImageOutputException ioex)
 +    {
 +      jalview.bin.Console.error(
 +              "Unexpected error whilst writing Jalview desktop snapshot as EPS",
 +              ioex);
      }
    }
  
     */
    public static void closeDesktop()
    {
 -    if (Desktop.instance != null) {
 +    if (Desktop.instance != null)
 +    {
        Desktop.instance.closeAll_actionPerformed(null);
        Desktop.instance.setVisible(false);
        Desktop.instance.dispose();
        Desktop.instance = null;
      }
    }
+   /**
+    * checks if any progress bars are being displayed in any of the windows managed by the desktop
+    * @return
+    */
+   public boolean operationsAreInProgress()
+   {
+     JInternalFrame[] frames = getAllFrames();
+     for (JInternalFrame frame:frames)
+     {
+       if (frame instanceof IProgressIndicator)
+       {
+         if (((IProgressIndicator)frame).operationInProgress())
+         {
+           return true;
+         }
+       }
+     }
+     return operationInProgress();
+   }
  }