2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.binding;
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
27 import jalview.util.MessageManager;
29 import org.exolab.castor.xml.Marshaller;
30 import org.exolab.castor.xml.Unmarshaller;
35 * @version $Revision$ $Date$
37 public class Annotation implements java.io.Serializable
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private boolean _graph;
50 * keeps track of state for field: _graph
52 private boolean _has_graph;
57 private int _graphType;
60 * keeps track of state for field: _graphType
62 private boolean _has_graphType;
65 * Field _annotationElementList.
67 private java.util.Vector _annotationElementList;
72 private java.lang.String _label;
77 private java.lang.String _description;
86 this._annotationElementList = new java.util.Vector();
96 * @param vAnnotationElement
97 * @throws java.lang.IndexOutOfBoundsException
98 * if the index given is outside the bounds of the collection
100 public void addAnnotationElement(
101 final jalview.binding.AnnotationElement vAnnotationElement)
102 throws java.lang.IndexOutOfBoundsException
104 this._annotationElementList.addElement(vAnnotationElement);
111 * @param vAnnotationElement
112 * @throws java.lang.IndexOutOfBoundsException
113 * if the index given is outside the bounds of the collection
115 public void addAnnotationElement(final int index,
116 final jalview.binding.AnnotationElement vAnnotationElement)
117 throws java.lang.IndexOutOfBoundsException
119 this._annotationElementList.add(index, vAnnotationElement);
124 public void deleteGraph()
126 this._has_graph = false;
131 public void deleteGraphType()
133 this._has_graphType = false;
137 * Method enumerateAnnotationElement.
139 * @return an Enumeration over all jalview.binding.AnnotationElement elements
141 public java.util.Enumeration enumerateAnnotationElement()
143 return this._annotationElementList.elements();
147 * Method getAnnotationElement.
150 * @throws java.lang.IndexOutOfBoundsException
151 * if the index given is outside the bounds of the collection
152 * @return the value of the jalview.binding.AnnotationElement at the given
155 public jalview.binding.AnnotationElement getAnnotationElement(
156 final int index) throws java.lang.IndexOutOfBoundsException
158 // check bounds for index
159 if (index < 0 || index >= this._annotationElementList.size())
161 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
162 "getAnnotationElement",
163 Integer.valueOf(index).toString(),
164 Integer.valueOf((this._annotationElementList.size() - 1)).toString()
168 return (jalview.binding.AnnotationElement) _annotationElementList
173 * Method getAnnotationElement.Returns the contents of the collection in an
176 * Note: Just in case the collection contents are changing in another thread,
177 * we pass a 0-length Array of the correct type into the API call. This way we
178 * <i>know</i> that the Array returned is of exactly the correct length.
180 * @return this collection as an Array
182 public jalview.binding.AnnotationElement[] getAnnotationElement()
184 jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
185 return (jalview.binding.AnnotationElement[]) this._annotationElementList
190 * Method getAnnotationElementCount.
192 * @return the size of this collection
194 public int getAnnotationElementCount()
196 return this._annotationElementList.size();
200 * Returns the value of field 'description'.
202 * @return the value of field 'Description'.
204 public java.lang.String getDescription()
206 return this._description;
210 * Returns the value of field 'graph'.
212 * @return the value of field 'Graph'.
214 public boolean getGraph()
220 * Returns the value of field 'graphType'.
222 * @return the value of field 'GraphType'.
224 public int getGraphType()
226 return this._graphType;
230 * Returns the value of field 'label'.
232 * @return the value of field 'Label'.
234 public java.lang.String getLabel()
242 * @return true if at least one Graph has been added
244 public boolean hasGraph()
246 return this._has_graph;
250 * Method hasGraphType.
252 * @return true if at least one GraphType has been added
254 public boolean hasGraphType()
256 return this._has_graphType;
260 * Returns the value of field 'graph'.
262 * @return the value of field 'Graph'.
264 public boolean isGraph()
272 * @return true if this object is valid according to the schema
274 public boolean isValid()
279 } catch (org.exolab.castor.xml.ValidationException vex)
290 * @throws org.exolab.castor.xml.MarshalException
291 * if object is null or if any SAXException is thrown during
293 * @throws org.exolab.castor.xml.ValidationException
294 * if this object is an invalid instance according to the schema
296 public void marshal(final java.io.Writer out)
297 throws org.exolab.castor.xml.MarshalException,
298 org.exolab.castor.xml.ValidationException
300 Marshaller.marshal(this, out);
307 * @throws java.io.IOException
308 * if an IOException occurs during marshaling
309 * @throws org.exolab.castor.xml.ValidationException
310 * if this object is an invalid instance according to the schema
311 * @throws org.exolab.castor.xml.MarshalException
312 * if object is null or if any SAXException is thrown during
315 public void marshal(final org.xml.sax.ContentHandler handler)
316 throws java.io.IOException,
317 org.exolab.castor.xml.MarshalException,
318 org.exolab.castor.xml.ValidationException
320 Marshaller.marshal(this, handler);
325 public void removeAllAnnotationElement()
327 this._annotationElementList.clear();
331 * Method removeAnnotationElement.
333 * @param vAnnotationElement
334 * @return true if the object was removed from the collection.
336 public boolean removeAnnotationElement(
337 final jalview.binding.AnnotationElement vAnnotationElement)
339 boolean removed = _annotationElementList.remove(vAnnotationElement);
344 * Method removeAnnotationElementAt.
347 * @return the element removed from the collection
349 public jalview.binding.AnnotationElement removeAnnotationElementAt(
352 java.lang.Object obj = this._annotationElementList.remove(index);
353 return (jalview.binding.AnnotationElement) obj;
360 * @param vAnnotationElement
361 * @throws java.lang.IndexOutOfBoundsException
362 * if the index given is outside the bounds of the collection
364 public void setAnnotationElement(final int index,
365 final jalview.binding.AnnotationElement vAnnotationElement)
366 throws java.lang.IndexOutOfBoundsException
368 // check bounds for index
369 if (index < 0 || index >= this._annotationElementList.size())
371 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
372 "setAnnotationElement",
373 Integer.valueOf(index).toString(),
374 Integer.valueOf((this._annotationElementList.size() - 1)).toString()
378 this._annotationElementList.set(index, vAnnotationElement);
384 * @param vAnnotationElementArray
386 public void setAnnotationElement(
387 final jalview.binding.AnnotationElement[] vAnnotationElementArray)
390 _annotationElementList.clear();
392 for (int i = 0; i < vAnnotationElementArray.length; i++)
394 this._annotationElementList.add(vAnnotationElementArray[i]);
399 * Sets the value of field 'description'.
402 * the value of field 'description'.
404 public void setDescription(final java.lang.String description)
406 this._description = description;
410 * Sets the value of field 'graph'.
413 * the value of field 'graph'.
415 public void setGraph(final boolean graph)
418 this._has_graph = true;
422 * Sets the value of field 'graphType'.
425 * the value of field 'graphType'.
427 public void setGraphType(final int graphType)
429 this._graphType = graphType;
430 this._has_graphType = true;
434 * Sets the value of field 'label'.
437 * the value of field 'label'.
439 public void setLabel(final java.lang.String label)
448 * @throws org.exolab.castor.xml.MarshalException
449 * if object is null or if any SAXException is thrown during
451 * @throws org.exolab.castor.xml.ValidationException
452 * if this object is an invalid instance according to the schema
453 * @return the unmarshaled jalview.binding.Annotation
455 public static jalview.binding.Annotation unmarshal(
456 final java.io.Reader reader)
457 throws org.exolab.castor.xml.MarshalException,
458 org.exolab.castor.xml.ValidationException
460 return (jalview.binding.Annotation) Unmarshaller.unmarshal(
461 jalview.binding.Annotation.class, reader);
467 * @throws org.exolab.castor.xml.ValidationException
468 * if this object is an invalid instance according to the schema
470 public void validate() throws org.exolab.castor.xml.ValidationException
472 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
473 validator.validate(this);