+ protected static List<String> readArgFile(File argFile)
+ {
+ List<String> args = new ArrayList<>();
+ if (argFile != null && argFile.exists())
+ {
+ try
+ {
+ for (String line : Files.readAllLines(Paths.get(argFile.getPath())))
+ {
+ if (line != null && line.length() > 0
+ && line.charAt(0) != ARGFILECOMMENT)
+ args.add(line);
+ }
+ } catch (IOException e)
+ {
+ String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
+ + "\": File could not be read.";
+ Console.debug(message, e);
+ Jalview.exit(message, 3);
+ }
+ }
+ return args;
+ }
+
+ public static enum Position
+ {
+ FIRST, BEFORE, AFTER
+ }
+
+ public static String getValueFromSubValOrArg(ArgValuesMap avm, Arg a,
+ SubVals sv)
+ {
+ return getFromSubValArgOrPref(avm, a, sv, null, null, null);
+ }
+
+ public static String getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ SubVals sv, String key, String pref, String def)
+ {
+ return getFromSubValArgOrPref(avm, a, Position.FIRST, null, sv, key,
+ pref, def);
+ }
+
+ public static String getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ Position pos, ArgValue av, SubVals sv, String key, String pref,
+ String def)
+ {
+ if (key == null)
+ key = a.getName();
+ if (sv != null && sv.has(key) && sv.get(key) != null)
+ return sv.get(key);
+ if (avm != null && avm.containsArg(a))
+ {
+ String val = null;
+ if (pos == Position.FIRST && avm.getValue(a) != null)
+ return avm.getValue(a);
+ else if (pos == Position.BEFORE
+ && avm.getClosestPreviousArgValueOfArg(av, a) != null)
+ return avm.getClosestPreviousArgValueOfArg(av, a).getValue();
+ else if (pos == Position.AFTER
+ && avm.getClosestNextArgValueOfArg(av, a) != null)
+ return avm.getClosestNextArgValueOfArg(av, a).getValue();
+ }
+ return pref != null ? Cache.getDefault(pref, def) : def;
+ }
+
+ public static boolean getBoolFromSubValOrArg(ArgValuesMap avm, Arg a,
+ SubVals sv)
+ {
+ return getFromSubValArgOrPref(avm, a, sv, null, null, false);
+ }
+
+ public static boolean getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ SubVals sv, String key, String pref, boolean def)
+ {
+ if (key == null)
+ key = a.getName();
+ if (sv != null && sv.has(key) && sv.get(key) != null)
+ return sv.get(key).toLowerCase(Locale.ROOT).equals("true");
+ if (avm != null && avm.containsArg(a))
+ return avm.getBoolean(a);
+ return pref != null ? Cache.getDefault(pref, def) : def;
+ }
+