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