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