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