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;
31 * @version $Revision$ $Date$
33 public class Annotation implements java.io.Serializable
36 // --------------------------/
37 // - Class/Member Variables -/
38 // --------------------------/
43 private boolean _graph;
46 * keeps track of state for field: _graph
48 private boolean _has_graph;
53 private int _graphType;
56 * keeps track of state for field: _graphType
58 private boolean _has_graphType;
61 * Field _annotationElementList.
63 private java.util.Vector _annotationElementList;
68 private java.lang.String _label;
73 private java.lang.String _description;
82 this._annotationElementList = new java.util.Vector();
92 * @param vAnnotationElement
93 * @throws java.lang.IndexOutOfBoundsException
94 * if the index given is outside the bounds of the collection
96 public void addAnnotationElement(
97 final jalview.binding.AnnotationElement vAnnotationElement)
98 throws java.lang.IndexOutOfBoundsException
100 this._annotationElementList.addElement(vAnnotationElement);
107 * @param vAnnotationElement
108 * @throws java.lang.IndexOutOfBoundsException
109 * if the index given is outside the bounds of the collection
111 public void addAnnotationElement(final int index,
112 final jalview.binding.AnnotationElement vAnnotationElement)
113 throws java.lang.IndexOutOfBoundsException
115 this._annotationElementList.add(index, vAnnotationElement);
120 public void deleteGraph()
122 this._has_graph = false;
127 public void deleteGraphType()
129 this._has_graphType = false;
133 * Method enumerateAnnotationElement.
135 * @return an Enumeration over all jalview.binding.AnnotationElement elements
137 public java.util.Enumeration enumerateAnnotationElement()
139 return this._annotationElementList.elements();
143 * Method getAnnotationElement.
146 * @throws java.lang.IndexOutOfBoundsException
147 * if the index given is outside the bounds of the collection
148 * @return the value of the jalview.binding.AnnotationElement at the given
151 public jalview.binding.AnnotationElement getAnnotationElement(
152 final int index) throws java.lang.IndexOutOfBoundsException
154 // check bounds for index
155 if (index < 0 || index >= this._annotationElementList.size())
157 throw new IndexOutOfBoundsException(
158 "getAnnotationElement: Index value '" + index
159 + "' not in range [0.."
160 + (this._annotationElementList.size() - 1) + "]");
163 return (jalview.binding.AnnotationElement) _annotationElementList
168 * Method getAnnotationElement.Returns the contents of the collection in an
171 * Note: Just in case the collection contents are changing in another thread,
172 * we pass a 0-length Array of the correct type into the API call. This way we
173 * <i>know</i> that the Array returned is of exactly the correct length.
175 * @return this collection as an Array
177 public jalview.binding.AnnotationElement[] getAnnotationElement()
179 jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
180 return (jalview.binding.AnnotationElement[]) this._annotationElementList
185 * Method getAnnotationElementCount.
187 * @return the size of this collection
189 public int getAnnotationElementCount()
191 return this._annotationElementList.size();
195 * Returns the value of field 'description'.
197 * @return the value of field 'Description'.
199 public java.lang.String getDescription()
201 return this._description;
205 * Returns the value of field 'graph'.
207 * @return the value of field 'Graph'.
209 public boolean getGraph()
215 * Returns the value of field 'graphType'.
217 * @return the value of field 'GraphType'.
219 public int getGraphType()
221 return this._graphType;
225 * Returns the value of field 'label'.
227 * @return the value of field 'Label'.
229 public java.lang.String getLabel()
237 * @return true if at least one Graph has been added
239 public boolean hasGraph()
241 return this._has_graph;
245 * Method hasGraphType.
247 * @return true if at least one GraphType has been added
249 public boolean hasGraphType()
251 return this._has_graphType;
255 * Returns the value of field 'graph'.
257 * @return the value of field 'Graph'.
259 public boolean isGraph()
267 * @return true if this object is valid according to the schema
269 public boolean isValid()
274 } catch (org.exolab.castor.xml.ValidationException vex)
285 * @throws org.exolab.castor.xml.MarshalException
286 * if object is null or if any SAXException is thrown during
288 * @throws org.exolab.castor.xml.ValidationException
289 * if this object is an invalid instance according to the
292 public void marshal(final java.io.Writer out)
293 throws org.exolab.castor.xml.MarshalException,
294 org.exolab.castor.xml.ValidationException
296 Marshaller.marshal(this, out);
303 * @throws java.io.IOException
304 * if an IOException occurs during marshaling
305 * @throws org.exolab.castor.xml.ValidationException
306 * if this object is an invalid instance according to the
308 * @throws org.exolab.castor.xml.MarshalException
309 * if object is null or if any SAXException is thrown during
312 public void marshal(final org.xml.sax.ContentHandler handler)
313 throws java.io.IOException,
314 org.exolab.castor.xml.MarshalException,
315 org.exolab.castor.xml.ValidationException
317 Marshaller.marshal(this, handler);
322 public void removeAllAnnotationElement()
324 this._annotationElementList.clear();
328 * Method removeAnnotationElement.
330 * @param vAnnotationElement
331 * @return true if the object was removed from the collection.
333 public boolean removeAnnotationElement(
334 final jalview.binding.AnnotationElement vAnnotationElement)
336 boolean removed = _annotationElementList.remove(vAnnotationElement);
341 * Method removeAnnotationElementAt.
344 * @return the element removed from the collection
346 public jalview.binding.AnnotationElement removeAnnotationElementAt(
349 java.lang.Object obj = this._annotationElementList.remove(index);
350 return (jalview.binding.AnnotationElement) obj;
357 * @param vAnnotationElement
358 * @throws java.lang.IndexOutOfBoundsException
359 * if the index given is outside the bounds of the collection
361 public void setAnnotationElement(final int index,
362 final jalview.binding.AnnotationElement vAnnotationElement)
363 throws java.lang.IndexOutOfBoundsException
365 // check bounds for index
366 if (index < 0 || index >= this._annotationElementList.size())
368 throw new IndexOutOfBoundsException(
369 "setAnnotationElement: Index value '" + index
370 + "' not in range [0.."
371 + (this._annotationElementList.size() - 1) + "]");
374 this._annotationElementList.set(index, vAnnotationElement);
380 * @param vAnnotationElementArray
382 public void setAnnotationElement(
383 final jalview.binding.AnnotationElement[] vAnnotationElementArray)
386 _annotationElementList.clear();
388 for (int i = 0; i < vAnnotationElementArray.length; i++)
390 this._annotationElementList.add(vAnnotationElementArray[i]);
395 * Sets the value of field 'description'.
398 * the value of field 'description'.
400 public void setDescription(final java.lang.String description)
402 this._description = description;
406 * Sets the value of field 'graph'.
409 * the value of field 'graph'.
411 public void setGraph(final boolean graph)
414 this._has_graph = true;
418 * Sets the value of field 'graphType'.
421 * the value of field 'graphType'.
423 public void setGraphType(final int graphType)
425 this._graphType = graphType;
426 this._has_graphType = true;
430 * Sets the value of field 'label'.
433 * the value of field 'label'.
435 public void setLabel(final java.lang.String label)
444 * @throws org.exolab.castor.xml.MarshalException
445 * if object is null or if any SAXException is thrown during
447 * @throws org.exolab.castor.xml.ValidationException
448 * if this object is an invalid instance according to the
450 * @return the unmarshaled jalview.binding.Annotation
452 public static jalview.binding.Annotation unmarshal(
453 final java.io.Reader reader)
454 throws org.exolab.castor.xml.MarshalException,
455 org.exolab.castor.xml.ValidationException
457 return (jalview.binding.Annotation) Unmarshaller.unmarshal(
458 jalview.binding.Annotation.class, reader);
464 * @throws org.exolab.castor.xml.ValidationException
465 * if this object is an invalid instance according to the
468 public void validate() throws org.exolab.castor.xml.ValidationException
470 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
471 validator.validate(this);