2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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/>.
18 package jalview.binding;
20 //---------------------------------/
21 //- Imported classes and packages -/
22 //---------------------------------/
24 import org.exolab.castor.xml.Marshaller;
25 import org.exolab.castor.xml.Unmarshaller;
28 * Class JalviewUserColours.
30 * @version $Revision$ $Date$
32 public class JalviewUserColours implements java.io.Serializable
35 // --------------------------/
36 // - Class/Member Variables -/
37 // --------------------------/
42 private java.lang.String _schemeName;
45 * Jalview colour scheme document version.
48 private java.lang.String _version;
53 private java.util.Vector _colourList;
59 public JalviewUserColours()
62 this._colourList = new java.util.Vector();
73 * @throws java.lang.IndexOutOfBoundsException
74 * if the index given is outside the bounds of the collection
76 public void addColour(final Colour vColour)
77 throws java.lang.IndexOutOfBoundsException
79 this._colourList.addElement(vColour);
87 * @throws java.lang.IndexOutOfBoundsException
88 * if the index given is outside the bounds of the collection
90 public void addColour(final int index, final Colour vColour)
91 throws java.lang.IndexOutOfBoundsException
93 this._colourList.add(index, vColour);
97 * Method enumerateColour.
99 * @return an Enumeration over all Colour elements
101 public java.util.Enumeration enumerateColour()
103 return this._colourList.elements();
110 * @throws java.lang.IndexOutOfBoundsException
111 * if the index given is outside the bounds of the collection
112 * @return the value of the Colour at the given index
114 public Colour getColour(final int index)
115 throws java.lang.IndexOutOfBoundsException
117 // check bounds for index
118 if (index < 0 || index >= this._colourList.size())
120 throw new IndexOutOfBoundsException("getColour: Index value '"
121 + index + "' not in range [0.."
122 + (this._colourList.size() - 1) + "]");
125 return (Colour) _colourList.get(index);
129 * Method getColour.Returns the contents of the collection in an Array.
131 * Note: Just in case the collection contents are changing in another thread,
132 * we pass a 0-length Array of the correct type into the API call. This way we
133 * <i>know</i> that the Array returned is of exactly the correct length.
135 * @return this collection as an Array
137 public Colour[] getColour()
139 Colour[] array = new Colour[0];
140 return (Colour[]) this._colourList.toArray(array);
144 * Method getColourCount.
146 * @return the size of this collection
148 public int getColourCount()
150 return this._colourList.size();
154 * Returns the value of field 'schemeName'.
156 * @return the value of field 'SchemeName'.
158 public java.lang.String getSchemeName()
160 return this._schemeName;
164 * Returns the value of field 'version'. The field 'version' has the following
165 * description: Jalview colour scheme document version.
168 * @return the value of field 'Version'.
170 public java.lang.String getVersion()
172 return this._version;
178 * @return true if this object is valid according to the schema
180 public boolean isValid()
185 } catch (org.exolab.castor.xml.ValidationException vex)
196 * @throws org.exolab.castor.xml.MarshalException
197 * if object is null or if any SAXException is thrown during
199 * @throws org.exolab.castor.xml.ValidationException
200 * if this object is an invalid instance according to the schema
202 public void marshal(final java.io.Writer out)
203 throws org.exolab.castor.xml.MarshalException,
204 org.exolab.castor.xml.ValidationException
206 Marshaller.marshal(this, out);
213 * @throws java.io.IOException
214 * if an IOException occurs during marshaling
215 * @throws org.exolab.castor.xml.ValidationException
216 * if this object is an invalid instance according to the schema
217 * @throws org.exolab.castor.xml.MarshalException
218 * if object is null or if any SAXException is thrown during
221 public void marshal(final org.xml.sax.ContentHandler handler)
222 throws java.io.IOException,
223 org.exolab.castor.xml.MarshalException,
224 org.exolab.castor.xml.ValidationException
226 Marshaller.marshal(this, handler);
231 public void removeAllColour()
233 this._colourList.clear();
237 * Method removeColour.
240 * @return true if the object was removed from the collection.
242 public boolean removeColour(final Colour vColour)
244 boolean removed = _colourList.remove(vColour);
249 * Method removeColourAt.
252 * @return the element removed from the collection
254 public Colour removeColourAt(final int index)
256 java.lang.Object obj = this._colourList.remove(index);
265 * @throws java.lang.IndexOutOfBoundsException
266 * if the index given is outside the bounds of the collection
268 public void setColour(final int index, final Colour vColour)
269 throws java.lang.IndexOutOfBoundsException
271 // check bounds for index
272 if (index < 0 || index >= this._colourList.size())
274 throw new IndexOutOfBoundsException("setColour: Index value '"
275 + index + "' not in range [0.."
276 + (this._colourList.size() - 1) + "]");
279 this._colourList.set(index, vColour);
285 * @param vColourArray
287 public void setColour(final Colour[] vColourArray)
292 for (int i = 0; i < vColourArray.length; i++)
294 this._colourList.add(vColourArray[i]);
299 * Sets the value of field 'schemeName'.
302 * the value of field 'schemeName'.
304 public void setSchemeName(final java.lang.String schemeName)
306 this._schemeName = schemeName;
310 * Sets the value of field 'version'. The field 'version' has the following
311 * description: Jalview colour scheme document version.
315 * the value of field 'version'.
317 public void setVersion(final java.lang.String version)
319 this._version = version;
326 * @throws org.exolab.castor.xml.MarshalException
327 * if object is null or if any SAXException is thrown during
329 * @throws org.exolab.castor.xml.ValidationException
330 * if this object is an invalid instance according to the schema
331 * @return the unmarshaled jalview.binding.JalviewUserColours
333 public static jalview.binding.JalviewUserColours unmarshal(
334 final java.io.Reader reader)
335 throws org.exolab.castor.xml.MarshalException,
336 org.exolab.castor.xml.ValidationException
338 return (jalview.binding.JalviewUserColours) Unmarshaller.unmarshal(
339 jalview.binding.JalviewUserColours.class, reader);
345 * @throws org.exolab.castor.xml.ValidationException
346 * if this object is an invalid instance according to the schema
348 public void validate() throws org.exolab.castor.xml.ValidationException
350 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
351 validator.validate(this);