extended Colour element with additional optional attributes for graduated colour
[jalview.git] / src / jalview / binding / JSeq.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 JSeq.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class JSeq implements java.io.Serializable {
34
35
36       //--------------------------/
37      //- Class/Member Variables -/
38     //--------------------------/
39
40     /**
41      * Field _colour.
42      */
43     private int _colour;
44
45     /**
46      * keeps track of state for field: _colour
47      */
48     private boolean _has_colour;
49
50     /**
51      * Field _start.
52      */
53     private int _start;
54
55     /**
56      * keeps track of state for field: _start
57      */
58     private boolean _has_start;
59
60     /**
61      * Field _end.
62      */
63     private int _end;
64
65     /**
66      * keeps track of state for field: _end
67      */
68     private boolean _has_end;
69
70     /**
71      * Field _id.
72      */
73     private int _id;
74
75     /**
76      * keeps track of state for field: _id
77      */
78     private boolean _has_id;
79
80     /**
81      * Field _featuresList.
82      */
83     private java.util.Vector _featuresList;
84
85     /**
86      * Field _pdbidsList.
87      */
88     private java.util.Vector _pdbidsList;
89
90
91       //----------------/
92      //- Constructors -/
93     //----------------/
94
95     public JSeq() {
96         super();
97         this._featuresList = new java.util.Vector();
98         this._pdbidsList = new java.util.Vector();
99     }
100
101
102       //-----------/
103      //- Methods -/
104     //-----------/
105
106     /**
107      * 
108      * 
109      * @param vFeatures
110      * @throws java.lang.IndexOutOfBoundsException if the index
111      * given is outside the bounds of the collection
112      */
113     public void addFeatures(
114             final jalview.binding.Features vFeatures)
115     throws java.lang.IndexOutOfBoundsException {
116         this._featuresList.addElement(vFeatures);
117     }
118
119     /**
120      * 
121      * 
122      * @param index
123      * @param vFeatures
124      * @throws java.lang.IndexOutOfBoundsException if the index
125      * given is outside the bounds of the collection
126      */
127     public void addFeatures(
128             final int index,
129             final jalview.binding.Features vFeatures)
130     throws java.lang.IndexOutOfBoundsException {
131         this._featuresList.add(index, vFeatures);
132     }
133
134     /**
135      * 
136      * 
137      * @param vPdbids
138      * @throws java.lang.IndexOutOfBoundsException if the index
139      * given is outside the bounds of the collection
140      */
141     public void addPdbids(
142             final jalview.binding.Pdbids vPdbids)
143     throws java.lang.IndexOutOfBoundsException {
144         this._pdbidsList.addElement(vPdbids);
145     }
146
147     /**
148      * 
149      * 
150      * @param index
151      * @param vPdbids
152      * @throws java.lang.IndexOutOfBoundsException if the index
153      * given is outside the bounds of the collection
154      */
155     public void addPdbids(
156             final int index,
157             final jalview.binding.Pdbids vPdbids)
158     throws java.lang.IndexOutOfBoundsException {
159         this._pdbidsList.add(index, vPdbids);
160     }
161
162     /**
163      */
164     public void deleteColour(
165     ) {
166         this._has_colour= false;
167     }
168
169     /**
170      */
171     public void deleteEnd(
172     ) {
173         this._has_end= false;
174     }
175
176     /**
177      */
178     public void deleteId(
179     ) {
180         this._has_id= false;
181     }
182
183     /**
184      */
185     public void deleteStart(
186     ) {
187         this._has_start= false;
188     }
189
190     /**
191      * Method enumerateFeatures.
192      * 
193      * @return an Enumeration over all jalview.binding.Features
194      * elements
195      */
196     public java.util.Enumeration enumerateFeatures(
197     ) {
198         return this._featuresList.elements();
199     }
200
201     /**
202      * Method enumeratePdbids.
203      * 
204      * @return an Enumeration over all jalview.binding.Pdbids
205      * elements
206      */
207     public java.util.Enumeration enumeratePdbids(
208     ) {
209         return this._pdbidsList.elements();
210     }
211
212     /**
213      * Returns the value of field 'colour'.
214      * 
215      * @return the value of field 'Colour'.
216      */
217     public int getColour(
218     ) {
219         return this._colour;
220     }
221
222     /**
223      * Returns the value of field 'end'.
224      * 
225      * @return the value of field 'End'.
226      */
227     public int getEnd(
228     ) {
229         return this._end;
230     }
231
232     /**
233      * Method getFeatures.
234      * 
235      * @param index
236      * @throws java.lang.IndexOutOfBoundsException if the index
237      * given is outside the bounds of the collection
238      * @return the value of the jalview.binding.Features at the
239      * given index
240      */
241     public jalview.binding.Features getFeatures(
242             final int index)
243     throws java.lang.IndexOutOfBoundsException {
244         // check bounds for index
245         if (index < 0 || index >= this._featuresList.size()) {
246             throw new IndexOutOfBoundsException("getFeatures: Index value '" + index + "' not in range [0.." + (this._featuresList.size() - 1) + "]");
247         }
248         
249         return (jalview.binding.Features) _featuresList.get(index);
250     }
251
252     /**
253      * Method getFeatures.Returns the contents of the collection in
254      * an Array.  <p>Note:  Just in case the collection contents
255      * are changing in another thread, we pass a 0-length Array of
256      * the correct type into the API call.  This way we <i>know</i>
257      * that the Array returned is of exactly the correct length.
258      * 
259      * @return this collection as an Array
260      */
261     public jalview.binding.Features[] getFeatures(
262     ) {
263         jalview.binding.Features[] array = new jalview.binding.Features[0];
264         return (jalview.binding.Features[]) this._featuresList.toArray(array);
265     }
266
267     /**
268      * Method getFeaturesCount.
269      * 
270      * @return the size of this collection
271      */
272     public int getFeaturesCount(
273     ) {
274         return this._featuresList.size();
275     }
276
277     /**
278      * Returns the value of field 'id'.
279      * 
280      * @return the value of field 'Id'.
281      */
282     public int getId(
283     ) {
284         return this._id;
285     }
286
287     /**
288      * Method getPdbids.
289      * 
290      * @param index
291      * @throws java.lang.IndexOutOfBoundsException if the index
292      * given is outside the bounds of the collection
293      * @return the value of the jalview.binding.Pdbids at the given
294      * index
295      */
296     public jalview.binding.Pdbids getPdbids(
297             final int index)
298     throws java.lang.IndexOutOfBoundsException {
299         // check bounds for index
300         if (index < 0 || index >= this._pdbidsList.size()) {
301             throw new IndexOutOfBoundsException("getPdbids: Index value '" + index + "' not in range [0.." + (this._pdbidsList.size() - 1) + "]");
302         }
303         
304         return (jalview.binding.Pdbids) _pdbidsList.get(index);
305     }
306
307     /**
308      * Method getPdbids.Returns the contents of the collection in
309      * an Array.  <p>Note:  Just in case the collection contents
310      * are changing in another thread, we pass a 0-length Array of
311      * the correct type into the API call.  This way we <i>know</i>
312      * that the Array returned is of exactly the correct length.
313      * 
314      * @return this collection as an Array
315      */
316     public jalview.binding.Pdbids[] getPdbids(
317     ) {
318         jalview.binding.Pdbids[] array = new jalview.binding.Pdbids[0];
319         return (jalview.binding.Pdbids[]) this._pdbidsList.toArray(array);
320     }
321
322     /**
323      * Method getPdbidsCount.
324      * 
325      * @return the size of this collection
326      */
327     public int getPdbidsCount(
328     ) {
329         return this._pdbidsList.size();
330     }
331
332     /**
333      * Returns the value of field 'start'.
334      * 
335      * @return the value of field 'Start'.
336      */
337     public int getStart(
338     ) {
339         return this._start;
340     }
341
342     /**
343      * Method hasColour.
344      * 
345      * @return true if at least one Colour has been added
346      */
347     public boolean hasColour(
348     ) {
349         return this._has_colour;
350     }
351
352     /**
353      * Method hasEnd.
354      * 
355      * @return true if at least one End has been added
356      */
357     public boolean hasEnd(
358     ) {
359         return this._has_end;
360     }
361
362     /**
363      * Method hasId.
364      * 
365      * @return true if at least one Id has been added
366      */
367     public boolean hasId(
368     ) {
369         return this._has_id;
370     }
371
372     /**
373      * Method hasStart.
374      * 
375      * @return true if at least one Start has been added
376      */
377     public boolean hasStart(
378     ) {
379         return this._has_start;
380     }
381
382     /**
383      * Method isValid.
384      * 
385      * @return true if this object is valid according to the schema
386      */
387     public boolean isValid(
388     ) {
389         try {
390             validate();
391         } catch (org.exolab.castor.xml.ValidationException vex) {
392             return false;
393         }
394         return true;
395     }
396
397     /**
398      * 
399      * 
400      * @param out
401      * @throws org.exolab.castor.xml.MarshalException if object is
402      * null or if any SAXException is thrown during marshaling
403      * @throws org.exolab.castor.xml.ValidationException if this
404      * object is an invalid instance according to the schema
405      */
406     public void marshal(
407             final java.io.Writer out)
408     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
409         Marshaller.marshal(this, out);
410     }
411
412     /**
413      * 
414      * 
415      * @param handler
416      * @throws java.io.IOException if an IOException occurs during
417      * marshaling
418      * @throws org.exolab.castor.xml.ValidationException if this
419      * object is an invalid instance according to the schema
420      * @throws org.exolab.castor.xml.MarshalException if object is
421      * null or if any SAXException is thrown during marshaling
422      */
423     public void marshal(
424             final org.xml.sax.ContentHandler handler)
425     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
426         Marshaller.marshal(this, handler);
427     }
428
429     /**
430      */
431     public void removeAllFeatures(
432     ) {
433         this._featuresList.clear();
434     }
435
436     /**
437      */
438     public void removeAllPdbids(
439     ) {
440         this._pdbidsList.clear();
441     }
442
443     /**
444      * Method removeFeatures.
445      * 
446      * @param vFeatures
447      * @return true if the object was removed from the collection.
448      */
449     public boolean removeFeatures(
450             final jalview.binding.Features vFeatures) {
451         boolean removed = _featuresList.remove(vFeatures);
452         return removed;
453     }
454
455     /**
456      * Method removeFeaturesAt.
457      * 
458      * @param index
459      * @return the element removed from the collection
460      */
461     public jalview.binding.Features removeFeaturesAt(
462             final int index) {
463         java.lang.Object obj = this._featuresList.remove(index);
464         return (jalview.binding.Features) obj;
465     }
466
467     /**
468      * Method removePdbids.
469      * 
470      * @param vPdbids
471      * @return true if the object was removed from the collection.
472      */
473     public boolean removePdbids(
474             final jalview.binding.Pdbids vPdbids) {
475         boolean removed = _pdbidsList.remove(vPdbids);
476         return removed;
477     }
478
479     /**
480      * Method removePdbidsAt.
481      * 
482      * @param index
483      * @return the element removed from the collection
484      */
485     public jalview.binding.Pdbids removePdbidsAt(
486             final int index) {
487         java.lang.Object obj = this._pdbidsList.remove(index);
488         return (jalview.binding.Pdbids) obj;
489     }
490
491     /**
492      * Sets the value of field 'colour'.
493      * 
494      * @param colour the value of field 'colour'.
495      */
496     public void setColour(
497             final int colour) {
498         this._colour = colour;
499         this._has_colour = true;
500     }
501
502     /**
503      * Sets the value of field 'end'.
504      * 
505      * @param end the value of field 'end'.
506      */
507     public void setEnd(
508             final int end) {
509         this._end = end;
510         this._has_end = true;
511     }
512
513     /**
514      * 
515      * 
516      * @param index
517      * @param vFeatures
518      * @throws java.lang.IndexOutOfBoundsException if the index
519      * given is outside the bounds of the collection
520      */
521     public void setFeatures(
522             final int index,
523             final jalview.binding.Features vFeatures)
524     throws java.lang.IndexOutOfBoundsException {
525         // check bounds for index
526         if (index < 0 || index >= this._featuresList.size()) {
527             throw new IndexOutOfBoundsException("setFeatures: Index value '" + index + "' not in range [0.." + (this._featuresList.size() - 1) + "]");
528         }
529         
530         this._featuresList.set(index, vFeatures);
531     }
532
533     /**
534      * 
535      * 
536      * @param vFeaturesArray
537      */
538     public void setFeatures(
539             final jalview.binding.Features[] vFeaturesArray) {
540         //-- copy array
541         _featuresList.clear();
542         
543         for (int i = 0; i < vFeaturesArray.length; i++) {
544                 this._featuresList.add(vFeaturesArray[i]);
545         }
546     }
547
548     /**
549      * Sets the value of field 'id'.
550      * 
551      * @param id the value of field 'id'.
552      */
553     public void setId(
554             final int id) {
555         this._id = id;
556         this._has_id = true;
557     }
558
559     /**
560      * 
561      * 
562      * @param index
563      * @param vPdbids
564      * @throws java.lang.IndexOutOfBoundsException if the index
565      * given is outside the bounds of the collection
566      */
567     public void setPdbids(
568             final int index,
569             final jalview.binding.Pdbids vPdbids)
570     throws java.lang.IndexOutOfBoundsException {
571         // check bounds for index
572         if (index < 0 || index >= this._pdbidsList.size()) {
573             throw new IndexOutOfBoundsException("setPdbids: Index value '" + index + "' not in range [0.." + (this._pdbidsList.size() - 1) + "]");
574         }
575         
576         this._pdbidsList.set(index, vPdbids);
577     }
578
579     /**
580      * 
581      * 
582      * @param vPdbidsArray
583      */
584     public void setPdbids(
585             final jalview.binding.Pdbids[] vPdbidsArray) {
586         //-- copy array
587         _pdbidsList.clear();
588         
589         for (int i = 0; i < vPdbidsArray.length; i++) {
590                 this._pdbidsList.add(vPdbidsArray[i]);
591         }
592     }
593
594     /**
595      * Sets the value of field 'start'.
596      * 
597      * @param start the value of field 'start'.
598      */
599     public void setStart(
600             final int start) {
601         this._start = start;
602         this._has_start = true;
603     }
604
605     /**
606      * Method unmarshal.
607      * 
608      * @param reader
609      * @throws org.exolab.castor.xml.MarshalException if object is
610      * null or if any SAXException is thrown during marshaling
611      * @throws org.exolab.castor.xml.ValidationException if this
612      * object is an invalid instance according to the schema
613      * @return the unmarshaled jalview.binding.JSeq
614      */
615     public static jalview.binding.JSeq unmarshal(
616             final java.io.Reader reader)
617     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
618         return (jalview.binding.JSeq) Unmarshaller.unmarshal(jalview.binding.JSeq.class, reader);
619     }
620
621     /**
622      * 
623      * 
624      * @throws org.exolab.castor.xml.ValidationException if this
625      * object is an invalid instance according to the schema
626      */
627     public void validate(
628     )
629     throws org.exolab.castor.xml.ValidationException {
630         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
631         validator.validate(this);
632     }
633
634 }