01b470e62143e7a0cf4fb479200181fe14815543
[jalview.git] / src / jalview / ws / params / simple / Option.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.ws.params.simple;
19
20 import jalview.ws.params.OptionI;
21
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26
27 public class Option implements OptionI
28 {
29
30   String name, value, defvalue, description;
31
32   ArrayList<String> possibleVals = new ArrayList<String>();
33
34   boolean required;
35
36   URL fdetails;
37
38   @Override
39   public String getName()
40   {
41     return name;
42   }
43
44   @Override
45   public String getValue()
46   {
47     return value == null ? defvalue : value;
48   }
49
50   @Override
51   public void setValue(String selectedItem)
52   {
53     value = selectedItem;
54   }
55
56   @Override
57   public URL getFurtherDetails()
58   {
59     return fdetails;
60   }
61
62   @Override
63   public boolean isRequired()
64   {
65     return required;
66   }
67
68   @Override
69   public String getDescription()
70   {
71     return description;
72   }
73
74   @Override
75   public List<String> getPossibleValues()
76   {
77     return possibleVals;
78   }
79
80   public Option(Option opt)
81   {
82     name = new String(opt.name);
83     if (opt.value != null)
84       value = new String(opt.value);
85     if (opt.defvalue != null)
86       defvalue = new String(opt.defvalue);
87     if (opt.description != null)
88       description = new String(opt.description);
89     if (opt.possibleVals != null)
90     {
91       possibleVals = (ArrayList<String>) opt.possibleVals.clone();
92     }
93     required = opt.required;
94     // URLs are singletons - so we copy by reference. nasty but true.
95     fdetails = opt.fdetails;
96   }
97
98   public Option()
99   {
100   }
101
102   public Option(String name2, String description2, boolean isrequired,
103           String defValue, String value, Collection<String> possibleVals,
104           URL fdetails)
105   {
106     name = name2;
107     description = description2;
108     this.value = value;
109     this.required = isrequired;
110     this.defvalue = defValue;
111     if (possibleVals != null)
112     {
113       this.possibleVals = new ArrayList<String>();
114       this.possibleVals.addAll(possibleVals);
115     }
116     this.fdetails = fdetails;
117   }
118
119   @Override
120   public OptionI copy()
121   {
122     Option opt = new Option(this);
123     return opt;
124   }
125 }