JAL-1503 update version in GPL header
[jalview.git] / src / jalview / binding / FeatureSettings.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3  * Copyright (C) 2014 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 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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.binding;
20
21 //---------------------------------/
22 //- Imported classes and packages -/
23 //---------------------------------/
24
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
27
28 /**
29  * Class FeatureSettings.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class FeatureSettings implements java.io.Serializable
34 {
35
36   // --------------------------/
37   // - Class/Member Variables -/
38   // --------------------------/
39
40   /**
41    * Field _settingList.
42    */
43   private java.util.Vector _settingList;
44
45   // ----------------/
46   // - Constructors -/
47   // ----------------/
48
49   public FeatureSettings()
50   {
51     super();
52     this._settingList = new java.util.Vector();
53   }
54
55   // -----------/
56   // - Methods -/
57   // -----------/
58
59   /**
60    * 
61    * 
62    * @param vSetting
63    * @throws java.lang.IndexOutOfBoundsException
64    *           if the index given is outside the bounds of the collection
65    */
66   public void addSetting(final jalview.binding.Setting vSetting)
67           throws java.lang.IndexOutOfBoundsException
68   {
69     this._settingList.addElement(vSetting);
70   }
71
72   /**
73    * 
74    * 
75    * @param index
76    * @param vSetting
77    * @throws java.lang.IndexOutOfBoundsException
78    *           if the index given is outside the bounds of the collection
79    */
80   public void addSetting(final int index,
81           final jalview.binding.Setting vSetting)
82           throws java.lang.IndexOutOfBoundsException
83   {
84     this._settingList.add(index, vSetting);
85   }
86
87   /**
88    * Method enumerateSetting.
89    * 
90    * @return an Enumeration over all jalview.binding.Setting elements
91    */
92   public java.util.Enumeration enumerateSetting()
93   {
94     return this._settingList.elements();
95   }
96
97   /**
98    * Method getSetting.
99    * 
100    * @param index
101    * @throws java.lang.IndexOutOfBoundsException
102    *           if the index given is outside the bounds of the collection
103    * @return the value of the jalview.binding.Setting at the given index
104    */
105   public jalview.binding.Setting getSetting(final int index)
106           throws java.lang.IndexOutOfBoundsException
107   {
108     // check bounds for index
109     if (index < 0 || index >= this._settingList.size())
110     {
111       throw new IndexOutOfBoundsException("getSetting: Index value '"
112               + index + "' not in range [0.."
113               + (this._settingList.size() - 1) + "]");
114     }
115
116     return (jalview.binding.Setting) _settingList.get(index);
117   }
118
119   /**
120    * Method getSetting.Returns the contents of the collection in an Array.
121    * <p>
122    * Note: Just in case the collection contents are changing in another thread,
123    * we pass a 0-length Array of the correct type into the API call. This way we
124    * <i>know</i> that the Array returned is of exactly the correct length.
125    * 
126    * @return this collection as an Array
127    */
128   public jalview.binding.Setting[] getSetting()
129   {
130     jalview.binding.Setting[] array = new jalview.binding.Setting[0];
131     return (jalview.binding.Setting[]) this._settingList.toArray(array);
132   }
133
134   /**
135    * Method getSettingCount.
136    * 
137    * @return the size of this collection
138    */
139   public int getSettingCount()
140   {
141     return this._settingList.size();
142   }
143
144   /**
145    * Method isValid.
146    * 
147    * @return true if this object is valid according to the schema
148    */
149   public boolean isValid()
150   {
151     try
152     {
153       validate();
154     } catch (org.exolab.castor.xml.ValidationException vex)
155     {
156       return false;
157     }
158     return true;
159   }
160
161   /**
162    * 
163    * 
164    * @param out
165    * @throws org.exolab.castor.xml.MarshalException
166    *           if object is null or if any SAXException is thrown during
167    *           marshaling
168    * @throws org.exolab.castor.xml.ValidationException
169    *           if this object is an invalid instance according to the schema
170    */
171   public void marshal(final java.io.Writer out)
172           throws org.exolab.castor.xml.MarshalException,
173           org.exolab.castor.xml.ValidationException
174   {
175     Marshaller.marshal(this, out);
176   }
177
178   /**
179    * 
180    * 
181    * @param handler
182    * @throws java.io.IOException
183    *           if an IOException occurs during marshaling
184    * @throws org.exolab.castor.xml.ValidationException
185    *           if this object is an invalid instance according to the schema
186    * @throws org.exolab.castor.xml.MarshalException
187    *           if object is null or if any SAXException is thrown during
188    *           marshaling
189    */
190   public void marshal(final org.xml.sax.ContentHandler handler)
191           throws java.io.IOException,
192           org.exolab.castor.xml.MarshalException,
193           org.exolab.castor.xml.ValidationException
194   {
195     Marshaller.marshal(this, handler);
196   }
197
198   /**
199      */
200   public void removeAllSetting()
201   {
202     this._settingList.clear();
203   }
204
205   /**
206    * Method removeSetting.
207    * 
208    * @param vSetting
209    * @return true if the object was removed from the collection.
210    */
211   public boolean removeSetting(final jalview.binding.Setting vSetting)
212   {
213     boolean removed = _settingList.remove(vSetting);
214     return removed;
215   }
216
217   /**
218    * Method removeSettingAt.
219    * 
220    * @param index
221    * @return the element removed from the collection
222    */
223   public jalview.binding.Setting removeSettingAt(final int index)
224   {
225     java.lang.Object obj = this._settingList.remove(index);
226     return (jalview.binding.Setting) obj;
227   }
228
229   /**
230    * 
231    * 
232    * @param index
233    * @param vSetting
234    * @throws java.lang.IndexOutOfBoundsException
235    *           if the index given is outside the bounds of the collection
236    */
237   public void setSetting(final int index,
238           final jalview.binding.Setting vSetting)
239           throws java.lang.IndexOutOfBoundsException
240   {
241     // check bounds for index
242     if (index < 0 || index >= this._settingList.size())
243     {
244       throw new IndexOutOfBoundsException("setSetting: Index value '"
245               + index + "' not in range [0.."
246               + (this._settingList.size() - 1) + "]");
247     }
248
249     this._settingList.set(index, vSetting);
250   }
251
252   /**
253    * 
254    * 
255    * @param vSettingArray
256    */
257   public void setSetting(final jalview.binding.Setting[] vSettingArray)
258   {
259     // -- copy array
260     _settingList.clear();
261
262     for (int i = 0; i < vSettingArray.length; i++)
263     {
264       this._settingList.add(vSettingArray[i]);
265     }
266   }
267
268   /**
269    * Method unmarshal.
270    * 
271    * @param reader
272    * @throws org.exolab.castor.xml.MarshalException
273    *           if object is null or if any SAXException is thrown during
274    *           marshaling
275    * @throws org.exolab.castor.xml.ValidationException
276    *           if this object is an invalid instance according to the schema
277    * @return the unmarshaled jalview.binding.FeatureSettings
278    */
279   public static jalview.binding.FeatureSettings unmarshal(
280           final java.io.Reader reader)
281           throws org.exolab.castor.xml.MarshalException,
282           org.exolab.castor.xml.ValidationException
283   {
284     return (jalview.binding.FeatureSettings) Unmarshaller.unmarshal(
285             jalview.binding.FeatureSettings.class, reader);
286   }
287
288   /**
289    * 
290    * 
291    * @throws org.exolab.castor.xml.ValidationException
292    *           if this object is an invalid instance according to the schema
293    */
294   public void validate() throws org.exolab.castor.xml.ValidationException
295   {
296     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
297     validator.validate(this);
298   }
299
300 }