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