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