JAL-1432 updated copyright notices
[jalview.git] / src / jalview / binding / Annotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
10  *  
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.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
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 schema
290    */
291   public void marshal(final java.io.Writer out)
292           throws org.exolab.castor.xml.MarshalException,
293           org.exolab.castor.xml.ValidationException
294   {
295     Marshaller.marshal(this, out);
296   }
297
298   /**
299    * 
300    * 
301    * @param handler
302    * @throws java.io.IOException
303    *           if an IOException occurs during marshaling
304    * @throws org.exolab.castor.xml.ValidationException
305    *           if this object is an invalid instance according to the schema
306    * @throws org.exolab.castor.xml.MarshalException
307    *           if object is null or if any SAXException is thrown during
308    *           marshaling
309    */
310   public void marshal(final org.xml.sax.ContentHandler handler)
311           throws java.io.IOException,
312           org.exolab.castor.xml.MarshalException,
313           org.exolab.castor.xml.ValidationException
314   {
315     Marshaller.marshal(this, handler);
316   }
317
318   /**
319      */
320   public void removeAllAnnotationElement()
321   {
322     this._annotationElementList.clear();
323   }
324
325   /**
326    * Method removeAnnotationElement.
327    * 
328    * @param vAnnotationElement
329    * @return true if the object was removed from the collection.
330    */
331   public boolean removeAnnotationElement(
332           final jalview.binding.AnnotationElement vAnnotationElement)
333   {
334     boolean removed = _annotationElementList.remove(vAnnotationElement);
335     return removed;
336   }
337
338   /**
339    * Method removeAnnotationElementAt.
340    * 
341    * @param index
342    * @return the element removed from the collection
343    */
344   public jalview.binding.AnnotationElement removeAnnotationElementAt(
345           final int index)
346   {
347     java.lang.Object obj = this._annotationElementList.remove(index);
348     return (jalview.binding.AnnotationElement) obj;
349   }
350
351   /**
352    * 
353    * 
354    * @param index
355    * @param vAnnotationElement
356    * @throws java.lang.IndexOutOfBoundsException
357    *           if the index given is outside the bounds of the collection
358    */
359   public void setAnnotationElement(final int index,
360           final jalview.binding.AnnotationElement vAnnotationElement)
361           throws java.lang.IndexOutOfBoundsException
362   {
363     // check bounds for index
364     if (index < 0 || index >= this._annotationElementList.size())
365     {
366       throw new IndexOutOfBoundsException(
367               "setAnnotationElement: Index value '" + index
368                       + "' not in range [0.."
369                       + (this._annotationElementList.size() - 1) + "]");
370     }
371
372     this._annotationElementList.set(index, vAnnotationElement);
373   }
374
375   /**
376    * 
377    * 
378    * @param vAnnotationElementArray
379    */
380   public void setAnnotationElement(
381           final jalview.binding.AnnotationElement[] vAnnotationElementArray)
382   {
383     // -- copy array
384     _annotationElementList.clear();
385
386     for (int i = 0; i < vAnnotationElementArray.length; i++)
387     {
388       this._annotationElementList.add(vAnnotationElementArray[i]);
389     }
390   }
391
392   /**
393    * Sets the value of field 'description'.
394    * 
395    * @param description
396    *          the value of field 'description'.
397    */
398   public void setDescription(final java.lang.String description)
399   {
400     this._description = description;
401   }
402
403   /**
404    * Sets the value of field 'graph'.
405    * 
406    * @param graph
407    *          the value of field 'graph'.
408    */
409   public void setGraph(final boolean graph)
410   {
411     this._graph = graph;
412     this._has_graph = true;
413   }
414
415   /**
416    * Sets the value of field 'graphType'.
417    * 
418    * @param graphType
419    *          the value of field 'graphType'.
420    */
421   public void setGraphType(final int graphType)
422   {
423     this._graphType = graphType;
424     this._has_graphType = true;
425   }
426
427   /**
428    * Sets the value of field 'label'.
429    * 
430    * @param label
431    *          the value of field 'label'.
432    */
433   public void setLabel(final java.lang.String label)
434   {
435     this._label = label;
436   }
437
438   /**
439    * Method unmarshal.
440    * 
441    * @param reader
442    * @throws org.exolab.castor.xml.MarshalException
443    *           if object is null or if any SAXException is thrown during
444    *           marshaling
445    * @throws org.exolab.castor.xml.ValidationException
446    *           if this object is an invalid instance according to the schema
447    * @return the unmarshaled jalview.binding.Annotation
448    */
449   public static jalview.binding.Annotation unmarshal(
450           final java.io.Reader reader)
451           throws org.exolab.castor.xml.MarshalException,
452           org.exolab.castor.xml.ValidationException
453   {
454     return (jalview.binding.Annotation) Unmarshaller.unmarshal(
455             jalview.binding.Annotation.class, reader);
456   }
457
458   /**
459    * 
460    * 
461    * @throws org.exolab.castor.xml.ValidationException
462    *           if this object is an invalid instance according to the schema
463    */
464   public void validate() throws org.exolab.castor.xml.ValidationException
465   {
466     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
467     validator.validate(this);
468   }
469
470 }