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