From: hansonr Date: Mon, 2 Jul 2018 18:00:29 +0000 (+0100) Subject: JAL-3026 File...Reload working X-Git-Tag: Release_2_11_4_0~45^2~18^2~607 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4ecd680a70a52359793d2cdc082d48a07573de79;p=jalview.git JAL-3026 File...Reload working --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ee2875a..c07cfe0 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -181,6 +181,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ String fileName = null; + File fileObject; + /** * Creates a new AlignFrame object with specific width and height. * @@ -533,6 +535,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, setFileFormat(format); reload.setEnabled(true); } + + /** + * JavaScript will have this, maybe others. More dependable than a file name + * and maintains a reference to the actual bytes loaded. + * + * @param file + */ + public void setFileObject(File file) { + this.fileObject = file; + } /** * Add a KeyListener with handlers for various KeyPressed and KeyReleased @@ -1064,8 +1076,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, FileLoader loader = new FileLoader(); DataSourceType protocol = fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE; + ? DataSourceType.URL : DataSourceType.FILE; loader.LoadFile(viewport, fileName, protocol, currentFileFormat); } else @@ -1073,11 +1084,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Rectangle bounds = this.getBounds(); FileLoader loader = new FileLoader(); - DataSourceType protocol = fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE; - AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName, - protocol, currentFileFormat); + + AlignFrame newframe = null; + + if (fileObject == null) + { + + DataSourceType protocol = (fileName.startsWith("http:") + ? DataSourceType.URL : DataSourceType.FILE); + newframe = loader.LoadFileWaitTillLoaded(fileName, protocol, + currentFileFormat); + } + else + { + newframe = loader.LoadFileWaitTillLoaded(fileObject, DataSourceType.FILE, currentFileFormat); + } newframe.setBounds(bounds); if (featureSettings != null && featureSettings.isShowing()) diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index eda3899..8e68067 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -170,6 +170,24 @@ public class FileLoader implements Runnable } /** + * Load alignment from (file, protocol) of type format and wait till loaded + * + * @param file + * @param sourceType + * @param format + * @return alignFrame constructed from file contents + */ + public AlignFrame LoadFileWaitTillLoaded(File file, + DataSourceType sourceType, FileFormatI format) + { + this.selectedFile = file; + this.file = file.getPath(); + this.protocol = sourceType; + this.format = format; + return _LoadFileWaitTillLoaded(); + } + + /** * Load alignment from FileParse source of type format and wait till loaded * * @param source @@ -443,6 +461,7 @@ public class FileLoader implements Runnable if (!(protocol == DataSourceType.PASTE)) { alignFrame.setFileName(file, format); + alignFrame.setFileObject(selectedFile); // BH 2018 SwingJS } if (proxyColourScheme != null) {