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