JAL-4420 Allow associated files to be dragged on separately from the alignment (but...
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 5 Jun 2024 20:20:32 +0000 (21:20 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 5 Jun 2024 20:20:32 +0000 (21:20 +0100)
src/jalview/gui/Desktop.java
src/jalview/util/ArgParserUtils.java

index addbb38..fd961eb 100644 (file)
@@ -146,6 +146,7 @@ import jalview.util.ArgParserUtils;
 import jalview.util.ArgParserUtils.BaseInfo;
 import jalview.util.BrowserLauncher;
 import jalview.util.ChannelProperties;
+import jalview.util.FileUtils;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.LaunchUtils;
 import jalview.util.MessageManager;
@@ -1264,15 +1265,86 @@ public class Desktop extends jalview.jbgui.GDesktop
                   : protocols.get(i);
           FileFormatI format = null;
 
-          if (fileName.endsWith(".jar"))
+          if (fileName.toLowerCase(Locale.ROOT).endsWith(".jar"))
           {
             format = FileFormat.Jalview;
-
           }
           else
           {
             format = new IdentifyFile().identify(file, protocol);
           }
+          // If features/annotations/tree file that hasn't been put into the
+          // baseInfoMap, look through titles of opened AlignFrames to add.
+          String ext = FileUtils.getExtension(fileName);
+          boolean isFeatures = ArgParserUtils.featuresExtensions
+                  .contains(ext);
+          boolean isAnnotations = ArgParserUtils.annotationsExtensions
+                  .contains(ext);
+          boolean isTree = ArgParserUtils.treeExtensions.contains(ext);
+          if (isFeatures || isAnnotations || isTree)
+          {
+            String base = FileUtils.getBase(fileName);
+            AlignFrame matchingAf = null;
+            AlignFrame[] afs = Desktop.instance.getAlignFrames();
+            boolean dontSkip = false;
+            for (AlignFrame af : afs)
+            {
+              String afFilename = af.fileName;
+              String afTitle = af.getTitle();
+              /**
+               * don't need to check the matching afFilename or afTitle has an
+               * alignment extenstion. It's obviously an alignment!
+               */
+              /*
+              if ((base.equals(FileUtils.getBase(afFilename))
+                      && ArgParserUtils.alignmentExtensions
+                              .contains(FileUtils.getExtension(afFilename)))
+                      || (base.equals(FileUtils.getBase(afTitle))
+                              && ArgParserUtils.alignmentExtensions
+                                      .contains(FileUtils
+                                              .getExtension(afTitle))))
+              */
+              if (base.equals(FileUtils.getBase(afFilename))
+                      || base.equals(FileUtils.getBase(afTitle)))
+              {
+                matchingAf = af;
+                break;
+              }
+            }
+            if (matchingAf != null)
+            {
+              if (isFeatures)
+              {
+                matchingAf.parseFeaturesFile(fileName,
+                        AppletFormatAdapter.checkProtocol(fileName));
+              }
+              else if (isAnnotations)
+              {
+                matchingAf.loadJalviewDataFile(fileName, null, null, null);
+              }
+              else if (isTree)
+              {
+                try
+                {
+                  NewickFile nf = new NewickFile(fileName,
+                          AppletFormatAdapter.checkProtocol(fileName));
+                  matchingAf.getViewport().setCurrentTree(matchingAf
+                          .showNewickTree(nf, fileName).getTree());
+                } catch (IOException e)
+                {
+                  jalview.bin.Console.warn(
+                          "Couldn't add potential tree '" + fileName + "'");
+                  dontSkip = true;
+                }
+              }
+              if (!dontSkip)
+              {
+                // skip to next file
+                continue;
+              }
+            }
+          }
+
           if (file instanceof File)
           {
             Platform.cacheFileData((File) file);
@@ -1309,8 +1381,8 @@ public class Desktop extends jalview.jbgui.GDesktop
                         af.showNewickTree(nf, treefile).getTree());
               } catch (IOException e)
               {
-                jalview.bin.Console.warn("Couldn't add tree " + treefile,
-                        e);
+                jalview.bin.Console.warn(
+                        "Couldn't add potential tree '" + treefile + "'");
               }
 
             }
index 435ed8a..20230b2 100644 (file)
@@ -15,13 +15,13 @@ import jalview.io.FileFormats;
 
 public class ArgParserUtils
 {
-  private static Set<String> alignmentExtensions = null;
+  public static Set<String> alignmentExtensions = null;
 
-  private static Set<String> annotationsExtensions = null;
+  public static Set<String> annotationsExtensions = null;
 
-  private static Set<String> featuresExtensions = null;
+  public static Set<String> featuresExtensions = null;
 
-  private static Set<String> treeExtensions = null;
+  public static Set<String> treeExtensions = null;
 
   public static List<Arg> argSet = null;