update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / params / simple / Option.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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   ArrayList<String> possibleVals=new ArrayList<String>();
32   boolean required;
33   URL fdetails;
34   @Override
35   public String getName()
36   {
37     return name;
38   }
39
40   @Override
41   public String getValue()
42   {
43     return value==null ? defvalue : value;
44   }
45
46   @Override
47   public void setValue(String selectedItem)
48   {
49     value = selectedItem;
50   }
51
52   @Override
53   public URL getFurtherDetails()
54   {
55     return fdetails;
56   }
57
58   @Override
59   public boolean isRequired()
60   {
61     return required;
62   }
63
64   @Override
65   public String getDescription()
66   {
67     return description;
68   }
69
70   @Override
71   public List<String> getPossibleValues()
72   {
73     return possibleVals;
74   }
75   public Option(Option opt)
76   {
77     name = new String(opt.name);
78     if (opt.value!=null) 
79       value = new String(opt.value);
80     if (opt.defvalue!=null)
81       defvalue=new String(opt.defvalue);
82     if (opt.description!=null)
83       description=new String(opt.description);
84     if (opt.possibleVals!=null) {
85       possibleVals = (ArrayList<String>)opt.possibleVals.clone();
86     }
87     required = opt.required;
88     // URLs are singletons - so we copy by reference. nasty but true.
89     fdetails = opt.fdetails;
90   }
91   public Option()
92   {
93   }
94
95   public Option(String name2, String description2, boolean isrequired,
96           String defValue, String value, Collection<String> possibleVals, URL fdetails)
97   {
98     name = name2;
99     description = description2;
100     this.value = value;
101     this.required = isrequired;
102     this.defvalue = defValue;
103     if (possibleVals!=null)
104     {
105       this.possibleVals = new ArrayList<String>();
106       this.possibleVals.addAll(possibleVals);
107     }
108     this.fdetails = fdetails;
109   }
110
111
112   @Override
113   public OptionI copy()
114   {
115     Option opt = new Option(this);
116     return opt;
117   }
118 }