X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=035da2564dc835e0f693650b8149bc412ae7fb14;hb=1f66bdde8f5379d17fe56001443e0e6fde1150d1;hp=bfd700f0c069971aa2737d87a9b8a580817d40dd;hpb=b78a8a809f8ffbda3ca79e83d3df1c89064ef202;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bfd700f..035da25 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -51,6 +51,7 @@ import java.awt.event.WindowEvent; import java.awt.geom.AffineTransform; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -63,6 +64,7 @@ import java.util.Hashtable; import java.util.List; import java.util.ListIterator; import java.util.Locale; +import java.util.Map; import java.util.Vector; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -439,7 +441,7 @@ public class Desktop extends jalview.jbgui.GDesktop * Send this message to stderr as the warning that follows (due to * reflection) also goes to stderr. */ - System.err.println( + jalview.bin.Console.errPrintln( "Linux platform only! You may have the following warning next: \"WARNING: An illegal reflective access operation has occurred\"\nThis is expected and cannot be avoided, sorry about that."); } final String awtAppClassName = "awtAppClassName"; @@ -536,6 +538,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 @@ -569,15 +574,16 @@ public class Desktop extends jalview.jbgui.GDesktop } // Thread off a new instance of the file chooser - this reduces the time - // it - // takes to open it later on. + // it takes to open it later on. new Thread(new Runnable() { @Override public void run() { jalview.bin.Console.debug("Filechooser init thread started."); - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + String fileFormat = FileLoader.getUseDefaultFileFormat() + ? Cache.getProperty("DEFAULT_FILE_FORMAT") + : null; JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat); jalview.bin.Console.debug("Filechooser init thread finished."); @@ -623,6 +629,12 @@ public class Desktop extends jalview.jbgui.GDesktop } }); desktop.addMouseListener(ma); + + if (Platform.isJS()) + { + // used for jalviewjsTest + jalview.bin.Console.info("JALVIEWJS: CREATED DESKTOP"); + } } /** @@ -864,7 +876,7 @@ public class Desktop extends jalview.jbgui.GDesktop } } catch (Exception ex) { - System.out.println( + jalview.bin.Console.outPrintln( "Unable to paste alignment from system clipboard:\n" + ex); } } @@ -1069,7 +1081,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); @@ -1229,7 +1270,9 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + String fileFormat = FileLoader.getUseDefaultFileFormat() + ? Cache.getProperty("DEFAULT_FILE_FORMAT") + : null; JalviewFileChooser chooser = JalviewFileChooser.forRead( Cache.getProperty("LAST_DIRECTORY"), fileFormat, BackupFiles.getEnabled()); @@ -1592,7 +1635,7 @@ public class Desktop extends jalview.jbgui.GDesktop } } catch (Exception ex) { - System.err.println("Error opening help: " + ex.getMessage()); + jalview.bin.Console.errPrintln("Error opening help: " + ex.getMessage()); } } @@ -1823,7 +1866,7 @@ public class Desktop extends jalview.jbgui.GDesktop boolean autoSave = projectFile != null && !saveAs && BackupFiles.getEnabled(); - // System.out.println("autoSave="+autoSave+", projectFile='"+projectFile+"', + // jalview.bin.Console.outPrintln("autoSave="+autoSave+", projectFile='"+projectFile+"', // saveAs="+saveAs+", Backups // "+(BackupFiles.getEnabled()?"enabled":"disabled")); @@ -3051,7 +3094,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; @@ -3069,12 +3112,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (dialogPause) { - try - { - block.acquire(); - } catch (InterruptedException x) - { - } + acquireDialogQueue(); } if (instance == null) { @@ -3092,12 +3130,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; } /** @@ -3132,10 +3199,14 @@ public class Desktop extends jalview.jbgui.GDesktop 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); } } @@ -3344,7 +3415,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (Platform.isAMacAndNotJS()) { - System.err.println( + jalview.bin.Console.errPrintln( "Please ignore plist error - occurs due to problem with java 8 on OSX"); } } @@ -3582,11 +3653,81 @@ public class Desktop extends jalview.jbgui.GDesktop */ 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 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(); + } + + /** + * keep track of modal JvOptionPanes open as modal dialogs for AlignFrames. + * The way the modal JInternalFrame is made means it cannot be a child of an + * AlignFrame, so closing the AlignFrame might leave the modal open :( + */ + private static Map alignFrameModalMap = new HashMap<>(); + + protected static void addModal(AlignFrame af, JInternalFrame jif) + { + alignFrameModalMap.put(af, jif); + } + + protected static void closeModal(AlignFrame af) + { + if (!alignFrameModalMap.containsKey(af)) + { + return; + } + JInternalFrame jif = alignFrameModalMap.get(af); + if (jif != null) + { + try + { + jif.setClosed(true); + } catch (PropertyVetoException e) + { + e.printStackTrace(); + } + } + alignFrameModalMap.remove(af); + } + }