X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=12ff20b742fd944ec50bdabe5f88b1a652da3b11;hb=4b031bc957ad1c5512798c6206adac7ed0364331;hp=2dfe8205886fe26b84d9f66e3c95e0b13069c0b8;hpb=3ba8b399b3f6e8163b748e208465dbb7bf4efbd5;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 2dfe820..12ff20b 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -536,6 +536,9 @@ public class Desktop extends jalview.jbgui.GDesktop setBounds(xPos, yPos, 900, 650); } + // start dialogue queue for single dialogues + startDialogQueue(); + if (!Platform.isJS()) /** * Java only @@ -1075,7 +1078,36 @@ public class Desktop extends jalview.jbgui.GDesktop setKeyBindings(frame); - desktop.add(frame); + // Since the latest FlatLaf patch, we occasionally have problems showing structureViewer frames... + int tries=3; + boolean shown=false; + Exception last=null; + do + { + try + { + desktop.add(frame); + shown=true; + } catch (IllegalArgumentException iaex) + { + last=iaex; + tries--; + jalview.bin.Console.info( + "Squashed IllegalArgument Exception (" + tries + " left) for "+frame.getTitle(), + iaex); + try + { + Thread.sleep(5); + } catch (InterruptedException iex) + { + } + ; + } + } while (!shown && tries > 0); + if (!shown) + { + jalview.bin.Console.error("Serious Problem whilst showing window "+frame.getTitle(),last); + } windowMenu.add(menuItem); @@ -3057,7 +3089,7 @@ public class Desktop extends jalview.jbgui.GDesktop /** * pause the queue */ - private java.util.concurrent.Semaphore block = new Semaphore(0); + private Semaphore block = new Semaphore(0); private static groovy.ui.Console groovyConsole; @@ -3075,12 +3107,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (dialogPause) { - try - { - block.acquire(); - } catch (InterruptedException x) - { - } + acquireDialogQueue(); } if (instance == null) { @@ -3098,12 +3125,41 @@ public class Desktop extends jalview.jbgui.GDesktop }); } + 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; } /** @@ -3596,8 +3652,42 @@ public class Desktop extends jalview.jbgui.GDesktop { Desktop.instance.closeAll_actionPerformed(null); Desktop.instance.setVisible(false); - Desktop.instance.dispose(); + Desktop us = Desktop.instance; Desktop.instance = null; + // call dispose in a separate thread - try to avoid indirect deadlocks + new Thread(new Runnable() { + @Override + public void run() + { + ExecutorService dex = us.dialogExecutor; + if (dex!=null) { + dex.shutdownNow(); + us.dialogExecutor=null; + us.block.drainPermits(); + } + us.dispose(); + } + }).start(); + } + } + + /** + * 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(); } }