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