X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=9ede0f55d69b2d3e54d49167bcb6d988aaafa64e;hb=3bf2b5ea57b1d77d6e2e7adc11a50387e5376dc0;hp=d3ac53fd0759f7b2fda48822e00ceb0ccce734ce;hpb=34ce5193c8766085422c32544246d92f12d0c975;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index d3ac53f..9ede0f5 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -41,6 +41,7 @@ import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; +import jalview.gui.QuitHandler; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.project.Jalview2XML; import jalview.schemes.ColourSchemeI; @@ -73,6 +74,8 @@ public class FileLoader implements Runnable private File selectedFile; + private static boolean useDefaultFileFormat = false; + /** * default constructor always raised errors in GUI dialog boxes */ @@ -95,32 +98,51 @@ public class FileLoader implements Runnable public void LoadFile(AlignViewport viewport, Object file, DataSourceType protocol, FileFormatI format) { + LoadFile(viewport, file, protocol, format, true); + } + + public void LoadFile(AlignViewport viewport, Object file, + DataSourceType protocol, FileFormatI format, boolean async) + { this.viewport = viewport; if (file instanceof File) { this.selectedFile = (File) file; file = selectedFile.getPath(); } - LoadFile(file.toString(), protocol, format); + LoadFile(file.toString(), protocol, format, async); } public void LoadFile(String file, DataSourceType protocol, FileFormatI format) { + LoadFile(file, protocol, format, true); + } + + public void LoadFile(String file, DataSourceType protocol, + FileFormatI format, boolean async) + { this.file = file; this.protocol = protocol; this.format = format; - final Thread loader = new Thread(this); - - SwingUtilities.invokeLater(new Runnable() + if (async) { - @Override - public void run() + final Thread loader = new Thread(this); + + SwingUtilities.invokeLater(new Runnable() { - loader.start(); - } - }); + @Override + public void run() + { + loader.start(); + } + }); + } + else + { + this.run(); + } } /** @@ -312,6 +334,8 @@ public class FileLoader implements Runnable MessageManager.getString("label.couldnt_read_data"), JvOptionPane.WARNING_MESSAGE); } + // don't set shouldBeSaved if didn't load anything + // this.setShouldBeSaved(); return; } // TODO: cache any stream datasources as a temporary file (eg. PDBs @@ -485,6 +509,12 @@ public class FileLoader implements Runnable // that perform queries to find the 'current working alignment' Desktop.addInternalFrame(alignFrame, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); + + /* + * for an Overview automatically opened with alignment, + * set its title now alignFrame title has been set + */ + alignFrame.alignPanel.setOverviewTitle(alignFrame); } try @@ -613,6 +643,9 @@ public class FileLoader implements Runnable Desktop.instance.stopLoading(); } + this.setShouldBeSaved(); + // after first file loaded we revert to assuming a default file format + useDefaultFileFormat = true; } /** @@ -638,4 +671,26 @@ public class FileLoader implements Runnable return tempStructFile.toString(); } + /* + * set whether quit should ask to save when just loaded this source + */ + private void setShouldBeSaved() + { + if (protocol == null) + return; + AlignFrame af = this.alignFrame; + if (af == null) + return; + AlignViewport avp = af.getViewport(); + if (avp == null) + return; + avp.setSavedUpToDate(!protocol.isDynamic(), + QuitHandler.Message.UNSAVED_ALIGNMENTS); + } + + public static boolean getUseDefaultFileFormat() + { + return useDefaultFileFormat; + } + }