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