2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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;
30 * @version $Revision$ $Date$
32 public class Annotation implements java.io.Serializable
35 // --------------------------/
36 // - Class/Member Variables -/
37 // --------------------------/
42 private boolean _graph;
45 * keeps track of state for field: _graph
47 private boolean _has_graph;
52 private int _graphType;
55 * keeps track of state for field: _graphType
57 private boolean _has_graphType;
60 * Field _annotationElementList.
62 private java.util.Vector _annotationElementList;
67 private java.lang.String _label;
72 private java.lang.String _description;
81 this._annotationElementList = new java.util.Vector();
91 * @param vAnnotationElement
92 * @throws java.lang.IndexOutOfBoundsException
93 * if the index given is outside the bounds of the collection
95 public void addAnnotationElement(
96 final jalview.binding.AnnotationElement vAnnotationElement)
97 throws java.lang.IndexOutOfBoundsException
99 this._annotationElementList.addElement(vAnnotationElement);
106 * @param vAnnotationElement
107 * @throws java.lang.IndexOutOfBoundsException
108 * if the index given is outside the bounds of the collection
110 public void addAnnotationElement(final int index,
111 final jalview.binding.AnnotationElement vAnnotationElement)
112 throws java.lang.IndexOutOfBoundsException
114 this._annotationElementList.add(index, vAnnotationElement);
119 public void deleteGraph()
121 this._has_graph = false;
126 public void deleteGraphType()
128 this._has_graphType = false;
132 * Method enumerateAnnotationElement.
134 * @return an Enumeration over all jalview.binding.AnnotationElement elements
136 public java.util.Enumeration enumerateAnnotationElement()
138 return this._annotationElementList.elements();
142 * Method getAnnotationElement.
145 * @throws java.lang.IndexOutOfBoundsException
146 * if the index given is outside the bounds of the collection
147 * @return the value of the jalview.binding.AnnotationElement at the given
150 public jalview.binding.AnnotationElement getAnnotationElement(
151 final int index) throws java.lang.IndexOutOfBoundsException
153 // check bounds for index
154 if (index < 0 || index >= this._annotationElementList.size())
156 throw new IndexOutOfBoundsException(
157 "getAnnotationElement: Index value '" + index
158 + "' not in range [0.."
159 + (this._annotationElementList.size() - 1) + "]");
162 return (jalview.binding.AnnotationElement) _annotationElementList
167 * Method getAnnotationElement.Returns the contents of the collection in an
170 * Note: Just in case the collection contents are changing in another thread,
171 * we pass a 0-length Array of the correct type into the API call. This way we
172 * <i>know</i> that the Array returned is of exactly the correct length.
174 * @return this collection as an Array
176 public jalview.binding.AnnotationElement[] getAnnotationElement()
178 jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
179 return (jalview.binding.AnnotationElement[]) this._annotationElementList
184 * Method getAnnotationElementCount.
186 * @return the size of this collection
188 public int getAnnotationElementCount()
190 return this._annotationElementList.size();
194 * Returns the value of field 'description'.
196 * @return the value of field 'Description'.
198 public java.lang.String getDescription()
200 return this._description;
204 * Returns the value of field 'graph'.
206 * @return the value of field 'Graph'.
208 public boolean getGraph()
214 * Returns the value of field 'graphType'.
216 * @return the value of field 'GraphType'.
218 public int getGraphType()
220 return this._graphType;
224 * Returns the value of field 'label'.
226 * @return the value of field 'Label'.
228 public java.lang.String getLabel()
236 * @return true if at least one Graph has been added
238 public boolean hasGraph()
240 return this._has_graph;
244 * Method hasGraphType.
246 * @return true if at least one GraphType has been added
248 public boolean hasGraphType()
250 return this._has_graphType;
254 * Returns the value of field 'graph'.
256 * @return the value of field 'Graph'.
258 public boolean isGraph()
266 * @return true if this object is valid according to the schema
268 public boolean isValid()
273 } catch (org.exolab.castor.xml.ValidationException vex)
284 * @throws org.exolab.castor.xml.MarshalException
285 * if object is null or if any SAXException is thrown during
287 * @throws org.exolab.castor.xml.ValidationException
288 * if this object is an invalid instance according to the schema
290 public void marshal(final java.io.Writer out)
291 throws org.exolab.castor.xml.MarshalException,
292 org.exolab.castor.xml.ValidationException
294 Marshaller.marshal(this, out);
301 * @throws java.io.IOException
302 * if an IOException occurs during marshaling
303 * @throws org.exolab.castor.xml.ValidationException
304 * if this object is an invalid instance according to the schema
305 * @throws org.exolab.castor.xml.MarshalException
306 * if object is null or if any SAXException is thrown during
309 public void marshal(final org.xml.sax.ContentHandler handler)
310 throws java.io.IOException,
311 org.exolab.castor.xml.MarshalException,
312 org.exolab.castor.xml.ValidationException
314 Marshaller.marshal(this, handler);
319 public void removeAllAnnotationElement()
321 this._annotationElementList.clear();
325 * Method removeAnnotationElement.
327 * @param vAnnotationElement
328 * @return true if the object was removed from the collection.
330 public boolean removeAnnotationElement(
331 final jalview.binding.AnnotationElement vAnnotationElement)
333 boolean removed = _annotationElementList.remove(vAnnotationElement);
338 * Method removeAnnotationElementAt.
341 * @return the element removed from the collection
343 public jalview.binding.AnnotationElement removeAnnotationElementAt(
346 java.lang.Object obj = this._annotationElementList.remove(index);
347 return (jalview.binding.AnnotationElement) obj;
354 * @param vAnnotationElement
355 * @throws java.lang.IndexOutOfBoundsException
356 * if the index given is outside the bounds of the collection
358 public void setAnnotationElement(final int index,
359 final jalview.binding.AnnotationElement vAnnotationElement)
360 throws java.lang.IndexOutOfBoundsException
362 // check bounds for index
363 if (index < 0 || index >= this._annotationElementList.size())
365 throw new IndexOutOfBoundsException(
366 "setAnnotationElement: Index value '" + index
367 + "' not in range [0.."
368 + (this._annotationElementList.size() - 1) + "]");
371 this._annotationElementList.set(index, vAnnotationElement);
377 * @param vAnnotationElementArray
379 public void setAnnotationElement(
380 final jalview.binding.AnnotationElement[] vAnnotationElementArray)
383 _annotationElementList.clear();
385 for (int i = 0; i < vAnnotationElementArray.length; i++)
387 this._annotationElementList.add(vAnnotationElementArray[i]);
392 * Sets the value of field 'description'.
395 * the value of field 'description'.
397 public void setDescription(final java.lang.String description)
399 this._description = description;
403 * Sets the value of field 'graph'.
406 * the value of field 'graph'.
408 public void setGraph(final boolean graph)
411 this._has_graph = true;
415 * Sets the value of field 'graphType'.
418 * the value of field 'graphType'.
420 public void setGraphType(final int graphType)
422 this._graphType = graphType;
423 this._has_graphType = true;
427 * Sets the value of field 'label'.
430 * the value of field 'label'.
432 public void setLabel(final java.lang.String label)
441 * @throws org.exolab.castor.xml.MarshalException
442 * if object is null or if any SAXException is thrown during
444 * @throws org.exolab.castor.xml.ValidationException
445 * if this object is an invalid instance according to the schema
446 * @return the unmarshaled jalview.binding.Annotation
448 public static jalview.binding.Annotation unmarshal(
449 final java.io.Reader reader)
450 throws org.exolab.castor.xml.MarshalException,
451 org.exolab.castor.xml.ValidationException
453 return (jalview.binding.Annotation) Unmarshaller.unmarshal(
454 jalview.binding.Annotation.class, reader);
460 * @throws org.exolab.castor.xml.ValidationException
461 * if this object is an invalid instance according to the schema
463 public void validate() throws org.exolab.castor.xml.ValidationException
465 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
466 validator.validate(this);