Jalview 2.6 source licence
[jalview.git] / src / jalview / schemabinding / version2 / JalviewUserColours.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)\r
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
4  * \r
5  * This file is part of Jalview.\r
6  * \r
7  * Jalview is free software: you can redistribute it and/or\r
8  * modify it under the terms of the GNU General Public License \r
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
10  * \r
11  * Jalview is distributed in the hope that it will be useful, but \r
12  * WITHOUT ANY WARRANTY; without even the implied warranty \r
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
14  * PURPOSE.  See the GNU General Public License for more details.\r
15  * \r
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
17  */\r
18 package jalview.schemabinding.version2;\r
19 \r
20 //---------------------------------/\r
21 //- Imported classes and packages -/\r
22 //---------------------------------/\r
23 \r
24 import org.exolab.castor.xml.Marshaller;\r
25 import org.exolab.castor.xml.Unmarshaller;\r
26 \r
27 /**\r
28  * Class JalviewUserColours.\r
29  * \r
30  * @version $Revision$ $Date$\r
31  */\r
32 public class JalviewUserColours implements java.io.Serializable\r
33 {\r
34 \r
35   // --------------------------/\r
36   // - Class/Member Variables -/\r
37   // --------------------------/\r
38 \r
39   /**\r
40    * Field _schemeName.\r
41    */\r
42   private java.lang.String _schemeName;\r
43 \r
44   /**\r
45    * Jalview colour scheme document version.\r
46    * \r
47    */\r
48   private java.lang.String _version;\r
49 \r
50   /**\r
51    * Field _colourList.\r
52    */\r
53   private java.util.Vector _colourList;\r
54 \r
55   // ----------------/\r
56   // - Constructors -/\r
57   // ----------------/\r
58 \r
59   public JalviewUserColours()\r
60   {\r
61     super();\r
62     this._colourList = new java.util.Vector();\r
63   }\r
64 \r
65   // -----------/\r
66   // - Methods -/\r
67   // -----------/\r
68 \r
69   /**\r
70    * \r
71    * \r
72    * @param vColour\r
73    * @throws java.lang.IndexOutOfBoundsException\r
74    *           if the index given is outside the bounds of the collection\r
75    */\r
76   public void addColour(final Colour vColour)\r
77           throws java.lang.IndexOutOfBoundsException\r
78   {\r
79     this._colourList.addElement(vColour);\r
80   }\r
81 \r
82   /**\r
83    * \r
84    * \r
85    * @param index\r
86    * @param vColour\r
87    * @throws java.lang.IndexOutOfBoundsException\r
88    *           if the index given is outside the bounds of the collection\r
89    */\r
90   public void addColour(final int index, final Colour vColour)\r
91           throws java.lang.IndexOutOfBoundsException\r
92   {\r
93     this._colourList.add(index, vColour);\r
94   }\r
95 \r
96   /**\r
97    * Method enumerateColour.\r
98    * \r
99    * @return an Enumeration over all Colour elements\r
100    */\r
101   public java.util.Enumeration enumerateColour()\r
102   {\r
103     return this._colourList.elements();\r
104   }\r
105 \r
106   /**\r
107    * Method getColour.\r
108    * \r
109    * @param index\r
110    * @throws java.lang.IndexOutOfBoundsException\r
111    *           if the index given is outside the bounds of the collection\r
112    * @return the value of the Colour at the given index\r
113    */\r
114   public Colour getColour(final int index)\r
115           throws java.lang.IndexOutOfBoundsException\r
116   {\r
117     // check bounds for index\r
118     if (index < 0 || index >= this._colourList.size())\r
119     {\r
120       throw new IndexOutOfBoundsException("getColour: Index value '"\r
121               + index + "' not in range [0.."\r
122               + (this._colourList.size() - 1) + "]");\r
123     }\r
124 \r
125     return (Colour) _colourList.get(index);\r
126   }\r
127 \r
128   /**\r
129    * Method getColour.Returns the contents of the collection in an Array.\r
130    * <p>\r
131    * Note: Just in case the collection contents are changing in another thread,\r
132    * we pass a 0-length Array of the correct type into the API call. This way we\r
133    * <i>know</i> that the Array returned is of exactly the correct length.\r
134    * \r
135    * @return this collection as an Array\r
136    */\r
137   public Colour[] getColour()\r
138   {\r
139     Colour[] array = new Colour[0];\r
140     return (Colour[]) this._colourList.toArray(array);\r
141   }\r
142 \r
143   /**\r
144    * Method getColourCount.\r
145    * \r
146    * @return the size of this collection\r
147    */\r
148   public int getColourCount()\r
149   {\r
150     return this._colourList.size();\r
151   }\r
152 \r
153   /**\r
154    * Returns the value of field 'schemeName'.\r
155    * \r
156    * @return the value of field 'SchemeName'.\r
157    */\r
158   public java.lang.String getSchemeName()\r
159   {\r
160     return this._schemeName;\r
161   }\r
162 \r
163   /**\r
164    * Returns the value of field 'version'. The field 'version' has the following\r
165    * description: Jalview colour scheme document version.\r
166    * \r
167    * \r
168    * @return the value of field 'Version'.\r
169    */\r
170   public java.lang.String getVersion()\r
171   {\r
172     return this._version;\r
173   }\r
174 \r
175   /**\r
176    * Method isValid.\r
177    * \r
178    * @return true if this object is valid according to the schema\r
179    */\r
180   public boolean isValid()\r
181   {\r
182     try\r
183     {\r
184       validate();\r
185     } catch (org.exolab.castor.xml.ValidationException vex)\r
186     {\r
187       return false;\r
188     }\r
189     return true;\r
190   }\r
191 \r
192   /**\r
193    * \r
194    * \r
195    * @param out\r
196    * @throws org.exolab.castor.xml.MarshalException\r
197    *           if object is null or if any SAXException is thrown during\r
198    *           marshaling\r
199    * @throws org.exolab.castor.xml.ValidationException\r
200    *           if this object is an invalid instance according to the schema\r
201    */\r
202   public void marshal(final java.io.Writer out)\r
203           throws org.exolab.castor.xml.MarshalException,\r
204           org.exolab.castor.xml.ValidationException\r
205   {\r
206     Marshaller.marshal(this, out);\r
207   }\r
208 \r
209   /**\r
210    * \r
211    * \r
212    * @param handler\r
213    * @throws java.io.IOException\r
214    *           if an IOException occurs during marshaling\r
215    * @throws org.exolab.castor.xml.ValidationException\r
216    *           if this object is an invalid instance according to the schema\r
217    * @throws org.exolab.castor.xml.MarshalException\r
218    *           if object is null or if any SAXException is thrown during\r
219    *           marshaling\r
220    */\r
221   public void marshal(final org.xml.sax.ContentHandler handler)\r
222           throws java.io.IOException,\r
223           org.exolab.castor.xml.MarshalException,\r
224           org.exolab.castor.xml.ValidationException\r
225   {\r
226     Marshaller.marshal(this, handler);\r
227   }\r
228 \r
229   /**\r
230      */\r
231   public void removeAllColour()\r
232   {\r
233     this._colourList.clear();\r
234   }\r
235 \r
236   /**\r
237    * Method removeColour.\r
238    * \r
239    * @param vColour\r
240    * @return true if the object was removed from the collection.\r
241    */\r
242   public boolean removeColour(final Colour vColour)\r
243   {\r
244     boolean removed = _colourList.remove(vColour);\r
245     return removed;\r
246   }\r
247 \r
248   /**\r
249    * Method removeColourAt.\r
250    * \r
251    * @param index\r
252    * @return the element removed from the collection\r
253    */\r
254   public Colour removeColourAt(final int index)\r
255   {\r
256     java.lang.Object obj = this._colourList.remove(index);\r
257     return (Colour) obj;\r
258   }\r
259 \r
260   /**\r
261    * \r
262    * \r
263    * @param index\r
264    * @param vColour\r
265    * @throws java.lang.IndexOutOfBoundsException\r
266    *           if the index given is outside the bounds of the collection\r
267    */\r
268   public void setColour(final int index, final Colour vColour)\r
269           throws java.lang.IndexOutOfBoundsException\r
270   {\r
271     // check bounds for index\r
272     if (index < 0 || index >= this._colourList.size())\r
273     {\r
274       throw new IndexOutOfBoundsException("setColour: Index value '"\r
275               + index + "' not in range [0.."\r
276               + (this._colourList.size() - 1) + "]");\r
277     }\r
278 \r
279     this._colourList.set(index, vColour);\r
280   }\r
281 \r
282   /**\r
283    * \r
284    * \r
285    * @param vColourArray\r
286    */\r
287   public void setColour(final Colour[] vColourArray)\r
288   {\r
289     // -- copy array\r
290     _colourList.clear();\r
291 \r
292     for (int i = 0; i < vColourArray.length; i++)\r
293     {\r
294       this._colourList.add(vColourArray[i]);\r
295     }\r
296   }\r
297 \r
298   /**\r
299    * Sets the value of field 'schemeName'.\r
300    * \r
301    * @param schemeName\r
302    *          the value of field 'schemeName'.\r
303    */\r
304   public void setSchemeName(final java.lang.String schemeName)\r
305   {\r
306     this._schemeName = schemeName;\r
307   }\r
308 \r
309   /**\r
310    * Sets the value of field 'version'. The field 'version' has the following\r
311    * description: Jalview colour scheme document version.\r
312    * \r
313    * \r
314    * @param version\r
315    *          the value of field 'version'.\r
316    */\r
317   public void setVersion(final java.lang.String version)\r
318   {\r
319     this._version = version;\r
320   }\r
321 \r
322   /**\r
323    * Method unmarshal.\r
324    * \r
325    * @param reader\r
326    * @throws org.exolab.castor.xml.MarshalException\r
327    *           if object is null or if any SAXException is thrown during\r
328    *           marshaling\r
329    * @throws org.exolab.castor.xml.ValidationException\r
330    *           if this object is an invalid instance according to the schema\r
331    * @return the unmarshaled jalview.schemabinding.version2.JalviewUserColours\r
332    */\r
333   public static jalview.schemabinding.version2.JalviewUserColours unmarshal(\r
334           final java.io.Reader reader)\r
335           throws org.exolab.castor.xml.MarshalException,\r
336           org.exolab.castor.xml.ValidationException\r
337   {\r
338     return (jalview.schemabinding.version2.JalviewUserColours) Unmarshaller\r
339             .unmarshal(\r
340                     jalview.schemabinding.version2.JalviewUserColours.class,\r
341                     reader);\r
342   }\r
343 \r
344   /**\r
345    * \r
346    * \r
347    * @throws org.exolab.castor.xml.ValidationException\r
348    *           if this object is an invalid instance according to the schema\r
349    */\r
350   public void validate() throws org.exolab.castor.xml.ValidationException\r
351   {\r
352     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
353     validator.validate(this);\r
354   }\r
355 \r
356 }\r