JAL-629 Allow attachment of pAE file to a particular sequence
[jalview.git] / src / jalview / io / FileLoader.java
index 3d2dded..c7ade20 100755 (executable)
@@ -33,6 +33,8 @@ import jalview.api.FeaturesDisplayedI;
 import jalview.api.FeaturesSourceI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentAnnotation.TFType;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
@@ -73,6 +75,8 @@ public class FileLoader implements Runnable
 
   private File selectedFile;
 
+  private AlignmentAnnotation.TFType temperatureFactorType = null;
+
   /**
    * default constructor always raised errors in GUI dialog boxes
    */
@@ -96,7 +100,8 @@ public class FileLoader implements Runnable
           DataSourceType protocol, FileFormatI format)
   {
     this.viewport = viewport;
-    if (file instanceof File) {
+    if (file instanceof File)
+    {
       this.selectedFile = (File) file;
       file = selectedFile.getPath();
     }
@@ -157,9 +162,26 @@ public class FileLoader implements Runnable
   public AlignFrame LoadFileWaitTillLoaded(String file,
           DataSourceType sourceType, FileFormatI format)
   {
+    return LoadFileWaitTillLoaded(file, sourceType, format, null);
+  }
+
+  /**
+   * Load alignment from (file, protocol) of type format with specified
+   * temperature factor type and wait till loaded
+   * 
+   * @param file
+   * @param sourceType
+   * @param format
+   * @param tempfacType
+   * @return alignFrame constructed from file contents
+   */
+  public AlignFrame LoadFileWaitTillLoaded(String file,
+          DataSourceType sourceType, FileFormatI format, AlignmentAnnotation.TFType tempfacType)
+  {
     this.file = file;
     this.protocol = sourceType;
     this.format = format;
+    this.temperatureFactorType = tempfacType;
     return _LoadFileWaitTillLoaded();
   }
 
@@ -271,6 +293,7 @@ public class FileLoader implements Runnable
             ? "Copied From Clipboard"
             : file;
     Runtime rt = Runtime.getRuntime();
+
     try
     {
       if (Desktop.instance != null)
@@ -285,7 +308,8 @@ public class FileLoader implements Runnable
           format = new IdentifyFile().identify(source, false);
           // identify stream and rewind rather than close
         }
-        else if (selectedFile != null) {
+        else if (selectedFile != null)
+        {
           format = new IdentifyFile().identify(selectedFile, protocol);
         }
         else
@@ -334,7 +358,8 @@ public class FileLoader implements Runnable
           // We read the data anyway - it might make sense.
         }
         // BH 2018 switch to File object here instead of filename
-        alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(selectedFile == null ? file : selectedFile);
+        alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(
+                selectedFile == null ? file : selectedFile);
       }
       else
       {
@@ -362,27 +387,31 @@ public class FileLoader implements Runnable
                       file.lastIndexOf("."));
               String tempStructureFileStr = createNamedJvTempFile(
                       urlLeafName, structExt);
-              
+
               // 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);
+
+              al = fa.readFile(tempFile, DataSourceType.FILE, format);
               source = fa.getAlignFile();
             }
             else
             {
-              if (selectedFile == null) {
-                al = fa.readFile(file, protocol, format);
-                
-              } else {
-                al = fa.readFile(selectedFile, protocol, format);
-                             }
+              if (selectedFile == null)
+              {
+                al = fa.readFile(null, file, protocol, format,
+                        temperatureFactorType);
+
+              }
+              else
+              {
+                al = fa.readFile(selectedFile, null, protocol, format,
+                        temperatureFactorType);
+              }
               source = fa.getAlignFile(); // keep reference for later if
-              
-                                          // necessary.
+
+              // necessary.
             }
           }
         } catch (java.io.IOException ex)
@@ -483,8 +512,8 @@ public class FileLoader implements Runnable
 
             try
             {
-              alignFrame.setMaximum(Cache
-                      .getDefault("SHOW_FULLSCREEN", false));
+              alignFrame.setMaximum(
+                      Cache.getDefault("SHOW_FULLSCREEN", false));
             } catch (java.beans.PropertyVetoException ex)
             {
             }