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