Update spike branch to latest
[jalview.git] / src / jalview / ws / params / simple / Option.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.params.simple;
22
23 import jalview.ws.params.OptionI;
24
25 import java.net.URL;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 public class Option implements OptionI
30 {
31   String name;
32
33   /*
34    * current value in string format, or "null" if undefined
35    */
36   String value;
37
38   /*
39    * default value in string format, or "null" if undefined
40    */
41   String defvalue;
42
43   String description;
44
45   List<String> possibleVals;
46
47   /*
48    * optional display names corresponding to possibleVals
49    */
50   List<String> displayVals;
51
52   boolean required;
53
54   URL fdetails;
55
56   /**
57    * Copy constructor
58    * 
59    * @param opt
60    */
61   public Option(Option opt)
62   {
63     name = opt.name;
64     value = opt.value;
65     defvalue = opt.defvalue;
66     description = opt.description;
67     if (opt.possibleVals != null)
68     {
69       possibleVals = new ArrayList<>(opt.possibleVals);
70     }
71     required = opt.required;
72     // URLs are singletons - so we copy by reference. nasty but true.
73     fdetails = opt.fdetails;
74   }
75
76   public Option()
77   {
78   }
79
80   /**
81    * Constructor including display names for possible values
82    * 
83    * @param name2
84    * @param description2
85    * @param isrequired
86    * @param defValue
87    * @param val
88    * @param possibleVals
89    * @param fdetails
90    */
91   public Option(String name2, String description2, boolean isrequired,
92           String defValue, String val, List<String> possibleVals,
93           List<String> displayNames, URL fdetails)
94   {
95     name = name2;
96     description = description2;
97     this.value = val;
98     this.required = isrequired;
99     this.defvalue = defValue;
100     if (possibleVals != null)
101     {
102       this.possibleVals = new ArrayList<>(possibleVals);
103     }
104     if (displayNames != null)
105     {
106       this.displayVals = new ArrayList<>(displayNames);
107     }
108     this.fdetails = fdetails;
109   }
110
111   /**
112    * Constructor
113    * 
114    * @param name2
115    * @param description2
116    * @param isrequired
117    * @param defValue
118    * @param val
119    * @param possibleVals
120    * @param fdetails
121    */
122   public Option(String name2, String description2, boolean isrequired,
123           String defValue, String val, List<String> possibleVals,
124           URL fdetails)
125   {
126     this(name2, description2, isrequired, defValue, val, possibleVals, null,
127             fdetails);
128   }
129
130   @Override
131   public OptionI copy()
132   {
133     Option opt = new Option(this);
134     return opt;
135   }
136
137   /**
138    * toString method to help identify options in the debugger only
139    */
140   @Override
141   public String toString()
142   {
143     return this.getClass().getName() + ":" + name;
144   }
145
146   @Override
147   public String getName()
148   {
149     return name;
150   }
151
152   @Override
153   public String getValue()
154   {
155     return value == null ? defvalue : value;
156   }
157
158   @Override
159   public void setValue(String selectedItem)
160   {
161     value = selectedItem;
162   }
163
164   @Override
165   public URL getFurtherDetails()
166   {
167     return fdetails;
168   }
169
170   @Override
171   public boolean isRequired()
172   {
173     return required;
174   }
175
176   @Override
177   public String getDescription()
178   {
179     return description;
180   }
181
182   @Override
183   public List<String> getPossibleValues()
184   {
185     return possibleVals;
186   }
187
188   @Override
189   public List<String> getDisplayNames()
190   {
191     return displayVals;
192   }
193 }