JAL-1517 fix copyright for 2.8.2
[jalview.git] / src / jalview / binding / Annotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10  * of the License, or (at your option) any later version.
11  *  
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.
16  * 
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.
20  */
21 package jalview.binding;
22
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
26
27 import org.exolab.castor.xml.Marshaller;
28 import org.exolab.castor.xml.Unmarshaller;
29
30 /**
31  * Class Annotation.
32  * 
33  * @version $Revision$ $Date$
34  */
35 public class Annotation implements java.io.Serializable
36 {
37
38   // --------------------------/
39   // - Class/Member Variables -/
40   // --------------------------/
41
42   /**
43    * Field _graph.
44    */
45   private boolean _graph;
46
47   /**
48    * keeps track of state for field: _graph
49    */
50   private boolean _has_graph;
51
52   /**
53    * Field _graphType.
54    */
55   private int _graphType;
56
57   /**
58    * keeps track of state for field: _graphType
59    */
60   private boolean _has_graphType;
61
62   /**
63    * Field _annotationElementList.
64    */
65   private java.util.Vector _annotationElementList;
66
67   /**
68    * Field _label.
69    */
70   private java.lang.String _label;
71
72   /**
73    * Field _description.
74    */
75   private java.lang.String _description;
76
77   // ----------------/
78   // - Constructors -/
79   // ----------------/
80
81   public Annotation()
82   {
83     super();
84     this._annotationElementList = new java.util.Vector();
85   }
86
87   // -----------/
88   // - Methods -/
89   // -----------/
90
91   /**
92    * 
93    * 
94    * @param vAnnotationElement
95    * @throws java.lang.IndexOutOfBoundsException
96    *           if the index given is outside the bounds of the collection
97    */
98   public void addAnnotationElement(
99           final jalview.binding.AnnotationElement vAnnotationElement)
100           throws java.lang.IndexOutOfBoundsException
101   {
102     this._annotationElementList.addElement(vAnnotationElement);
103   }
104
105   /**
106    * 
107    * 
108    * @param index
109    * @param vAnnotationElement
110    * @throws java.lang.IndexOutOfBoundsException
111    *           if the index given is outside the bounds of the collection
112    */
113   public void addAnnotationElement(final int index,
114           final jalview.binding.AnnotationElement vAnnotationElement)
115           throws java.lang.IndexOutOfBoundsException
116   {
117     this._annotationElementList.add(index, vAnnotationElement);
118   }
119
120   /**
121      */
122   public void deleteGraph()
123   {
124     this._has_graph = false;
125   }
126
127   /**
128      */
129   public void deleteGraphType()
130   {
131     this._has_graphType = false;
132   }
133
134   /**
135    * Method enumerateAnnotationElement.
136    * 
137    * @return an Enumeration over all jalview.binding.AnnotationElement elements
138    */
139   public java.util.Enumeration enumerateAnnotationElement()
140   {
141     return this._annotationElementList.elements();
142   }
143
144   /**
145    * Method getAnnotationElement.
146    * 
147    * @param index
148    * @throws java.lang.IndexOutOfBoundsException
149    *           if the index given is outside the bounds of the collection
150    * @return the value of the jalview.binding.AnnotationElement at the given
151    *         index
152    */
153   public jalview.binding.AnnotationElement getAnnotationElement(
154           final int index) throws java.lang.IndexOutOfBoundsException
155   {
156     // check bounds for index
157     if (index < 0 || index >= this._annotationElementList.size())
158     {
159       throw new IndexOutOfBoundsException(
160               "getAnnotationElement: Index value '" + index
161                       + "' not in range [0.."
162                       + (this._annotationElementList.size() - 1) + "]");
163     }
164
165     return (jalview.binding.AnnotationElement) _annotationElementList
166             .get(index);
167   }
168
169   /**
170    * Method getAnnotationElement.Returns the contents of the collection in an
171    * Array.
172    * <p>
173    * Note: Just in case the collection contents are changing in another thread,
174    * we pass a 0-length Array of the correct type into the API call. This way we
175    * <i>know</i> that the Array returned is of exactly the correct length.
176    * 
177    * @return this collection as an Array
178    */
179   public jalview.binding.AnnotationElement[] getAnnotationElement()
180   {
181     jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
182     return (jalview.binding.AnnotationElement[]) this._annotationElementList
183             .toArray(array);
184   }
185
186   /**
187    * Method getAnnotationElementCount.
188    * 
189    * @return the size of this collection
190    */
191   public int getAnnotationElementCount()
192   {
193     return this._annotationElementList.size();
194   }
195
196   /**
197    * Returns the value of field 'description'.
198    * 
199    * @return the value of field 'Description'.
200    */
201   public java.lang.String getDescription()
202   {
203     return this._description;
204   }
205
206   /**
207    * Returns the value of field 'graph'.
208    * 
209    * @return the value of field 'Graph'.
210    */
211   public boolean getGraph()
212   {
213     return this._graph;
214   }
215
216   /**
217    * Returns the value of field 'graphType'.
218    * 
219    * @return the value of field 'GraphType'.
220    */
221   public int getGraphType()
222   {
223     return this._graphType;
224   }
225
226   /**
227    * Returns the value of field 'label'.
228    * 
229    * @return the value of field 'Label'.
230    */
231   public java.lang.String getLabel()
232   {
233     return this._label;
234   }
235
236   /**
237    * Method hasGraph.
238    * 
239    * @return true if at least one Graph has been added
240    */
241   public boolean hasGraph()
242   {
243     return this._has_graph;
244   }
245
246   /**
247    * Method hasGraphType.
248    * 
249    * @return true if at least one GraphType has been added
250    */
251   public boolean hasGraphType()
252   {
253     return this._has_graphType;
254   }
255
256   /**
257    * Returns the value of field 'graph'.
258    * 
259    * @return the value of field 'Graph'.
260    */
261   public boolean isGraph()
262   {
263     return this._graph;
264   }
265
266   /**
267    * Method isValid.
268    * 
269    * @return true if this object is valid according to the schema
270    */
271   public boolean isValid()
272   {
273     try
274     {
275       validate();
276     } catch (org.exolab.castor.xml.ValidationException vex)
277     {
278       return false;
279     }
280     return true;
281   }
282
283   /**
284    * 
285    * 
286    * @param out
287    * @throws org.exolab.castor.xml.MarshalException
288    *           if object is null or if any SAXException is thrown during
289    *           marshaling
290    * @throws org.exolab.castor.xml.ValidationException
291    *           if this object is an invalid instance according to the schema
292    */
293   public void marshal(final java.io.Writer out)
294           throws org.exolab.castor.xml.MarshalException,
295           org.exolab.castor.xml.ValidationException
296   {
297     Marshaller.marshal(this, out);
298   }
299
300   /**
301    * 
302    * 
303    * @param handler
304    * @throws java.io.IOException
305    *           if an IOException occurs during marshaling
306    * @throws org.exolab.castor.xml.ValidationException
307    *           if this object is an invalid instance according to the 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 schema
449    * @return the unmarshaled jalview.binding.Annotation
450    */
451   public static jalview.binding.Annotation unmarshal(
452           final java.io.Reader reader)
453           throws org.exolab.castor.xml.MarshalException,
454           org.exolab.castor.xml.ValidationException
455   {
456     return (jalview.binding.Annotation) Unmarshaller.unmarshal(
457             jalview.binding.Annotation.class, reader);
458   }
459
460   /**
461    * 
462    * 
463    * @throws org.exolab.castor.xml.ValidationException
464    *           if this object is an invalid instance according to the schema
465    */
466   public void validate() throws org.exolab.castor.xml.ValidationException
467   {
468     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
469     validator.validate(this);
470   }
471
472 }