merge from 2_4_Release branch
[jalview.git] / src / jalview / binding / Annotation.java
1 /*
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
4  * 
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.
9  * 
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.
14  * 
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
18  */
19 package jalview.binding;
20
21 // ---------------------------------/
22 // - Imported classes and packages -/
23 // ---------------------------------/
24
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
27
28 /**
29  * Class Annotation.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class Annotation implements java.io.Serializable
34 {
35
36   // --------------------------/
37   // - Class/Member Variables -/
38   // --------------------------/
39
40   /**
41    * Field _graph.
42    */
43   private boolean _graph;
44
45   /**
46    * keeps track of state for field: _graph
47    */
48   private boolean _has_graph;
49
50   /**
51    * Field _graphType.
52    */
53   private int _graphType;
54
55   /**
56    * keeps track of state for field: _graphType
57    */
58   private boolean _has_graphType;
59
60   /**
61    * Field _annotationElementList.
62    */
63   private java.util.Vector _annotationElementList;
64
65   /**
66    * Field _label.
67    */
68   private java.lang.String _label;
69
70   /**
71    * Field _description.
72    */
73   private java.lang.String _description;
74
75   // ----------------/
76   // - Constructors -/
77   // ----------------/
78
79   public Annotation()
80   {
81     super();
82     this._annotationElementList = new java.util.Vector();
83   }
84
85   // -----------/
86   // - Methods -/
87   // -----------/
88
89   /**
90    * 
91    * 
92    * @param vAnnotationElement
93    * @throws java.lang.IndexOutOfBoundsException
94    *                 if the index given is outside the bounds of the collection
95    */
96   public void addAnnotationElement(
97           final jalview.binding.AnnotationElement vAnnotationElement)
98           throws java.lang.IndexOutOfBoundsException
99   {
100     this._annotationElementList.addElement(vAnnotationElement);
101   }
102
103   /**
104    * 
105    * 
106    * @param index
107    * @param vAnnotationElement
108    * @throws java.lang.IndexOutOfBoundsException
109    *                 if the index given is outside the bounds of the collection
110    */
111   public void addAnnotationElement(final int index,
112           final jalview.binding.AnnotationElement vAnnotationElement)
113           throws java.lang.IndexOutOfBoundsException
114   {
115     this._annotationElementList.add(index, vAnnotationElement);
116   }
117
118   /**
119    */
120   public void deleteGraph()
121   {
122     this._has_graph = false;
123   }
124
125   /**
126    */
127   public void deleteGraphType()
128   {
129     this._has_graphType = false;
130   }
131
132   /**
133    * Method enumerateAnnotationElement.
134    * 
135    * @return an Enumeration over all jalview.binding.AnnotationElement elements
136    */
137   public java.util.Enumeration enumerateAnnotationElement()
138   {
139     return this._annotationElementList.elements();
140   }
141
142   /**
143    * Method getAnnotationElement.
144    * 
145    * @param index
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
149    *         index
150    */
151   public jalview.binding.AnnotationElement getAnnotationElement(
152           final int index) throws java.lang.IndexOutOfBoundsException
153   {
154     // check bounds for index
155     if (index < 0 || index >= this._annotationElementList.size())
156     {
157       throw new IndexOutOfBoundsException(
158               "getAnnotationElement: Index value '" + index
159                       + "' not in range [0.."
160                       + (this._annotationElementList.size() - 1) + "]");
161     }
162
163     return (jalview.binding.AnnotationElement) _annotationElementList
164             .get(index);
165   }
166
167   /**
168    * Method getAnnotationElement.Returns the contents of the collection in an
169    * Array.
170    * <p>
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.
174    * 
175    * @return this collection as an Array
176    */
177   public jalview.binding.AnnotationElement[] getAnnotationElement()
178   {
179     jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
180     return (jalview.binding.AnnotationElement[]) this._annotationElementList
181             .toArray(array);
182   }
183
184   /**
185    * Method getAnnotationElementCount.
186    * 
187    * @return the size of this collection
188    */
189   public int getAnnotationElementCount()
190   {
191     return this._annotationElementList.size();
192   }
193
194   /**
195    * Returns the value of field 'description'.
196    * 
197    * @return the value of field 'Description'.
198    */
199   public java.lang.String getDescription()
200   {
201     return this._description;
202   }
203
204   /**
205    * Returns the value of field 'graph'.
206    * 
207    * @return the value of field 'Graph'.
208    */
209   public boolean getGraph()
210   {
211     return this._graph;
212   }
213
214   /**
215    * Returns the value of field 'graphType'.
216    * 
217    * @return the value of field 'GraphType'.
218    */
219   public int getGraphType()
220   {
221     return this._graphType;
222   }
223
224   /**
225    * Returns the value of field 'label'.
226    * 
227    * @return the value of field 'Label'.
228    */
229   public java.lang.String getLabel()
230   {
231     return this._label;
232   }
233
234   /**
235    * Method hasGraph.
236    * 
237    * @return true if at least one Graph has been added
238    */
239   public boolean hasGraph()
240   {
241     return this._has_graph;
242   }
243
244   /**
245    * Method hasGraphType.
246    * 
247    * @return true if at least one GraphType has been added
248    */
249   public boolean hasGraphType()
250   {
251     return this._has_graphType;
252   }
253
254   /**
255    * Returns the value of field 'graph'.
256    * 
257    * @return the value of field 'Graph'.
258    */
259   public boolean isGraph()
260   {
261     return this._graph;
262   }
263
264   /**
265    * Method isValid.
266    * 
267    * @return true if this object is valid according to the schema
268    */
269   public boolean isValid()
270   {
271     try
272     {
273       validate();
274     } catch (org.exolab.castor.xml.ValidationException vex)
275     {
276       return false;
277     }
278     return true;
279   }
280
281   /**
282    * 
283    * 
284    * @param out
285    * @throws org.exolab.castor.xml.MarshalException
286    *                 if object is null or if any SAXException is thrown during
287    *                 marshaling
288    * @throws org.exolab.castor.xml.ValidationException
289    *                 if this object is an invalid instance according to the
290    *                 schema
291    */
292   public void marshal(final java.io.Writer out)
293           throws org.exolab.castor.xml.MarshalException,
294           org.exolab.castor.xml.ValidationException
295   {
296     Marshaller.marshal(this, out);
297   }
298
299   /**
300    * 
301    * 
302    * @param handler
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
307    *                 schema
308    * @throws org.exolab.castor.xml.MarshalException
309    *                 if object is null or if any SAXException is thrown during
310    *                 marshaling
311    */
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
316   {
317     Marshaller.marshal(this, handler);
318   }
319
320   /**
321    */
322   public void removeAllAnnotationElement()
323   {
324     this._annotationElementList.clear();
325   }
326
327   /**
328    * Method removeAnnotationElement.
329    * 
330    * @param vAnnotationElement
331    * @return true if the object was removed from the collection.
332    */
333   public boolean removeAnnotationElement(
334           final jalview.binding.AnnotationElement vAnnotationElement)
335   {
336     boolean removed = _annotationElementList.remove(vAnnotationElement);
337     return removed;
338   }
339
340   /**
341    * Method removeAnnotationElementAt.
342    * 
343    * @param index
344    * @return the element removed from the collection
345    */
346   public jalview.binding.AnnotationElement removeAnnotationElementAt(
347           final int index)
348   {
349     java.lang.Object obj = this._annotationElementList.remove(index);
350     return (jalview.binding.AnnotationElement) obj;
351   }
352
353   /**
354    * 
355    * 
356    * @param index
357    * @param vAnnotationElement
358    * @throws java.lang.IndexOutOfBoundsException
359    *                 if the index given is outside the bounds of the collection
360    */
361   public void setAnnotationElement(final int index,
362           final jalview.binding.AnnotationElement vAnnotationElement)
363           throws java.lang.IndexOutOfBoundsException
364   {
365     // check bounds for index
366     if (index < 0 || index >= this._annotationElementList.size())
367     {
368       throw new IndexOutOfBoundsException(
369               "setAnnotationElement: Index value '" + index
370                       + "' not in range [0.."
371                       + (this._annotationElementList.size() - 1) + "]");
372     }
373
374     this._annotationElementList.set(index, vAnnotationElement);
375   }
376
377   /**
378    * 
379    * 
380    * @param vAnnotationElementArray
381    */
382   public void setAnnotationElement(
383           final jalview.binding.AnnotationElement[] vAnnotationElementArray)
384   {
385     // -- copy array
386     _annotationElementList.clear();
387
388     for (int i = 0; i < vAnnotationElementArray.length; i++)
389     {
390       this._annotationElementList.add(vAnnotationElementArray[i]);
391     }
392   }
393
394   /**
395    * Sets the value of field 'description'.
396    * 
397    * @param description
398    *                the value of field 'description'.
399    */
400   public void setDescription(final java.lang.String description)
401   {
402     this._description = description;
403   }
404
405   /**
406    * Sets the value of field 'graph'.
407    * 
408    * @param graph
409    *                the value of field 'graph'.
410    */
411   public void setGraph(final boolean graph)
412   {
413     this._graph = graph;
414     this._has_graph = true;
415   }
416
417   /**
418    * Sets the value of field 'graphType'.
419    * 
420    * @param graphType
421    *                the value of field 'graphType'.
422    */
423   public void setGraphType(final int graphType)
424   {
425     this._graphType = graphType;
426     this._has_graphType = true;
427   }
428
429   /**
430    * Sets the value of field 'label'.
431    * 
432    * @param label
433    *                the value of field 'label'.
434    */
435   public void setLabel(final java.lang.String label)
436   {
437     this._label = label;
438   }
439
440   /**
441    * Method unmarshal.
442    * 
443    * @param reader
444    * @throws org.exolab.castor.xml.MarshalException
445    *                 if object is null or if any SAXException is thrown during
446    *                 marshaling
447    * @throws org.exolab.castor.xml.ValidationException
448    *                 if this object is an invalid instance according to the
449    *                 schema
450    * @return the unmarshaled jalview.binding.Annotation
451    */
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
456   {
457     return (jalview.binding.Annotation) Unmarshaller.unmarshal(
458             jalview.binding.Annotation.class, reader);
459   }
460
461   /**
462    * 
463    * 
464    * @throws org.exolab.castor.xml.ValidationException
465    *                 if this object is an invalid instance according to the
466    *                 schema
467    */
468   public void validate() throws org.exolab.castor.xml.ValidationException
469   {
470     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
471     validator.validate(this);
472   }
473
474 }