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