extended Colour element with additional optional attributes for graduated colour
[jalview.git] / src / jalview / schemabinding / version2 / JalviewUserColours.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer (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      * Jalview colour scheme document version.\r
47      *  \r
48      */\r
49     private java.lang.String _version;\r
50 \r
51     /**\r
52      * Field _colourList.\r
53      */\r
54     private java.util.Vector _colourList;\r
55 \r
56 \r
57       //----------------/\r
58      //- Constructors -/\r
59     //----------------/\r
60 \r
61     public JalviewUserColours() {\r
62         super();\r
63         this._colourList = new java.util.Vector();\r
64     }\r
65 \r
66 \r
67       //-----------/\r
68      //- Methods -/\r
69     //-----------/\r
70 \r
71     /**\r
72      * \r
73      * \r
74      * @param vColour\r
75      * @throws java.lang.IndexOutOfBoundsException if the index\r
76      * given is outside the bounds of the collection\r
77      */\r
78     public void addColour(\r
79             final Colour vColour)\r
80     throws java.lang.IndexOutOfBoundsException {\r
81         this._colourList.addElement(vColour);\r
82     }\r
83 \r
84     /**\r
85      * \r
86      * \r
87      * @param index\r
88      * @param vColour\r
89      * @throws java.lang.IndexOutOfBoundsException if the index\r
90      * given is outside the bounds of the collection\r
91      */\r
92     public void addColour(\r
93             final int index,\r
94             final Colour vColour)\r
95     throws java.lang.IndexOutOfBoundsException {\r
96         this._colourList.add(index, vColour);\r
97     }\r
98 \r
99     /**\r
100      * Method enumerateColour.\r
101      * \r
102      * @return an Enumeration over all Colour elements\r
103      */\r
104     public java.util.Enumeration enumerateColour(\r
105     ) {\r
106         return this._colourList.elements();\r
107     }\r
108 \r
109     /**\r
110      * Method getColour.\r
111      * \r
112      * @param index\r
113      * @throws java.lang.IndexOutOfBoundsException if the index\r
114      * given is outside the bounds of the collection\r
115      * @return the value of the Colour at the given index\r
116      */\r
117     public Colour getColour(\r
118             final int index)\r
119     throws java.lang.IndexOutOfBoundsException {\r
120         // check bounds for index\r
121         if (index < 0 || index >= this._colourList.size()) {\r
122             throw new IndexOutOfBoundsException("getColour: Index value '" + index + "' not in range [0.." + (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\r
130      * an Array.  <p>Note:  Just in case the collection contents\r
131      * are changing in another thread, we pass a 0-length Array of\r
132      * the correct type into the API call.  This way we <i>know</i>\r
133      * 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'\r
165      * has the following description: Jalview colour scheme\r
166      * document version.\r
167      *  \r
168      * \r
169      * @return the value of field 'Version'.\r
170      */\r
171     public java.lang.String getVersion(\r
172     ) {\r
173         return this._version;\r
174     }\r
175 \r
176     /**\r
177      * Method isValid.\r
178      * \r
179      * @return true if this object is valid according to the schema\r
180      */\r
181     public boolean isValid(\r
182     ) {\r
183         try {\r
184             validate();\r
185         } catch (org.exolab.castor.xml.ValidationException vex) {\r
186             return false;\r
187         }\r
188         return true;\r
189     }\r
190 \r
191     /**\r
192      * \r
193      * \r
194      * @param out\r
195      * @throws org.exolab.castor.xml.MarshalException if object is\r
196      * null or if any SAXException is thrown during marshaling\r
197      * @throws org.exolab.castor.xml.ValidationException if this\r
198      * object is an invalid instance according to the schema\r
199      */\r
200     public void marshal(\r
201             final java.io.Writer out)\r
202     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
203         Marshaller.marshal(this, out);\r
204     }\r
205 \r
206     /**\r
207      * \r
208      * \r
209      * @param handler\r
210      * @throws java.io.IOException if an IOException occurs during\r
211      * marshaling\r
212      * @throws org.exolab.castor.xml.ValidationException if this\r
213      * object is an invalid instance according to the schema\r
214      * @throws org.exolab.castor.xml.MarshalException if object is\r
215      * null or if any SAXException is thrown during marshaling\r
216      */\r
217     public void marshal(\r
218             final org.xml.sax.ContentHandler handler)\r
219     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
220         Marshaller.marshal(this, handler);\r
221     }\r
222 \r
223     /**\r
224      */\r
225     public void removeAllColour(\r
226     ) {\r
227         this._colourList.clear();\r
228     }\r
229 \r
230     /**\r
231      * Method removeColour.\r
232      * \r
233      * @param vColour\r
234      * @return true if the object was removed from the collection.\r
235      */\r
236     public boolean removeColour(\r
237             final Colour vColour) {\r
238         boolean removed = _colourList.remove(vColour);\r
239         return removed;\r
240     }\r
241 \r
242     /**\r
243      * Method removeColourAt.\r
244      * \r
245      * @param index\r
246      * @return the element removed from the collection\r
247      */\r
248     public Colour removeColourAt(\r
249             final int index) {\r
250         java.lang.Object obj = this._colourList.remove(index);\r
251         return (Colour) obj;\r
252     }\r
253 \r
254     /**\r
255      * \r
256      * \r
257      * @param index\r
258      * @param vColour\r
259      * @throws java.lang.IndexOutOfBoundsException if the index\r
260      * given is outside the bounds of the collection\r
261      */\r
262     public void setColour(\r
263             final int index,\r
264             final Colour vColour)\r
265     throws java.lang.IndexOutOfBoundsException {\r
266         // check bounds for index\r
267         if (index < 0 || index >= this._colourList.size()) {\r
268             throw new IndexOutOfBoundsException("setColour: Index value '" + index + "' not in range [0.." + (this._colourList.size() - 1) + "]");\r
269         }\r
270         \r
271         this._colourList.set(index, vColour);\r
272     }\r
273 \r
274     /**\r
275      * \r
276      * \r
277      * @param vColourArray\r
278      */\r
279     public void setColour(\r
280             final Colour[] vColourArray) {\r
281         //-- copy array\r
282         _colourList.clear();\r
283         \r
284         for (int i = 0; i < vColourArray.length; i++) {\r
285                 this._colourList.add(vColourArray[i]);\r
286         }\r
287     }\r
288 \r
289     /**\r
290      * Sets the value of field 'schemeName'.\r
291      * \r
292      * @param schemeName the value of field 'schemeName'.\r
293      */\r
294     public void setSchemeName(\r
295             final java.lang.String schemeName) {\r
296         this._schemeName = schemeName;\r
297     }\r
298 \r
299     /**\r
300      * Sets the value of field 'version'. The field 'version' has\r
301      * the following description: Jalview colour scheme document\r
302      * version.\r
303      *  \r
304      * \r
305      * @param version the value of field 'version'.\r
306      */\r
307     public void setVersion(\r
308             final java.lang.String version) {\r
309         this._version = version;\r
310     }\r
311 \r
312     /**\r
313      * Method unmarshal.\r
314      * \r
315      * @param reader\r
316      * @throws org.exolab.castor.xml.MarshalException if object is\r
317      * null or if any SAXException is thrown during marshaling\r
318      * @throws org.exolab.castor.xml.ValidationException if this\r
319      * object is an invalid instance according to the schema\r
320      * @return the unmarshaled\r
321      * jalview.schemabinding.version2.JalviewUserColours\r
322      */\r
323     public static jalview.schemabinding.version2.JalviewUserColours unmarshal(\r
324             final java.io.Reader reader)\r
325     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
326         return (jalview.schemabinding.version2.JalviewUserColours) Unmarshaller.unmarshal(jalview.schemabinding.version2.JalviewUserColours.class, reader);\r
327     }\r
328 \r
329     /**\r
330      * \r
331      * \r
332      * @throws org.exolab.castor.xml.ValidationException if this\r
333      * object is an invalid instance according to the schema\r
334      */\r
335     public void validate(\r
336     )\r
337     throws org.exolab.castor.xml.ValidationException {\r
338         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
339         validator.validate(this);\r
340     }\r
341 \r
342 }\r