From a16741c87b8246f228af144f52bcff904d66e43a Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 28 Mar 2023 11:17:23 +0100 Subject: [PATCH] JAL-629 Opening files in new windows. not working yet --- src/jalview/bin/Commands.java | 19 ++++++++-- src/jalview/bin/Jalview.java | 8 +++-- src/jalview/bin/argparser/Arg.java | 15 ++++---- src/jalview/bin/argparser/ArgParser.java | 48 ++++++++++++-------------- src/jalview/bin/argparser/ArgValue.java | 17 ++++++++- src/jalview/bin/argparser/BootstrapArgs.java | 35 +++++++++++++++---- src/jalview/bin/argparser/SubVals.java | 17 ++++++--- src/jalview/gui/Desktop.java | 38 ++++++++++---------- 8 files changed, 132 insertions(+), 65 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 67c0c64..43dc1fd 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -2,6 +2,7 @@ package jalview.bin; import java.io.File; import java.io.IOException; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -10,6 +11,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import jalview.analysis.AlignmentUtils; import jalview.api.AlignmentViewPanel; @@ -33,6 +35,7 @@ import jalview.gui.StructureChooser; import jalview.gui.StructureViewer; import jalview.io.AppletFormatAdapter; import jalview.io.DataSourceType; +import jalview.io.FileFormat; import jalview.io.FileFormatException; import jalview.io.FileFormatI; import jalview.io.FileLoader; @@ -164,8 +167,19 @@ public class Commands boolean first = true; boolean progressBarSet = false; AlignFrame af; - for (ArgValue av : avm.getArgValueList(Arg.OPEN)) + List> openAvList = new ArrayList<>(); + avm.getArgValueList(Arg.OPEN).stream() + .forEachOrdered(av -> openAvList.add( + new AbstractMap.SimpleEntry(Arg.OPEN, + av))); + avm.getArgValueList(Arg.OPENNEW).stream() + .forEachOrdered(av -> openAvList + .add(new AbstractMap.SimpleEntry( + Arg.OPENNEW, av))); + for (Entry aav : openAvList) { + Arg a = aav.getKey(); + ArgValue av = aav.getValue(); String openFile = av.getValue(); if (openFile == null) continue; @@ -213,7 +227,8 @@ public class Commands } af = afMap.get(id); - if (af == null) + if (af == null || "true".equals(av.getSubVal("new")) + || a == Arg.OPENNEW || format == FileFormat.Jalview) { /* * this approach isn't working yet diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 9e488dc..bc8c997 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -649,14 +649,16 @@ public class Jalview .println("CMD [-noquestionnaire] executed successfully!"); } - if (!aparser.contains("nonews") - || Cache.getProperty("NONEWS") == null) + if ((!aparser.contains("nonews") + && Cache.getProperty("NONEWS") == null + && !"false".equals(bootstrapArgs.get(Arg.NEWS))) + || "true".equals(bootstrapArgs.get(Arg.NEWS))) { desktop.checkForNews(); } if (!aparser.contains("nohtmltemplates") - || Cache.getProperty("NOHTMLTEMPLATES") == null) + && Cache.getProperty("NOHTMLTEMPLATES") == null) { BioJsHTMLOutput.updateBioJS(); } diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index a13acd2..4c2465c 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -10,11 +10,11 @@ public enum Arg HELP("h"), CALCULATION, MENUBAR, STATUS, SHOWOVERVIEW, ANNOTATIONS, COLOUR, FEATURES, GROOVY, GROUPS, HEADLESS, JABAWS, ANNOTATION, ANNOTATION2, DISPLAY, GUI, NEWS, NOQUESTIONNAIRE, SORTBYTREE, USAGESTATS, - OPEN, OPEN2, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC, VSESS, OUTPUT, + OPEN, OPENNEW, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC, VSESS, OUTPUT, OUTPUTTYPE, SSANNOTATION, NOTEMPFAC, TEMPFAC, TEMPFAC_LABEL, TEMPFAC_DESC, TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP, NOSTRUCTURE, STRUCTURE, IMAGE, QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, INCREMENT, NPP("n++"), - SUBSTITUTIONS, NIL; + SUBSTITUTIONS, NIL, SPLASH; protected static enum Opt { @@ -43,14 +43,17 @@ public enum Arg ANNOTATION2.setOptions(true, Opt.BOOLEAN, Opt.LINKED); DISPLAY.setOptions(true, Opt.BOOLEAN); GUI.setOptions(true, Opt.BOOLEAN); - NEWS.setOptions(true, Opt.BOOLEAN); - NOQUESTIONNAIRE.setOptions(Opt.UNARY); // unary as --questionnaire=val - // expects a string value + NEWS.setOptions(true, Opt.BOOLEAN, Opt.BOOTSTRAP); + SPLASH.setOptions(true, Opt.BOOLEAN, Opt.BOOTSTRAP); + NOQUESTIONNAIRE.setOptions(Opt.UNARY, Opt.BOOTSTRAP); // unary as + // --questionnaire=val + // expects a string value SORTBYTREE.setOptions(true, Opt.BOOLEAN); USAGESTATS.setOptions(true, Opt.BOOLEAN); OPEN.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB, Opt.ALLOWSUBSTITUTIONS); - OPEN2.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS); + OPENNEW.setOptions(Opt.STRING, Opt.MULTI, Opt.GLOB, + Opt.ALLOWSUBSTITUTIONS); PROPS.setOptions(Opt.STRING, Opt.BOOTSTRAP); QUESTIONNAIRE.setOptions(Opt.STRING); SETPROP.setOptions(Opt.STRING); diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index c6580a7..f22ca7f 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -49,6 +49,12 @@ public class ArgParser // the counter added to the default linked id prefix private int defaultLinkedIdCounter = 0; + // the linked id prefix used for --opennew files + protected static final String OPENNEWLINKEDIDPREFIX = "OPENNEW:"; + + // the counter added to the default linked id prefix + private int opennewLinkedIdCounter = 0; + // the linked id used to increment the idCounter (and use the incremented // value) private static final String INCREMENTAUTOCOUNTERLINKEDID = "{++n}"; @@ -115,26 +121,26 @@ public class ArgParser private void parse(List args) { int argIndex = 0; - boolean initialFilenameArgs = true; + boolean openEachInitialFilenames = true; for (int i = 0; i < args.size(); i++) { String arg = args.get(i); + Console.debug("##### Looking at arg '" + arg + "'"); + // If the first arguments do not start with "--" or "-" or is "open" and // is a filename that exists it is probably a file/list of files to open // so we fake an Arg.OPEN argument and when adding files only add the // single arg[i] and increment the defaultLinkedIdCounter so that each of // these files is opened separately. - if (initialFilenameArgs && !arg.startsWith(DOUBLEDASH) + if (openEachInitialFilenames && !arg.startsWith(DOUBLEDASH) && !arg.startsWith("-") && new File(arg).exists()) { - arg = DOUBLEDASH + Arg.OPEN.getName(); - Console.debug("Adding argument '" + args.get(i) - + "' as a file to be opened"); + arg = DOUBLEDASH + Arg.OPENNEW.getName(); } else { - initialFilenameArgs = false; + openEachInitialFilenames = false; } String argName = null; @@ -223,16 +229,8 @@ public class ArgParser { // if this is the first argument with a file list at the start of // the args we add filenames from index i instead of i+1 - // and assume they should be opened separately - if (initialFilenameArgs) - { - val = args.get(i); - defaultLinkedIdCounter++; - } - else - { - vals = getShellGlobbedFilenameValues(a, args, i + 1); - } + vals = getShellGlobbedFilenameValues(a, args, + openEachInitialFilenames ? i : i + 1); } else { @@ -261,7 +259,14 @@ public class ArgParser .append(Integer.toString(defaultLinkedIdCounter)) .toString(); boolean usingDefaultLinkedId = false; - if (a.hasOption(Opt.LINKED)) + if (a == Arg.OPENNEW) + { + linkedId = new StringBuilder(OPENNEWLINKEDIDPREFIX) + .append(Integer.toString(opennewLinkedIdCounter)) + .toString(); + opennewLinkedIdCounter++; + } + else if (a.hasOption(Opt.LINKED)) { if (linkedId == null) { @@ -319,13 +324,9 @@ public class ArgParser continue; } + boolean argIndexIncremented = false; ArgValues avs = avm.getOrCreateArgValues(a); - if (avs == null) - { - avs = new ArgValues(a); - } - boolean argIndexIncremented = false; // store appropriate value if (a.hasOption(Opt.STRING)) { @@ -358,9 +359,6 @@ public class ArgParser // store in appropriate place if (a.hasOption(Opt.LINKED)) { - // allow a default linked id for single usage - if (linkedId == null) - linkedId = defaultLinkedId; // store the order of linkedIds if (linkedOrder == null) linkedOrder = new ArrayList<>(); diff --git a/src/jalview/bin/argparser/ArgValue.java b/src/jalview/bin/argparser/ArgValue.java index 019e7c7..2aa32df 100644 --- a/src/jalview/bin/argparser/ArgValue.java +++ b/src/jalview/bin/argparser/ArgValue.java @@ -11,10 +11,13 @@ public class ArgValue private String id; + private SubVals subVals = null; + protected ArgValue(String value, int argIndex) { this.value = value; this.argIndex = argIndex; + this.subVals = ArgParser.getSubVals(getValue()); } public String getValue() @@ -39,6 +42,18 @@ public class ArgValue public SubVals getSubVals() { - return ArgParser.getSubVals(getValue()); + return subVals; + } + + public String getSubVal(String key) + { + if (subVals == null || !subVals.has(key)) + return null; + return subVals.get(key); + } + + protected void putSubVal(String key, String val) + { + this.subVals.put(key, val); } } \ No newline at end of file diff --git a/src/jalview/bin/argparser/BootstrapArgs.java b/src/jalview/bin/argparser/BootstrapArgs.java index bcb86f9..49e8686 100644 --- a/src/jalview/bin/argparser/BootstrapArgs.java +++ b/src/jalview/bin/argparser/BootstrapArgs.java @@ -22,10 +22,10 @@ public class BootstrapArgs private BootstrapArgs(List args) { - init(args); + parse(args); } - private void init(List args) + private void parse(List args) { if (args == null) return; @@ -36,15 +36,28 @@ public class BootstrapArgs String val = null; if (arg.startsWith(ArgParser.DOUBLEDASH)) { + // remove "--" + System.out.println("###### BOOTSTRAP: '" + arg + "'"); + arg = arg.substring(ArgParser.DOUBLEDASH.length()); int equalPos = arg.indexOf('='); - if (equalPos > -1) + if (equalPos > -1 + && ArgParser.argMap.containsKey(arg.substring(0, equalPos))) { - argName = arg.substring(ArgParser.DOUBLEDASH.length(), equalPos); + argName = arg.substring(0, equalPos); val = arg.substring(equalPos + 1); } - else + // check for boolean prepended by "no" + else if (arg.startsWith(ArgParser.NEGATESTRING) + && ArgParser.argMap.containsKey( + arg.substring(ArgParser.NEGATESTRING.length()))) + { + System.out.println("###### BOOTSTRAP IN NEGATESTRING"); + argName = arg.substring(ArgParser.NEGATESTRING.length()); + val = "false"; + } + else if (ArgParser.argMap.containsKey(arg)) { - argName = arg.substring(ArgParser.DOUBLEDASH.length()); + argName = arg; val = "true"; } @@ -73,6 +86,8 @@ public class BootstrapArgs } else { + System.err.println( + "###### Adding '" + a.getName() + "' with '" + val + "'"); add(a, val); } } @@ -140,4 +155,12 @@ public class BootstrapArgs List aL = bootstrapArgMap.get(a); return (aL == null || aL.size() == 0) ? null : aL.get(0); } + + public boolean getBoolean(Arg a) + { + if (!bootstrapArgMap.containsKey(a) + || !(a.hasOption(Opt.BOOLEAN) || a.hasOption(Opt.UNARY))) + return false; + return Boolean.parseBoolean(get(a)); + } } diff --git a/src/jalview/bin/argparser/SubVals.java b/src/jalview/bin/argparser/SubVals.java index 796c03d..e6a7cb2 100644 --- a/src/jalview/bin/argparser/SubVals.java +++ b/src/jalview/bin/argparser/SubVals.java @@ -47,7 +47,7 @@ public class SubVals { if (subVals == null) subVals = new HashMap<>(); - subVals.put(subvalString.substring(0, equals), + this.put(subvalString.substring(0, equals), subvalString.substring(equals + 1)); } else @@ -58,14 +58,16 @@ public class SubVals setIndex = true; } catch (NumberFormatException e) { - Console.warn("Failed to obtain subvalue or index from '" + item - + "'. Setting index=0 and using content='" + content - + "'."); + // store this non-numeric key as a "true" value + subVals.put(subvalsString, "true"); } } } if (!setIndex) this.index = NOTSET; + else + Console.debug("SubVals from '" + subvalsString + "' has index " + + this.index + " set"); } else { @@ -73,6 +75,13 @@ public class SubVals } } + protected void put(String key, String val) + { + if (subVals == null) + subVals = new HashMap<>(); + subVals.put(key, val); + } + public boolean notSet() { // notSet is true if content present but nonsensical diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 0197db7..cd62c9f 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -808,7 +808,7 @@ public class Desktop extends jalview.jbgui.GDesktop // TODO - write tests and fix AlignFrame.paste() which doesn't track if // clipboard has come from a different alignment window than the one where // paste has been called! JAL-4151 - + if (Desktop.jalviewClipboard != null) { // The clipboard was filled from within Jalview, we must use the @@ -835,30 +835,32 @@ public class Desktop extends jalview.jbgui.GDesktop } Desktop.addInternalFrame(af, newtitle, AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); + AlignFrame.DEFAULT_HEIGHT); - } else { - try + } + else { - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable contents = c.getContents(this); - - if (contents != null) + try { - String file = (String) contents - .getTransferData(DataFlavor.stringFlavor); + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents = c.getContents(this); - FileFormatI format = new IdentifyFile().identify(file, - DataSourceType.PASTE); + if (contents != null) + { + String file = (String) contents + .getTransferData(DataFlavor.stringFlavor); - new FileLoader().LoadFile(file, DataSourceType.PASTE, format); + FileFormatI format = new IdentifyFile().identify(file, + DataSourceType.PASTE); + new FileLoader().LoadFile(file, DataSourceType.PASTE, format); + + } + } catch (Exception ex) + { + System.out.println( + "Unable to paste alignment from system clipboard:\n" + ex); } - } catch (Exception ex) - { - System.out.println( - "Unable to paste alignment from system clipboard:\n" + ex); - } } } -- 1.7.10.2