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.binding;
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
27 import jalview.util.MessageManager;
29 import org.exolab.castor.xml.Marshaller;
30 import org.exolab.castor.xml.Unmarshaller;
33 * Class JalviewUserColours.
35 * @version $Revision$ $Date$
37 public class JalviewUserColours implements java.io.Serializable
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private java.lang.String _schemeName;
50 * Jalview colour scheme document version.
53 private java.lang.String _version;
58 private java.util.Vector _colourList;
64 public JalviewUserColours()
67 this._colourList = new java.util.Vector();
78 * @throws java.lang.IndexOutOfBoundsException
79 * if the index given is outside the bounds of the collection
81 public void addColour(final Colour vColour)
82 throws java.lang.IndexOutOfBoundsException
84 this._colourList.addElement(vColour);
92 * @throws java.lang.IndexOutOfBoundsException
93 * if the index given is outside the bounds of the collection
95 public void addColour(final int index, final Colour vColour)
96 throws java.lang.IndexOutOfBoundsException
98 this._colourList.add(index, vColour);
102 * Method enumerateColour.
104 * @return an Enumeration over all Colour elements
106 public java.util.Enumeration enumerateColour()
108 return this._colourList.elements();
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
119 public Colour getColour(final int index)
120 throws java.lang.IndexOutOfBoundsException
122 // check bounds for index
123 if (index < 0 || index >= this._colourList.size())
125 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
127 Integer.valueOf(index).toString(),
128 Integer.valueOf((this._colourList.size() - 1)).toString()
132 return (Colour) _colourList.get(index);
136 * Method getColour.Returns the contents of the collection in an Array.
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.
142 * @return this collection as an Array
144 public Colour[] getColour()
146 Colour[] array = new Colour[0];
147 return (Colour[]) this._colourList.toArray(array);
151 * Method getColourCount.
153 * @return the size of this collection
155 public int getColourCount()
157 return this._colourList.size();
161 * Returns the value of field 'schemeName'.
163 * @return the value of field 'SchemeName'.
165 public java.lang.String getSchemeName()
167 return this._schemeName;
171 * Returns the value of field 'version'. The field 'version' has the following
172 * description: Jalview colour scheme document version.
175 * @return the value of field 'Version'.
177 public java.lang.String getVersion()
179 return this._version;
185 * @return true if this object is valid according to the schema
187 public boolean isValid()
192 } catch (org.exolab.castor.xml.ValidationException vex)
203 * @throws org.exolab.castor.xml.MarshalException
204 * if object is null or if any SAXException is thrown during
206 * @throws org.exolab.castor.xml.ValidationException
207 * if this object is an invalid instance according to the schema
209 public void marshal(final java.io.Writer out)
210 throws org.exolab.castor.xml.MarshalException,
211 org.exolab.castor.xml.ValidationException
213 Marshaller.marshal(this, out);
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
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
233 Marshaller.marshal(this, handler);
238 public void removeAllColour()
240 this._colourList.clear();
244 * Method removeColour.
247 * @return true if the object was removed from the collection.
249 public boolean removeColour(final Colour vColour)
251 boolean removed = _colourList.remove(vColour);
256 * Method removeColourAt.
259 * @return the element removed from the collection
261 public Colour removeColourAt(final int index)
263 java.lang.Object obj = this._colourList.remove(index);
272 * @throws java.lang.IndexOutOfBoundsException
273 * if the index given is outside the bounds of the collection
275 public void setColour(final int index, final Colour vColour)
276 throws java.lang.IndexOutOfBoundsException
278 // check bounds for index
279 if (index < 0 || index >= this._colourList.size())
281 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
283 Integer.valueOf(index).toString(),
284 Integer.valueOf((this._colourList.size() - 1)).toString()
288 this._colourList.set(index, vColour);
294 * @param vColourArray
296 public void setColour(final Colour[] vColourArray)
301 for (int i = 0; i < vColourArray.length; i++)
303 this._colourList.add(vColourArray[i]);
308 * Sets the value of field 'schemeName'.
311 * the value of field 'schemeName'.
313 public void setSchemeName(final java.lang.String schemeName)
315 this._schemeName = schemeName;
319 * Sets the value of field 'version'. The field 'version' has the following
320 * description: Jalview colour scheme document version.
324 * the value of field 'version'.
326 public void setVersion(final java.lang.String version)
328 this._version = version;
335 * @throws org.exolab.castor.xml.MarshalException
336 * if object is null or if any SAXException is thrown during
338 * @throws org.exolab.castor.xml.ValidationException
339 * if this object is an invalid instance according to the schema
340 * @return the unmarshaled jalview.binding.JalviewUserColours
342 public static jalview.binding.JalviewUserColours unmarshal(
343 final java.io.Reader reader)
344 throws org.exolab.castor.xml.MarshalException,
345 org.exolab.castor.xml.ValidationException
347 return (jalview.binding.JalviewUserColours) Unmarshaller.unmarshal(
348 jalview.binding.JalviewUserColours.class, reader);
354 * @throws org.exolab.castor.xml.ValidationException
355 * if this object is an invalid instance according to the schema
357 public void validate() throws org.exolab.castor.xml.ValidationException
359 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
360 validator.validate(this);