X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FFileLoader.java;h=38594dfbf1fa9fc0948c7ca612afc3c269da783c;hb=6babd7c2387996384a49042ed4290095c13d5ed9;hp=390e8cd3360f9dee5856d82c0e53a1472a8104d5;hpb=fab0afc9e1e7a5ca460f0cbd48545536f989a435;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 390e8cd..38594df 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -39,6 +39,7 @@ 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; import java.io.BufferedReader; @@ -47,7 +48,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Vector; @@ -278,9 +278,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 +302,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 +318,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 @@ -338,7 +338,8 @@ public class FileLoader implements Runnable "IMPLEMENTATION ERROR: Cannot read consecutive Jalview XML projects from a stream."); // We read the data anyway - it might make sense. } - alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(file); + // BH 2018 switch to File object here instead of filename + alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(selectedFile == null ? file : selectedFile); } else { @@ -360,9 +361,9 @@ 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); @@ -410,7 +411,7 @@ public class FileLoader implements Runnable // register PDB entries with desktop's structure selection // manager StructureSelectionManager - .getStructureSelectionManager(Desktop.instance) + .getStructureSelectionManager(Desktop.getInstance()) .registerPDBEntry(pdbe); } } @@ -499,23 +500,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"), @@ -543,7 +544,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 }), @@ -565,7 +566,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 }), @@ -587,7 +588,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) { @@ -609,9 +610,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(); } } @@ -645,14 +646,16 @@ public class FileLoader implements Runnable * @return * @throws FileNotFoundException */ - @SuppressWarnings("unused") - public static BufferedReader getBuffereReader(Object file) throws FileNotFoundException { + public static BufferedReader getBufferedReader(Object file) throws FileNotFoundException { if (file instanceof String) + { return new BufferedReader(new FileReader((String) file)); - - byte[] bytes = /** @j2sNative file._bytes || */ null; + } + byte[] bytes = Platform.getFileBytes((File) file); if (bytes != null) + { return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes))); + } return new BufferedReader(new FileReader((File) file)); }