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