JAL-3048 AlignFrame->File->Load Tree adapted for js
[jalview.git] / src / jalview / gui / AlignFrame.java
index 26c5548..dafeafc 100644 (file)
@@ -1118,6 +1118,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void saveAs_actionPerformed(ActionEvent e)
   {
+    // TODO: JAL-3048 JalviewFileChooser - Save option
+
     String format = currentFileFormat == null ? null
             : currentFileFormat.getName();
     JalviewFileChooser chooser = JalviewFileChooser
@@ -1422,7 +1424,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void associatedData_actionPerformed(ActionEvent e)
   {
-    // Pick the tree file
     JalviewFileChooser chooser = new JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new JalviewFileView());
@@ -3904,6 +3905,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
   {
+    // TODO: JAL-3048 JalviewFileChooser
     // Pick the tree file
     JalviewFileChooser chooser = new JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
@@ -3913,33 +3915,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setToolTipText(
             MessageManager.getString("label.load_tree_file"));
 
-    int value = chooser.showOpenDialog(null);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      String filePath = chooser.getSelectedFile().getPath();
-      Cache.setProperty("LAST_DIRECTORY", filePath);
-      NewickFile fin = null;
-      try
-      {
-        fin = new NewickFile(filePath, DataSourceType.FILE);
-        viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
-      } catch (Exception ex)
-      {
-        JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
-                MessageManager.getString("label.problem_reading_tree_file"),
-                JvOptionPane.WARNING_MESSAGE);
-        ex.printStackTrace();
-      }
-      if (fin != null && fin.hasWarningMessage())
-      {
-        JvOptionPane.showMessageDialog(Desktop.desktop,
-                fin.getWarningMessage(),
-                MessageManager
-                        .getString("label.possible_problem_with_tree_file"),
-                JvOptionPane.WARNING_MESSAGE);
-      }
-    }
+    chooser.response(
+            new jalview.util.dialogrunner.RunResponse(JalviewFileChooser.APPROVE_OPTION)
+            {
+              @Override
+              public void run()
+              {
+                String filePath = chooser.getSelectedFile().getPath();
+                Cache.setProperty("LAST_DIRECTORY", filePath);
+                NewickFile fin = null;
+                try
+                {
+                  fin = new NewickFile(filePath, DataSourceType.FILE);
+                  viewport.setCurrentTree(
+                          showNewickTree(fin, filePath).getTree());
+                } catch (Exception ex)
+                {
+                  JvOptionPane.showMessageDialog(Desktop.desktop,
+                          ex.getMessage(),
+                          MessageManager.getString(
+                                  "label.problem_reading_tree_file"),
+                          JvOptionPane.WARNING_MESSAGE);
+                  ex.printStackTrace();
+                }
+                if (fin != null && fin.hasWarningMessage())
+                {
+                  JvOptionPane.showMessageDialog(Desktop.desktop,
+                          fin.getWarningMessage(),
+                          MessageManager.getString(
+                                  "label.possible_problem_with_tree_file"),
+                          JvOptionPane.WARNING_MESSAGE);
+                }
+              }
+            }).openDialog(this);
   }
 
   public TreePanel showNewickTree(NewickFile nf, String treeTitle)
@@ -4359,13 +4367,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Try to load a features file onto the alignment.
    * 
    * @param file
-   *          contents or path to retrieve file
+   *          contents or path to retrieve file or a File object
    * @param sourceType
    *          access mode of file (see jalview.io.AlignFile)
    * @return true if features file was parsed correctly.
    */
-  public boolean parseFeaturesFile(String file, DataSourceType sourceType)
+  public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
   {
+    // BH 2018 
     return avc.parseFeaturesFile(file, sourceType,
             Cache.getDefault("RELAXEDSEQIDMATCHING", false));
 
@@ -4412,8 +4421,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // Java's Transferable for native dnd
     evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
     Transferable t = evt.getTransferable();
+    
+    
     final AlignFrame thisaf = this;
-    final List<String> files = new ArrayList<>();
+    final List<Object> files = new ArrayList<>();
     List<DataSourceType> protocols = new ArrayList<>();
 
     try
@@ -4441,20 +4452,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<String> filesnotmatched = new ArrayList<>();
+            ArrayList<Object> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
-              String file = files.get(i).toString();
+              // BH 2018 
+              Object file = files.get(i);
+              String fileName = file.toString();
               String pdbfn = "";
-              DataSourceType protocol = FormatAdapter.checkProtocol(file);
+              DataSourceType protocol = (file instanceof File ? DataSourceType.FILE : FormatAdapter.checkProtocol(fileName));
               if (protocol == DataSourceType.FILE)
               {
-                File fl = new File(file);
+                File fl = (file instanceof File ? (File) file : new File(fileName));
                 pdbfn = fl.getName();
               }
               else if (protocol == DataSourceType.URL)
               {
-                URL url = new URL(file);
+                URL url = new URL(fileName);
                 pdbfn = url.getFile();
               }
               if (pdbfn.length() > 0)
@@ -4476,7 +4489,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 if (mtch != null)
                 {
-                  FileFormatI type = null;
+                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4545,7 +4558,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                  */
                 for (Object[] o : filesmatched)
                 {
-                  filesnotmatched.add((String) o[0]);
+                  filesnotmatched.add(o[0]);
                 }
               }
             }
@@ -4567,7 +4580,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (String fn : filesnotmatched)
+              for (Object fn : filesnotmatched)
               {
                 loadJalviewDataFile(fn, null, null, null);
               }
@@ -4594,9 +4607,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param file
    *          either a filename or a URL string.
    */
-  public void loadJalviewDataFile(String file, DataSourceType sourceType,
+  public void loadJalviewDataFile(Object file, DataSourceType sourceType,
           FileFormatI format, SequenceI assocSeq)
   {
+    // BH 2018 was String file
     try
     {
       if (sourceType == null)
@@ -5627,6 +5641,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void loadVcf_actionPerformed()
   {
+    // TODO: JAL-3048 - No VCF support in JsJalview
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new JalviewFileView());