X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=38594dfbf1fa9fc0948c7ca612afc3c269da783c;hb=6babd7c2387996384a49042ed4290095c13d5ed9;hp=f244d14a12500d827f88fe1dc11aefdf5c25382c;hpb=59d9dfb7b746fcc396af9b572b40636028df9fed;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index f244d14..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 @@ -361,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); @@ -411,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); } } @@ -500,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"), @@ -544,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 }), @@ -566,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 }), @@ -588,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) { @@ -610,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(); } } @@ -646,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)); }