extended Colour element with additional optional attributes for graduated colour
[jalview.git] / src / jalview / binding / Annotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.1)
3  * Copyright (C) 2009 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       //----------------/
77      //- Constructors -/
78     //----------------/
79
80     public Annotation() {
81         super();
82         this._annotationElementList = new java.util.Vector();
83     }
84
85
86       //-----------/
87      //- Methods -/
88     //-----------/
89
90     /**
91      * 
92      * 
93      * @param vAnnotationElement
94      * @throws java.lang.IndexOutOfBoundsException if the index
95      * given is outside the bounds of the collection
96      */
97     public void addAnnotationElement(
98             final jalview.binding.AnnotationElement vAnnotationElement)
99     throws java.lang.IndexOutOfBoundsException {
100         this._annotationElementList.addElement(vAnnotationElement);
101     }
102
103     /**
104      * 
105      * 
106      * @param index
107      * @param vAnnotationElement
108      * @throws java.lang.IndexOutOfBoundsException if the index
109      * given is outside the bounds of the collection
110      */
111     public void addAnnotationElement(
112             final int index,
113             final jalview.binding.AnnotationElement vAnnotationElement)
114     throws java.lang.IndexOutOfBoundsException {
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
136      * jalview.binding.AnnotationElement elements
137      */
138     public java.util.Enumeration enumerateAnnotationElement(
139     ) {
140         return this._annotationElementList.elements();
141     }
142
143     /**
144      * Method getAnnotationElement.
145      * 
146      * @param index
147      * @throws java.lang.IndexOutOfBoundsException if the index
148      * given is outside the bounds of the collection
149      * @return the value of the jalview.binding.AnnotationElement
150      * at the given index
151      */
152     public jalview.binding.AnnotationElement getAnnotationElement(
153             final int index)
154     throws java.lang.IndexOutOfBoundsException {
155         // check bounds for index
156         if (index < 0 || index >= this._annotationElementList.size()) {
157             throw new IndexOutOfBoundsException("getAnnotationElement: Index value '" + index + "' not in range [0.." + (this._annotationElementList.size() - 1) + "]");
158         }
159         
160         return (jalview.binding.AnnotationElement) _annotationElementList.get(index);
161     }
162
163     /**
164      * Method getAnnotationElement.Returns the contents of the
165      * collection in an Array.  <p>Note:  Just in case the
166      * collection contents are changing in another thread, we pass
167      * a 0-length Array of the correct type into the API call. 
168      * This way we <i>know</i> that the Array returned is of
169      * exactly the correct length.
170      * 
171      * @return this collection as an Array
172      */
173     public jalview.binding.AnnotationElement[] getAnnotationElement(
174     ) {
175         jalview.binding.AnnotationElement[] array = new jalview.binding.AnnotationElement[0];
176         return (jalview.binding.AnnotationElement[]) this._annotationElementList.toArray(array);
177     }
178
179     /**
180      * Method getAnnotationElementCount.
181      * 
182      * @return the size of this collection
183      */
184     public int getAnnotationElementCount(
185     ) {
186         return this._annotationElementList.size();
187     }
188
189     /**
190      * Returns the value of field 'description'.
191      * 
192      * @return the value of field 'Description'.
193      */
194     public java.lang.String getDescription(
195     ) {
196         return this._description;
197     }
198
199     /**
200      * Returns the value of field 'graph'.
201      * 
202      * @return the value of field 'Graph'.
203      */
204     public boolean getGraph(
205     ) {
206         return this._graph;
207     }
208
209     /**
210      * Returns the value of field 'graphType'.
211      * 
212      * @return the value of field 'GraphType'.
213      */
214     public int getGraphType(
215     ) {
216         return this._graphType;
217     }
218
219     /**
220      * Returns the value of field 'label'.
221      * 
222      * @return the value of field 'Label'.
223      */
224     public java.lang.String getLabel(
225     ) {
226         return this._label;
227     }
228
229     /**
230      * Method hasGraph.
231      * 
232      * @return true if at least one Graph has been added
233      */
234     public boolean hasGraph(
235     ) {
236         return this._has_graph;
237     }
238
239     /**
240      * Method hasGraphType.
241      * 
242      * @return true if at least one GraphType has been added
243      */
244     public boolean hasGraphType(
245     ) {
246         return this._has_graphType;
247     }
248
249     /**
250      * Returns the value of field 'graph'.
251      * 
252      * @return the value of field 'Graph'.
253      */
254     public boolean isGraph(
255     ) {
256         return this._graph;
257     }
258
259     /**
260      * Method isValid.
261      * 
262      * @return true if this object is valid according to the schema
263      */
264     public boolean isValid(
265     ) {
266         try {
267             validate();
268         } catch (org.exolab.castor.xml.ValidationException vex) {
269             return false;
270         }
271         return true;
272     }
273
274     /**
275      * 
276      * 
277      * @param out
278      * @throws org.exolab.castor.xml.MarshalException if object is
279      * null or if any SAXException is thrown during marshaling
280      * @throws org.exolab.castor.xml.ValidationException if this
281      * object is an invalid instance according to the schema
282      */
283     public void marshal(
284             final java.io.Writer out)
285     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
286         Marshaller.marshal(this, out);
287     }
288
289     /**
290      * 
291      * 
292      * @param handler
293      * @throws java.io.IOException if an IOException occurs during
294      * marshaling
295      * @throws org.exolab.castor.xml.ValidationException if this
296      * object is an invalid instance according to the schema
297      * @throws org.exolab.castor.xml.MarshalException if object is
298      * null or if any SAXException is thrown during marshaling
299      */
300     public void marshal(
301             final org.xml.sax.ContentHandler handler)
302     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
303         Marshaller.marshal(this, handler);
304     }
305
306     /**
307      */
308     public void removeAllAnnotationElement(
309     ) {
310         this._annotationElementList.clear();
311     }
312
313     /**
314      * Method removeAnnotationElement.
315      * 
316      * @param vAnnotationElement
317      * @return true if the object was removed from the collection.
318      */
319     public boolean removeAnnotationElement(
320             final jalview.binding.AnnotationElement vAnnotationElement) {
321         boolean removed = _annotationElementList.remove(vAnnotationElement);
322         return removed;
323     }
324
325     /**
326      * Method removeAnnotationElementAt.
327      * 
328      * @param index
329      * @return the element removed from the collection
330      */
331     public jalview.binding.AnnotationElement removeAnnotationElementAt(
332             final int index) {
333         java.lang.Object obj = this._annotationElementList.remove(index);
334         return (jalview.binding.AnnotationElement) obj;
335     }
336
337     /**
338      * 
339      * 
340      * @param index
341      * @param vAnnotationElement
342      * @throws java.lang.IndexOutOfBoundsException if the index
343      * given is outside the bounds of the collection
344      */
345     public void setAnnotationElement(
346             final int index,
347             final jalview.binding.AnnotationElement vAnnotationElement)
348     throws java.lang.IndexOutOfBoundsException {
349         // check bounds for index
350         if (index < 0 || index >= this._annotationElementList.size()) {
351             throw new IndexOutOfBoundsException("setAnnotationElement: Index value '" + index + "' not in range [0.." + (this._annotationElementList.size() - 1) + "]");
352         }
353         
354         this._annotationElementList.set(index, vAnnotationElement);
355     }
356
357     /**
358      * 
359      * 
360      * @param vAnnotationElementArray
361      */
362     public void setAnnotationElement(
363             final jalview.binding.AnnotationElement[] vAnnotationElementArray) {
364         //-- copy array
365         _annotationElementList.clear();
366         
367         for (int i = 0; i < vAnnotationElementArray.length; i++) {
368                 this._annotationElementList.add(vAnnotationElementArray[i]);
369         }
370     }
371
372     /**
373      * Sets the value of field 'description'.
374      * 
375      * @param description the value of field 'description'.
376      */
377     public void setDescription(
378             final java.lang.String description) {
379         this._description = description;
380     }
381
382     /**
383      * Sets the value of field 'graph'.
384      * 
385      * @param graph the value of field 'graph'.
386      */
387     public void setGraph(
388             final boolean graph) {
389         this._graph = graph;
390         this._has_graph = true;
391     }
392
393     /**
394      * Sets the value of field 'graphType'.
395      * 
396      * @param graphType the value of field 'graphType'.
397      */
398     public void setGraphType(
399             final int graphType) {
400         this._graphType = graphType;
401         this._has_graphType = true;
402     }
403
404     /**
405      * Sets the value of field 'label'.
406      * 
407      * @param label the value of field 'label'.
408      */
409     public void setLabel(
410             final java.lang.String label) {
411         this._label = label;
412     }
413
414     /**
415      * Method unmarshal.
416      * 
417      * @param reader
418      * @throws org.exolab.castor.xml.MarshalException if object is
419      * null or if any SAXException is thrown during marshaling
420      * @throws org.exolab.castor.xml.ValidationException if this
421      * object is an invalid instance according to the schema
422      * @return the unmarshaled jalview.binding.Annotation
423      */
424     public static jalview.binding.Annotation unmarshal(
425             final java.io.Reader reader)
426     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
427         return (jalview.binding.Annotation) Unmarshaller.unmarshal(jalview.binding.Annotation.class, reader);
428     }
429
430     /**
431      * 
432      * 
433      * @throws org.exolab.castor.xml.ValidationException if this
434      * object is an invalid instance according to the schema
435      */
436     public void validate(
437     )
438     throws org.exolab.castor.xml.ValidationException {
439         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
440         validator.validate(this);
441     }
442
443 }