2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
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.
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.
21 package jalview.schemabinding.version2;
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
27 import org.exolab.castor.xml.Marshaller;
28 import org.exolab.castor.xml.Unmarshaller;
31 * Class JalviewUserColours.
33 * @version $Revision$ $Date$
35 public class JalviewUserColours implements java.io.Serializable
38 // --------------------------/
39 // - Class/Member Variables -/
40 // --------------------------/
45 private java.lang.String _schemeName;
48 * Jalview colour scheme document version.
51 private java.lang.String _version;
56 private java.util.Vector _colourList;
62 public JalviewUserColours()
65 this._colourList = new java.util.Vector();
76 * @throws java.lang.IndexOutOfBoundsException
77 * if the index given is outside the bounds of the collection
79 public void addColour(final Colour vColour)
80 throws java.lang.IndexOutOfBoundsException
82 this._colourList.addElement(vColour);
90 * @throws java.lang.IndexOutOfBoundsException
91 * if the index given is outside the bounds of the collection
93 public void addColour(final int index, final Colour vColour)
94 throws java.lang.IndexOutOfBoundsException
96 this._colourList.add(index, vColour);
100 * Method enumerateColour.
102 * @return an Enumeration over all Colour elements
104 public java.util.Enumeration enumerateColour()
106 return this._colourList.elements();
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
117 public Colour getColour(final int index)
118 throws java.lang.IndexOutOfBoundsException
120 // check bounds for index
121 if (index < 0 || index >= this._colourList.size())
123 throw new IndexOutOfBoundsException("getColour: Index value '"
124 + index + "' not in range [0.."
125 + (this._colourList.size() - 1) + "]");
128 return (Colour) _colourList.get(index);
132 * Method getColour.Returns the contents of the collection in an Array.
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.
138 * @return this collection as an Array
140 public Colour[] getColour()
142 Colour[] array = new Colour[0];
143 return (Colour[]) this._colourList.toArray(array);
147 * Method getColourCount.
149 * @return the size of this collection
151 public int getColourCount()
153 return this._colourList.size();
157 * Returns the value of field 'schemeName'.
159 * @return the value of field 'SchemeName'.
161 public java.lang.String getSchemeName()
163 return this._schemeName;
167 * Returns the value of field 'version'. The field 'version' has the following
168 * description: Jalview colour scheme document version.
171 * @return the value of field 'Version'.
173 public java.lang.String getVersion()
175 return this._version;
181 * @return true if this object is valid according to the schema
183 public boolean isValid()
188 } catch (org.exolab.castor.xml.ValidationException vex)
199 * @throws org.exolab.castor.xml.MarshalException
200 * if object is null or if any SAXException is thrown during
202 * @throws org.exolab.castor.xml.ValidationException
203 * if this object is an invalid instance according to the schema
205 public void marshal(final java.io.Writer out)
206 throws org.exolab.castor.xml.MarshalException,
207 org.exolab.castor.xml.ValidationException
209 Marshaller.marshal(this, out);
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
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
229 Marshaller.marshal(this, handler);
234 public void removeAllColour()
236 this._colourList.clear();
240 * Method removeColour.
243 * @return true if the object was removed from the collection.
245 public boolean removeColour(final Colour vColour)
247 boolean removed = _colourList.remove(vColour);
252 * Method removeColourAt.
255 * @return the element removed from the collection
257 public Colour removeColourAt(final int index)
259 java.lang.Object obj = this._colourList.remove(index);
268 * @throws java.lang.IndexOutOfBoundsException
269 * if the index given is outside the bounds of the collection
271 public void setColour(final int index, final Colour vColour)
272 throws java.lang.IndexOutOfBoundsException
274 // check bounds for index
275 if (index < 0 || index >= this._colourList.size())
277 throw new IndexOutOfBoundsException("setColour: Index value '"
278 + index + "' not in range [0.."
279 + (this._colourList.size() - 1) + "]");
282 this._colourList.set(index, vColour);
288 * @param vColourArray
290 public void setColour(final Colour[] vColourArray)
295 for (int i = 0; i < vColourArray.length; i++)
297 this._colourList.add(vColourArray[i]);
302 * Sets the value of field 'schemeName'.
305 * the value of field 'schemeName'.
307 public void setSchemeName(final java.lang.String schemeName)
309 this._schemeName = schemeName;
313 * Sets the value of field 'version'. The field 'version' has the following
314 * description: Jalview colour scheme document version.
318 * the value of field 'version'.
320 public void setVersion(final java.lang.String version)
322 this._version = version;
329 * @throws org.exolab.castor.xml.MarshalException
330 * if object is null or if any SAXException is thrown during
332 * @throws org.exolab.castor.xml.ValidationException
333 * if this object is an invalid instance according to the schema
334 * @return the unmarshaled jalview.schemabinding.version2.JalviewUserColours
336 public static jalview.schemabinding.version2.JalviewUserColours unmarshal(
337 final java.io.Reader reader)
338 throws org.exolab.castor.xml.MarshalException,
339 org.exolab.castor.xml.ValidationException
341 return (jalview.schemabinding.version2.JalviewUserColours) Unmarshaller
343 jalview.schemabinding.version2.JalviewUserColours.class,
350 * @throws org.exolab.castor.xml.ValidationException
351 * if this object is an invalid instance according to the schema
353 public void validate() throws org.exolab.castor.xml.ValidationException
355 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
356 validator.validate(this);