JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / io / FileLoader.java
index eda3899..95f85e6 100755 (executable)
@@ -33,12 +33,13 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.gui.Desktop;
-import jalview.gui.Jalview2XML;
 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;
 
 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;
@@ -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
@@ -320,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
       {
@@ -348,8 +367,13 @@ public class FileLoader implements Runnable
                       file.lastIndexOf("."));
               String tempStructureFileStr = createNamedJvTempFile(
                       urlLeafName, structExt);
-              UrlDownloadClient.download(file, tempStructureFileStr);
-              al = fa.readFile(tempStructureFileStr, DataSourceType.FILE,
+              
+              // BH - switching to File object here so as to hold
+              // ._bytes array directly
+              File tempFile = new File(tempStructureFileStr);
+              UrlDownloadClient.download(file, tempFile);
+              
+              al = fa.readFile(tempFile, DataSourceType.FILE,
                       format);
               source = fa.getAlignFile();
             }
@@ -443,13 +467,14 @@ public class FileLoader implements Runnable
             if (!(protocol == DataSourceType.PASTE))
             {
               alignFrame.setFileName(file, format);
+              alignFrame.setFileObject(selectedFile); // BH 2018 SwingJS
             }
             if (proxyColourScheme != null)
             {
               alignFrame.getViewport()
                       .applyFeaturesStyle(proxyColourScheme);
             }
-            alignFrame.statusBar.setText(MessageManager.formatMessage(
+            alignFrame.setStatus(MessageManager.formatMessage(
                     "label.successfully_loaded_file", new String[]
                     { title }));
 
@@ -621,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));
   }