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();
93 * @param vAnnotationElement
94 * @throws java.lang.IndexOutOfBoundsException if the index
95 * given is outside the bounds of the collection
97 public void addAnnotationElement(
98 final jalview.binding.AnnotationElement vAnnotationElement)
99 throws java.lang.IndexOutOfBoundsException {
100 this._annotationElementList.addElement(vAnnotationElement);
107 * @param vAnnotationElement
108 * @throws java.lang.IndexOutOfBoundsException if the index
109 * given is outside the bounds of the collection
111 public void addAnnotationElement(
113 final jalview.binding.AnnotationElement vAnnotationElement)
114 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
136 * jalview.binding.AnnotationElement elements
138 public java.util.Enumeration enumerateAnnotationElement(
140 return this._annotationElementList.elements();
144 * Method getAnnotationElement.
147 * @throws java.lang.IndexOutOfBoundsException if the index
148 * given is outside the bounds of the collection
149 * @return the value of the jalview.binding.AnnotationElement
152 public jalview.binding.AnnotationElement getAnnotationElement(
154 throws java.lang.IndexOutOfBoundsException {
155 // check bounds for index
156 if (index < 0 || index >= this._annotationElementList.size()) {
157 throw new IndexOutOfBoundsException("getAnnotationElement: Index value '" + index + "' not in range [0.." + (this._annotationElementList.size() - 1) + "]");
160 return (jalview.binding.AnnotationElement) _annotationElementList.get(index);
164 * Method getAnnotationElement.Returns the contents of the
165 * collection in an Array. <p>Note: Just in case the
166 * collection contents are changing in another thread, we pass
167 * a 0-length Array of the correct type into the API call.
168 * This way we <i>know</i> that the Array returned is of
169 * exactly the correct length.
171 * @return this collection as an Array
173 public jalview.binding.AnnotationElement[] getAnnotationElement(
175 jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
176 return (jalview.binding.AnnotationElement[]) this._annotationElementList.toArray(array);
180 * Method getAnnotationElementCount.
182 * @return the size of this collection
184 public int getAnnotationElementCount(
186 return this._annotationElementList.size();
190 * Returns the value of field 'description'.
192 * @return the value of field 'Description'.
194 public java.lang.String getDescription(
196 return this._description;
200 * Returns the value of field 'graph'.
202 * @return the value of field 'Graph'.
204 public boolean getGraph(
210 * Returns the value of field 'graphType'.
212 * @return the value of field 'GraphType'.
214 public int getGraphType(
216 return this._graphType;
220 * Returns the value of field 'label'.
222 * @return the value of field 'Label'.
224 public java.lang.String getLabel(
232 * @return true if at least one Graph has been added
234 public boolean hasGraph(
236 return this._has_graph;
240 * Method hasGraphType.
242 * @return true if at least one GraphType has been added
244 public boolean hasGraphType(
246 return this._has_graphType;
250 * Returns the value of field 'graph'.
252 * @return the value of field 'Graph'.
254 public boolean isGraph(
262 * @return true if this object is valid according to the schema
264 public boolean isValid(
268 } catch (org.exolab.castor.xml.ValidationException vex) {
278 * @throws org.exolab.castor.xml.MarshalException if object is
279 * null or if any SAXException is thrown during marshaling
280 * @throws org.exolab.castor.xml.ValidationException if this
281 * object is an invalid instance according to the schema
284 final java.io.Writer out)
285 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
286 Marshaller.marshal(this, out);
293 * @throws java.io.IOException if an IOException occurs during
295 * @throws org.exolab.castor.xml.ValidationException if this
296 * object is an invalid instance according to the schema
297 * @throws org.exolab.castor.xml.MarshalException if object is
298 * null or if any SAXException is thrown during marshaling
301 final org.xml.sax.ContentHandler handler)
302 throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
303 Marshaller.marshal(this, handler);
308 public void removeAllAnnotationElement(
310 this._annotationElementList.clear();
314 * Method removeAnnotationElement.
316 * @param vAnnotationElement
317 * @return true if the object was removed from the collection.
319 public boolean removeAnnotationElement(
320 final jalview.binding.AnnotationElement vAnnotationElement) {
321 boolean removed = _annotationElementList.remove(vAnnotationElement);
326 * Method removeAnnotationElementAt.
329 * @return the element removed from the collection
331 public jalview.binding.AnnotationElement removeAnnotationElementAt(
333 java.lang.Object obj = this._annotationElementList.remove(index);
334 return (jalview.binding.AnnotationElement) obj;
341 * @param vAnnotationElement
342 * @throws java.lang.IndexOutOfBoundsException if the index
343 * given is outside the bounds of the collection
345 public void setAnnotationElement(
347 final jalview.binding.AnnotationElement vAnnotationElement)
348 throws java.lang.IndexOutOfBoundsException {
349 // check bounds for index
350 if (index < 0 || index >= this._annotationElementList.size()) {
351 throw new IndexOutOfBoundsException("setAnnotationElement: Index value '" + index + "' not in range [0.." + (this._annotationElementList.size() - 1) + "]");
354 this._annotationElementList.set(index, vAnnotationElement);
360 * @param vAnnotationElementArray
362 public void setAnnotationElement(
363 final jalview.binding.AnnotationElement[] vAnnotationElementArray) {
365 _annotationElementList.clear();
367 for (int i = 0; i < vAnnotationElementArray.length; i++) {
368 this._annotationElementList.add(vAnnotationElementArray[i]);
373 * Sets the value of field 'description'.
375 * @param description the value of field 'description'.
377 public void setDescription(
378 final java.lang.String description) {
379 this._description = description;
383 * Sets the value of field 'graph'.
385 * @param graph the value of field 'graph'.
387 public void setGraph(
388 final boolean graph) {
390 this._has_graph = true;
394 * Sets the value of field 'graphType'.
396 * @param graphType the value of field 'graphType'.
398 public void setGraphType(
399 final int graphType) {
400 this._graphType = graphType;
401 this._has_graphType = true;
405 * Sets the value of field 'label'.
407 * @param label the value of field 'label'.
409 public void setLabel(
410 final java.lang.String label) {
418 * @throws org.exolab.castor.xml.MarshalException if object is
419 * null or if any SAXException is thrown during marshaling
420 * @throws org.exolab.castor.xml.ValidationException if this
421 * object is an invalid instance according to the schema
422 * @return the unmarshaled jalview.binding.Annotation
424 public static jalview.binding.Annotation unmarshal(
425 final java.io.Reader reader)
426 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
427 return (jalview.binding.Annotation) Unmarshaller.unmarshal(jalview.binding.Annotation.class, reader);
433 * @throws org.exolab.castor.xml.ValidationException if this
434 * object is an invalid instance according to the schema
436 public void validate(
438 throws org.exolab.castor.xml.ValidationException {
439 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
440 validator.validate(this);