2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
19 package jalview.schemabinding.version2;
21 //---------------------------------/
22 //- Imported classes and packages -/
23 //---------------------------------/
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
29 * Class JalviewUserColours.
31 * @version $Revision$ $Date$
33 public class JalviewUserColours implements java.io.Serializable
36 // --------------------------/
37 // - Class/Member Variables -/
38 // --------------------------/
43 private java.lang.String _schemeName;
46 * Jalview colour scheme document version.
49 private java.lang.String _version;
54 private java.util.Vector _colourList;
60 public JalviewUserColours()
63 this._colourList = new java.util.Vector();
74 * @throws java.lang.IndexOutOfBoundsException
75 * if the index given is outside the bounds of the collection
77 public void addColour(final Colour vColour)
78 throws java.lang.IndexOutOfBoundsException
80 this._colourList.addElement(vColour);
88 * @throws java.lang.IndexOutOfBoundsException
89 * if the index given is outside the bounds of the collection
91 public void addColour(final int index, final Colour vColour)
92 throws java.lang.IndexOutOfBoundsException
94 this._colourList.add(index, vColour);
98 * Method enumerateColour.
100 * @return an Enumeration over all Colour elements
102 public java.util.Enumeration enumerateColour()
104 return this._colourList.elements();
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
115 public Colour getColour(final int index)
116 throws java.lang.IndexOutOfBoundsException
118 // check bounds for index
119 if (index < 0 || index >= this._colourList.size())
121 throw new IndexOutOfBoundsException("getColour: Index value '"
122 + index + "' not in range [0.."
123 + (this._colourList.size() - 1) + "]");
126 return (Colour) _colourList.get(index);
130 * Method getColour.Returns the contents of the collection in an Array.
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.
136 * @return this collection as an Array
138 public Colour[] getColour()
140 Colour[] array = new Colour[0];
141 return (Colour[]) this._colourList.toArray(array);
145 * Method getColourCount.
147 * @return the size of this collection
149 public int getColourCount()
151 return this._colourList.size();
155 * Returns the value of field 'schemeName'.
157 * @return the value of field 'SchemeName'.
159 public java.lang.String getSchemeName()
161 return this._schemeName;
165 * Returns the value of field 'version'. The field 'version' has the following
166 * description: Jalview colour scheme document version.
169 * @return the value of field 'Version'.
171 public java.lang.String getVersion()
173 return this._version;
179 * @return true if this object is valid according to the schema
181 public boolean isValid()
186 } catch (org.exolab.castor.xml.ValidationException vex)
197 * @throws org.exolab.castor.xml.MarshalException
198 * if object is null or if any SAXException is thrown during
200 * @throws org.exolab.castor.xml.ValidationException
201 * if this object is an invalid instance according to the schema
203 public void marshal(final java.io.Writer out)
204 throws org.exolab.castor.xml.MarshalException,
205 org.exolab.castor.xml.ValidationException
207 Marshaller.marshal(this, out);
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
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
227 Marshaller.marshal(this, handler);
232 public void removeAllColour()
234 this._colourList.clear();
238 * Method removeColour.
241 * @return true if the object was removed from the collection.
243 public boolean removeColour(final Colour vColour)
245 boolean removed = _colourList.remove(vColour);
250 * Method removeColourAt.
253 * @return the element removed from the collection
255 public Colour removeColourAt(final int index)
257 java.lang.Object obj = this._colourList.remove(index);
266 * @throws java.lang.IndexOutOfBoundsException
267 * if the index given is outside the bounds of the collection
269 public void setColour(final int index, final Colour vColour)
270 throws java.lang.IndexOutOfBoundsException
272 // check bounds for index
273 if (index < 0 || index >= this._colourList.size())
275 throw new IndexOutOfBoundsException("setColour: Index value '"
276 + index + "' not in range [0.."
277 + (this._colourList.size() - 1) + "]");
280 this._colourList.set(index, vColour);
286 * @param vColourArray
288 public void setColour(final Colour[] vColourArray)
293 for (int i = 0; i < vColourArray.length; i++)
295 this._colourList.add(vColourArray[i]);
300 * Sets the value of field 'schemeName'.
303 * the value of field 'schemeName'.
305 public void setSchemeName(final java.lang.String schemeName)
307 this._schemeName = schemeName;
311 * Sets the value of field 'version'. The field 'version' has the following
312 * description: Jalview colour scheme document version.
316 * the value of field 'version'.
318 public void setVersion(final java.lang.String version)
320 this._version = version;
327 * @throws org.exolab.castor.xml.MarshalException
328 * if object is null or if any SAXException is thrown during
330 * @throws org.exolab.castor.xml.ValidationException
331 * if this object is an invalid instance according to the schema
332 * @return the unmarshaled jalview.schemabinding.version2.JalviewUserColours
334 public static jalview.schemabinding.version2.JalviewUserColours unmarshal(
335 final java.io.Reader reader)
336 throws org.exolab.castor.xml.MarshalException,
337 org.exolab.castor.xml.ValidationException
339 return (jalview.schemabinding.version2.JalviewUserColours) Unmarshaller
341 jalview.schemabinding.version2.JalviewUserColours.class,
348 * @throws org.exolab.castor.xml.ValidationException
349 * if this object is an invalid instance according to the schema
351 public void validate() throws org.exolab.castor.xml.ValidationException
353 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
354 validator.validate(this);