From 6151b89badff956d951326011424c08ccabb5e99 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 5 Jun 2024 21:20:32 +0100 Subject: [PATCH] JAL-4420 Allow associated files to be dragged on separately from the alignment (but afterwards). --- src/jalview/gui/Desktop.java | 80 ++++++++++++++++++++++++++++++++-- src/jalview/util/ArgParserUtils.java | 8 ++-- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index addbb38..fd961eb 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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 + "'"); } } diff --git a/src/jalview/util/ArgParserUtils.java b/src/jalview/util/ArgParserUtils.java index 435ed8a..20230b2 100644 --- a/src/jalview/util/ArgParserUtils.java +++ b/src/jalview/util/ArgParserUtils.java @@ -15,13 +15,13 @@ import jalview.io.FileFormats; public class ArgParserUtils { - private static Set alignmentExtensions = null; + public static Set alignmentExtensions = null; - private static Set annotationsExtensions = null; + public static Set annotationsExtensions = null; - private static Set featuresExtensions = null; + public static Set featuresExtensions = null; - private static Set treeExtensions = null; + public static Set treeExtensions = null; public static List argSet = null; -- 1.7.10.2