X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fparams%2Fsimple%2FOption.java;h=40e38048628da416f3c506fd9c2acd0722999f8e;hb=d02166c8801f0005ac9c1fbffdf0c26c7ca912aa;hp=8f6ebb4c02ed6e56e5bbb21c97ca1a9ae87f44d3;hpb=b57a02c25e335d033c97f8a6bacd6b54f62bd2b6;p=jalview.git diff --git a/src/jalview/ws/params/simple/Option.java b/src/jalview/ws/params/simple/Option.java index 8f6ebb4..40e3804 100644 --- a/src/jalview/ws/params/simple/Option.java +++ b/src/jalview/ws/params/simple/Option.java @@ -1,40 +1,158 @@ -/******************************************************************************* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) - * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle - * +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * * This file is part of Jalview. - * + * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . - *******************************************************************************/ + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.ws.params.simple; import jalview.ws.params.OptionI; import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.List; public class Option implements OptionI { + String name; - String name, value, defvalue, description; + String label; - ArrayList possibleVals = new ArrayList(); + /* + * current value in string format, or "null" if undefined + */ + String value; + + /* + * default value in string format, or "null" if undefined + */ + String defvalue; + + String description; + + List possibleVals; + + /* + * optional display names corresponding to possibleVals + */ + List displayVals; boolean required; URL fdetails; + /** + * Copy constructor + * + * @param opt + */ + public Option(Option opt) + { + name = opt.name; + label = opt.label; + value = opt.value; + defvalue = opt.defvalue; + description = opt.description; + if (opt.possibleVals != null) + { + possibleVals = new ArrayList<>(opt.possibleVals); + } + required = opt.required; + // URLs are singletons - so we copy by reference. nasty but true. + fdetails = opt.fdetails; + } + + public Option() + { + } + + public Option(String name, String description, String label, boolean isrequired, + String defValue, String val, List possibleVals, URL fdetails) + { + this(name, description, isrequired, defValue, val, possibleVals, fdetails); + this.label = label; + } + + /** + * Constructor including display names for possible values + * + * @param name2 + * @param description2 + * @param isrequired + * @param defValue + * @param val + * @param possibleVals + * @param fdetails + */ + public Option(String name2, String description2, boolean isrequired, + String defValue, String val, List possibleVals, + List displayNames, URL fdetails) + { + name = name2; + description = description2; + this.value = val; + this.required = isrequired; + this.defvalue = defValue; + if (possibleVals != null) + { + this.possibleVals = new ArrayList<>(possibleVals); + } + if (displayNames != null) + { + this.displayVals = new ArrayList<>(displayNames); + } + this.fdetails = fdetails; + } + + /** + * Constructor + * + * @param name2 + * @param description2 + * @param isrequired + * @param defValue + * @param val + * @param possibleVals + * @param fdetails + */ + public Option(String name2, String description2, boolean isrequired, + String defValue, String val, List possibleVals, + URL fdetails) + { + this(name2, description2, isrequired, defValue, val, possibleVals, null, + fdetails); + } + + @Override + public OptionI copy() + { + Option opt = new Option(this); + return opt; + } + + /** + * toString method to help identify options in the debugger only + */ + @Override + public String toString() + { + return this.getClass().getName() + ":" + name; + } + @Override public String getName() { @@ -42,6 +160,12 @@ public class Option implements OptionI } @Override + public String getLabel() + { + return label != null ? label : name; + } + + @Override public String getValue() { return value == null ? defvalue : value; @@ -77,49 +201,9 @@ public class Option implements OptionI return possibleVals; } - public Option(Option opt) - { - name = new String(opt.name); - if (opt.value != null) - value = new String(opt.value); - if (opt.defvalue != null) - defvalue = new String(opt.defvalue); - if (opt.description != null) - description = new String(opt.description); - if (opt.possibleVals != null) - { - possibleVals = (ArrayList) opt.possibleVals.clone(); - } - required = opt.required; - // URLs are singletons - so we copy by reference. nasty but true. - fdetails = opt.fdetails; - } - - public Option() - { - } - - public Option(String name2, String description2, boolean isrequired, - String defValue, String value, Collection possibleVals, - URL fdetails) - { - name = name2; - description = description2; - this.value = value; - this.required = isrequired; - this.defvalue = defValue; - if (possibleVals != null) - { - this.possibleVals = new ArrayList(); - this.possibleVals.addAll(possibleVals); - } - this.fdetails = fdetails; - } - @Override - public OptionI copy() + public List getDisplayNames() { - Option opt = new Option(this); - return opt; + return displayVals; } -} \ No newline at end of file +}