X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=3585c93af58ef775ef1e6c241b5baec8e8b98cd9;hb=a83adb45bdf9554e270921b4baad94defd314b36;hp=95f85e6336e9c259beaad99b8ea88da3d751bce7;hpb=4f77328104498504339216829abf5ea87e2791ec;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 95f85e6..3585c93 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -37,7 +37,6 @@ import jalview.gui.JvOptionPane; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.project.Jalview2XML; import jalview.schemes.ColourSchemeI; -import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.utils.UrlDownloadClient; @@ -56,16 +55,35 @@ import javax.swing.SwingUtilities; public class FileLoader implements Runnable { + private File selectedFile; + String file; DataSourceType protocol; FileFormatI format; - AlignmentFileReaderI source = null; // alternative specification of where data - // comes + AlignmentFileReaderI source; // alternative specification of where data + // comes from - // from + /** + * It is critical that all these fields are set, as this instance is reused. + * + * @param source + * @param file + * @param inFile + * @param dataSourceType + * @param format + */ + private void setFileFields(AlignmentFileReaderI source, File file, + String inFile, DataSourceType dataSourceType, FileFormatI format) + { + this.source = source; + this.file = inFile; + this.selectedFile = file; + this.protocol = dataSourceType; + this.format = format; + } AlignViewport viewport; @@ -77,8 +95,6 @@ public class FileLoader implements Runnable boolean raiseGUI = true; - private File selectedFile; - /** * default constructor always raised errors in GUI dialog boxes */ @@ -98,7 +114,7 @@ public class FileLoader implements Runnable this.raiseGUI = raiseGUI; } - public void LoadFile(AlignViewport viewport, Object file, + public void loadFile(AlignViewport viewport, Object file, DataSourceType protocol, FileFormatI format) { this.viewport = viewport; @@ -106,10 +122,10 @@ public class FileLoader implements Runnable this.selectedFile = (File) file; file = selectedFile.getPath(); } - LoadFile(file.toString(), protocol, format); + loadFile(file.toString(), protocol, format); } - public void LoadFile(String file, DataSourceType protocol, + public void loadFile(String file, DataSourceType protocol, FileFormatI format) { this.file = file; @@ -136,7 +152,7 @@ public class FileLoader implements Runnable */ public void LoadFile(String file, DataSourceType protocol) { - LoadFile(file, protocol, null); + loadFile(file, protocol, null); } /** @@ -149,7 +165,7 @@ public class FileLoader implements Runnable public AlignFrame LoadFileWaitTillLoaded(String file, DataSourceType sourceType) { - return LoadFileWaitTillLoaded(file, sourceType, null); + return loadFileWaitTillLoaded(file, sourceType, null); } /** @@ -160,13 +176,11 @@ public class FileLoader implements Runnable * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(String file, + public AlignFrame loadFileWaitTillLoaded(String file, DataSourceType sourceType, FileFormatI format) { - this.file = file; - this.protocol = sourceType; - this.format = format; - return _LoadFileWaitTillLoaded(); + setFileFields(null, null, file, sourceType, format); + return _loadFileWaitTillLoaded(); } /** @@ -177,14 +191,11 @@ public class FileLoader implements Runnable * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(File file, + public AlignFrame loadFileWaitTillLoaded(File file, DataSourceType sourceType, FileFormatI format) { - this.selectedFile = file; - this.file = file.getPath(); - this.protocol = sourceType; - this.format = format; - return _LoadFileWaitTillLoaded(); + setFileFields(null, file, null, sourceType, format); + return _loadFileWaitTillLoaded(); } /** @@ -194,15 +205,12 @@ public class FileLoader implements Runnable * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(AlignmentFileReaderI source, + public AlignFrame loadFileWaitTillLoaded(AlignmentFileReaderI source, FileFormatI format) { - this.source = source; - - file = source.getInFile(); - protocol = source.getDataSourceType(); - this.format = format; - return _LoadFileWaitTillLoaded(); + setFileFields(source, null, source.getInFile(), + source.getDataSourceType(), format); + return _loadFileWaitTillLoaded(); } /** @@ -211,7 +219,7 @@ public class FileLoader implements Runnable * * @return */ - protected AlignFrame _LoadFileWaitTillLoaded() + private AlignFrame _loadFileWaitTillLoaded() { this.run(); return alignFrame; @@ -278,9 +286,9 @@ public class FileLoader implements Runnable Runtime rt = Runtime.getRuntime(); try { - if (Desktop.instance != null) + if (Desktop.getInstance() != null) { - Desktop.instance.startLoading(file); + Desktop.getInstance().startLoading(file); } if (format == null) { @@ -302,12 +310,12 @@ public class FileLoader implements Runnable if (format == null) { - Desktop.instance.stopLoading(); + Desktop.getInstance().stopLoading(); System.err.println("The input file \"" + file + "\" has null or unidentifiable data content!"); if (!Jalview.isHeadlessMode()) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), MessageManager.getString("label.couldnt_read_data") + " in " + file + "\n" + AppletFormatAdapter.getSupportedFormats(), @@ -318,7 +326,7 @@ public class FileLoader implements Runnable } // TODO: cache any stream datasources as a temporary file (eg. PDBs // retrieved via URL) - if (Desktop.desktop != null && Desktop.desktop.isShowMemoryUsage()) + if (Desktop.getDesktopPane() != null && Desktop.getDesktopPane().isShowMemoryUsage()) { System.gc(); memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory()); // free @@ -339,7 +347,10 @@ public class FileLoader implements Runnable // We read the data anyway - it might make sense. } // BH 2018 switch to File object here instead of filename + Platform.timeCheck(null, Platform.TIME_MARK); alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(selectedFile == null ? file : selectedFile); + Platform.timeCheck("JVP loaded", Platform.TIME_MARK); + } else { @@ -361,15 +372,15 @@ public class FileLoader implements Runnable if (downloadStructureFile) { String structExt = format.getExtensions().split(",")[0]; - String urlLeafName = file.substring( - file.lastIndexOf( - System.getProperty("file.separator")), + int pt = file.lastIndexOf(file.indexOf('/') >= 0 ? "/" + : System.getProperty("file.separator")); + String urlLeafName = file.substring(pt, file.lastIndexOf(".")); String tempStructureFileStr = createNamedJvTempFile( urlLeafName, structExt); // BH - switching to File object here so as to hold - // ._bytes array directly + // .秘bytes array directly File tempFile = new File(tempStructureFileStr); UrlDownloadClient.download(file, tempFile); @@ -410,8 +421,7 @@ public class FileLoader implements Runnable { // register PDB entries with desktop's structure selection // manager - StructureSelectionManager - .getStructureSelectionManager(Desktop.instance) + Desktop.getStructureSelectionManager() .registerPDBEntry(pdbe); } } @@ -500,23 +510,23 @@ public class FileLoader implements Runnable } else { - if (Desktop.instance != null) + if (Desktop.getInstance() != null) { - Desktop.instance.stopLoading(); + Desktop.getInstance().stopLoading(); } final String errorMessage = MessageManager.getString( "label.couldnt_load_file") + " " + title + "\n" + error; // TODO: refactor FileLoader to be independent of Desktop / Applet GUI // bits ? - if (raiseGUI && Desktop.desktop != null) + if (raiseGUI && Desktop.getDesktopPane() != null) { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), errorMessage, MessageManager .getString("label.error_loading_file"), @@ -544,7 +554,7 @@ public class FileLoader implements Runnable @Override public void run() { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), MessageManager.formatMessage( "label.problems_opening_file", new String[] { file }), @@ -566,7 +576,7 @@ public class FileLoader implements Runnable @Override public void run() { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), MessageManager.formatMessage( "warn.out_of_memory_loading_file", new String[] { file }), @@ -588,7 +598,7 @@ public class FileLoader implements Runnable // memory // after // load - if (Desktop.desktop != null && Desktop.desktop.isShowMemoryUsage()) + if (Desktop.getDesktopPane() != null && Desktop.getDesktopPane().isShowMemoryUsage()) { if (alignFrame != null) { @@ -610,9 +620,9 @@ public class FileLoader implements Runnable } } // remove the visual delay indicator - if (Desktop.instance != null) + if (Desktop.getInstance() != null) { - Desktop.instance.stopLoading(); + Desktop.getInstance().stopLoading(); } }