2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
48 private java.util.Vector _colourList;
54 public JalviewUserColours()
57 this._colourList = new java.util.Vector();
68 * @throws java.lang.IndexOutOfBoundsException
69 * if the index given is outside the bounds of the collection
71 public void addColour(final Colour vColour)
72 throws java.lang.IndexOutOfBoundsException
74 this._colourList.addElement(vColour);
82 * @throws java.lang.IndexOutOfBoundsException
83 * if the index given is outside the bounds of the collection
85 public void addColour(final int index, final Colour vColour)
86 throws java.lang.IndexOutOfBoundsException
88 this._colourList.add(index, vColour);
92 * Method enumerateColour.
94 * @return an Enumeration over all Colour elements
96 public java.util.Enumeration enumerateColour()
98 return this._colourList.elements();
105 * @throws java.lang.IndexOutOfBoundsException
106 * if the index given is outside the bounds of the collection
107 * @return the value of the Colour at the given index
109 public Colour getColour(final int index)
110 throws java.lang.IndexOutOfBoundsException
112 // check bounds for index
113 if (index < 0 || index >= this._colourList.size())
115 throw new IndexOutOfBoundsException("getColour: Index value '"
116 + index + "' not in range [0.."
117 + (this._colourList.size() - 1) + "]");
120 return (Colour) _colourList.get(index);
124 * Method getColour.Returns the contents of the collection in an Array.
126 * Note: Just in case the collection contents are changing in another thread,
127 * we pass a 0-length Array of the correct type into the API call. This way we
128 * <i>know</i> that the Array returned is of exactly the correct length.
130 * @return this collection as an Array
132 public Colour[] getColour()
134 Colour[] array = new Colour[0];
135 return (Colour[]) this._colourList.toArray(array);
139 * Method getColourCount.
141 * @return the size of this collection
143 public int getColourCount()
145 return this._colourList.size();
149 * Returns the value of field 'schemeName'.
151 * @return the value of field 'SchemeName'.
153 public java.lang.String getSchemeName()
155 return this._schemeName;
161 * @return true if this object is valid according to the schema
163 public boolean isValid()
168 } catch (org.exolab.castor.xml.ValidationException vex)
179 * @throws org.exolab.castor.xml.MarshalException
180 * if object is null or if any SAXException is thrown during
182 * @throws org.exolab.castor.xml.ValidationException
183 * if this object is an invalid instance according to the
186 public void marshal(final java.io.Writer out)
187 throws org.exolab.castor.xml.MarshalException,
188 org.exolab.castor.xml.ValidationException
190 Marshaller.marshal(this, out);
197 * @throws java.io.IOException
198 * if an IOException occurs during marshaling
199 * @throws org.exolab.castor.xml.ValidationException
200 * if this object is an invalid instance according to the
202 * @throws org.exolab.castor.xml.MarshalException
203 * if object is null or if any SAXException is thrown during
206 public void marshal(final org.xml.sax.ContentHandler handler)
207 throws java.io.IOException,
208 org.exolab.castor.xml.MarshalException,
209 org.exolab.castor.xml.ValidationException
211 Marshaller.marshal(this, handler);
216 public void removeAllColour()
218 this._colourList.clear();
222 * Method removeColour.
225 * @return true if the object was removed from the collection.
227 public boolean removeColour(final Colour vColour)
229 boolean removed = _colourList.remove(vColour);
234 * Method removeColourAt.
237 * @return the element removed from the collection
239 public Colour removeColourAt(final int index)
241 java.lang.Object obj = this._colourList.remove(index);
250 * @throws java.lang.IndexOutOfBoundsException
251 * if the index given is outside the bounds of the collection
253 public void setColour(final int index, final Colour vColour)
254 throws java.lang.IndexOutOfBoundsException
256 // check bounds for index
257 if (index < 0 || index >= this._colourList.size())
259 throw new IndexOutOfBoundsException("setColour: Index value '"
260 + index + "' not in range [0.."
261 + (this._colourList.size() - 1) + "]");
264 this._colourList.set(index, vColour);
270 * @param vColourArray
272 public void setColour(final Colour[] vColourArray)
277 for (int i = 0; i < vColourArray.length; i++)
279 this._colourList.add(vColourArray[i]);
284 * Sets the value of field 'schemeName'.
287 * the value of field 'schemeName'.
289 public void setSchemeName(final java.lang.String schemeName)
291 this._schemeName = schemeName;
298 * @throws org.exolab.castor.xml.MarshalException
299 * if object is null or if any SAXException is thrown during
301 * @throws org.exolab.castor.xml.ValidationException
302 * if this object is an invalid instance according to the
304 * @return the unmarshaled jalview.binding.JalviewUserColours
306 public static jalview.binding.JalviewUserColours unmarshal(
307 final java.io.Reader reader)
308 throws org.exolab.castor.xml.MarshalException,
309 org.exolab.castor.xml.ValidationException
311 return (jalview.binding.JalviewUserColours) Unmarshaller.unmarshal(
312 jalview.binding.JalviewUserColours.class, reader);
318 * @throws org.exolab.castor.xml.ValidationException
319 * if this object is an invalid instance according to the
322 public void validate() throws org.exolab.castor.xml.ValidationException
324 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
325 validator.validate(this);