2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.binding;
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;
61 public JalviewUserColours() {
63 this._colourList = new java.util.Vector();
75 * @throws java.lang.IndexOutOfBoundsException if the index
76 * given is outside the bounds of the collection
78 public void addColour(
80 throws java.lang.IndexOutOfBoundsException {
81 this._colourList.addElement(vColour);
89 * @throws java.lang.IndexOutOfBoundsException if the index
90 * given is outside the bounds of the collection
92 public void addColour(
95 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 if the index
114 * given is outside the bounds of the collection
115 * @return the value of the Colour at the given index
117 public Colour getColour(
119 throws java.lang.IndexOutOfBoundsException {
120 // check bounds for index
121 if (index < 0 || index >= this._colourList.size()) {
122 throw new IndexOutOfBoundsException("getColour: Index value '" + index + "' not in range [0.." + (this._colourList.size() - 1) + "]");
125 return (Colour) _colourList.get(index);
129 * Method getColour.Returns the contents of the collection in
130 * an Array. <p>Note: Just in case the collection contents
131 * are changing in another thread, we pass a 0-length Array of
132 * the correct type into the API call. This way we <i>know</i>
133 * 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'
165 * has the following description: Jalview colour scheme
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(
185 } catch (org.exolab.castor.xml.ValidationException vex) {
195 * @throws org.exolab.castor.xml.MarshalException if object is
196 * null or if any SAXException is thrown during marshaling
197 * @throws org.exolab.castor.xml.ValidationException if this
198 * object is an invalid instance according to the schema
201 final java.io.Writer out)
202 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
203 Marshaller.marshal(this, out);
210 * @throws java.io.IOException if an IOException occurs during
212 * @throws org.exolab.castor.xml.ValidationException if this
213 * object is an invalid instance according to the schema
214 * @throws org.exolab.castor.xml.MarshalException if object is
215 * null or if any SAXException is thrown during marshaling
218 final org.xml.sax.ContentHandler handler)
219 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
220 Marshaller.marshal(this, handler);
225 public void removeAllColour(
227 this._colourList.clear();
231 * Method removeColour.
234 * @return true if the object was removed from the collection.
236 public boolean removeColour(
237 final Colour vColour) {
238 boolean removed = _colourList.remove(vColour);
243 * Method removeColourAt.
246 * @return the element removed from the collection
248 public Colour removeColourAt(
250 java.lang.Object obj = this._colourList.remove(index);
259 * @throws java.lang.IndexOutOfBoundsException if the index
260 * given is outside the bounds of the collection
262 public void setColour(
264 final Colour vColour)
265 throws java.lang.IndexOutOfBoundsException {
266 // check bounds for index
267 if (index < 0 || index >= this._colourList.size()) {
268 throw new IndexOutOfBoundsException("setColour: Index value '" + index + "' not in range [0.." + (this._colourList.size() - 1) + "]");
271 this._colourList.set(index, vColour);
277 * @param vColourArray
279 public void setColour(
280 final Colour[] vColourArray) {
284 for (int i = 0; i < vColourArray.length; i++) {
285 this._colourList.add(vColourArray[i]);
290 * Sets the value of field 'schemeName'.
292 * @param schemeName the value of field 'schemeName'.
294 public void setSchemeName(
295 final java.lang.String schemeName) {
296 this._schemeName = schemeName;
300 * Sets the value of field 'version'. The field 'version' has
301 * the following description: Jalview colour scheme document
305 * @param version the value of field 'version'.
307 public void setVersion(
308 final java.lang.String version) {
309 this._version = version;
316 * @throws org.exolab.castor.xml.MarshalException if object is
317 * null or if any SAXException is thrown during marshaling
318 * @throws org.exolab.castor.xml.ValidationException if this
319 * object is an invalid instance according to the schema
320 * @return the unmarshaled jalview.binding.JalviewUserColours
322 public static jalview.binding.JalviewUserColours unmarshal(
323 final java.io.Reader reader)
324 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
325 return (jalview.binding.JalviewUserColours) Unmarshaller.unmarshal(jalview.binding.JalviewUserColours.class, reader);
331 * @throws org.exolab.castor.xml.ValidationException if this
332 * object is an invalid instance according to the schema
334 public void validate(
336 throws org.exolab.castor.xml.ValidationException {
337 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
338 validator.validate(this);