import java.io.File;
import java.io.IOException;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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;
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;
boolean first = true;
boolean progressBarSet = false;
AlignFrame af;
- for (ArgValue av : avm.getArgValueList(Arg.OPEN))
+ List<Entry<Arg, ArgValue>> openAvList = new ArrayList<>();
+ avm.getArgValueList(Arg.OPEN).stream()
+ .forEachOrdered(av -> openAvList.add(
+ new AbstractMap.SimpleEntry<Arg, ArgValue>(Arg.OPEN,
+ av)));
+ avm.getArgValueList(Arg.OPENNEW).stream()
+ .forEachOrdered(av -> openAvList
+ .add(new AbstractMap.SimpleEntry<Arg, ArgValue>(
+ Arg.OPENNEW, av)));
+ for (Entry<Arg, ArgValue> aav : openAvList)
{
+ Arg a = aav.getKey();
+ ArgValue av = aav.getValue();
String openFile = av.getValue();
if (openFile == null)
continue;
}
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
.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();
}
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
{
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);
// 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}";
private void parse(List<String> 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;
{
// 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
{
.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)
{
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))
{
// 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<>();
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()
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
private BootstrapArgs(List<String> args)
{
- init(args);
+ parse(args);
}
- private void init(List<String> args)
+ private void parse(List<String> args)
{
if (args == null)
return;
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";
}
}
else
{
+ System.err.println(
+ "###### Adding '" + a.getName() + "' with '" + val + "'");
add(a, val);
}
}
List<String> 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));
+ }
}
{
if (subVals == null)
subVals = new HashMap<>();
- subVals.put(subvalString.substring(0, equals),
+ this.put(subvalString.substring(0, equals),
subvalString.substring(equals + 1));
}
else
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
{
}
}
+ 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
// 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
}
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);
- }
}
}