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
5 * This file is part of Jalview.
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.
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.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.binding;
20 //---------------------------------/
21 //- Imported classes and packages -/
22 //---------------------------------/
24 import org.exolab.castor.xml.Marshaller;
25 import org.exolab.castor.xml.Unmarshaller;
28 * Class JalviewModelSequence.
30 * @version $Revision$ $Date$
32 public class JalviewModelSequence implements java.io.Serializable
35 // --------------------------/
36 // - Class/Member Variables -/
37 // --------------------------/
42 private java.util.Vector _JSeqList;
47 private java.util.Vector _JGroupList;
50 * Field _viewportList.
52 private java.util.Vector _viewportList;
55 * Field _userColoursList.
57 private java.util.Vector _userColoursList;
62 private java.util.Vector _treeList;
65 * Field _featureSettings.
67 private jalview.binding.FeatureSettings _featureSettings;
73 public JalviewModelSequence()
76 this._JSeqList = new java.util.Vector();
77 this._JGroupList = new java.util.Vector();
78 this._viewportList = new java.util.Vector();
79 this._userColoursList = new java.util.Vector();
80 this._treeList = new java.util.Vector();
91 * @throws java.lang.IndexOutOfBoundsException
92 * if the index given is outside the bounds of the collection
94 public void addJGroup(final jalview.binding.JGroup vJGroup)
95 throws java.lang.IndexOutOfBoundsException
97 this._JGroupList.addElement(vJGroup);
105 * @throws java.lang.IndexOutOfBoundsException
106 * if the index given is outside the bounds of the collection
108 public void addJGroup(final int index,
109 final jalview.binding.JGroup vJGroup)
110 throws java.lang.IndexOutOfBoundsException
112 this._JGroupList.add(index, vJGroup);
119 * @throws java.lang.IndexOutOfBoundsException
120 * if the index given is outside the bounds of the collection
122 public void addJSeq(final jalview.binding.JSeq vJSeq)
123 throws java.lang.IndexOutOfBoundsException
125 this._JSeqList.addElement(vJSeq);
133 * @throws java.lang.IndexOutOfBoundsException
134 * if the index given is outside the bounds of the collection
136 public void addJSeq(final int index, final jalview.binding.JSeq vJSeq)
137 throws java.lang.IndexOutOfBoundsException
139 this._JSeqList.add(index, vJSeq);
146 * @throws java.lang.IndexOutOfBoundsException
147 * if the index given is outside the bounds of the collection
149 public void addTree(final jalview.binding.Tree vTree)
150 throws java.lang.IndexOutOfBoundsException
152 this._treeList.addElement(vTree);
160 * @throws java.lang.IndexOutOfBoundsException
161 * if the index given is outside the bounds of the collection
163 public void addTree(final int index, final jalview.binding.Tree vTree)
164 throws java.lang.IndexOutOfBoundsException
166 this._treeList.add(index, vTree);
172 * @param vUserColours
173 * @throws java.lang.IndexOutOfBoundsException
174 * if the index given is outside the bounds of the collection
176 public void addUserColours(final jalview.binding.UserColours vUserColours)
177 throws java.lang.IndexOutOfBoundsException
179 this._userColoursList.addElement(vUserColours);
186 * @param vUserColours
187 * @throws java.lang.IndexOutOfBoundsException
188 * if the index given is outside the bounds of the collection
190 public void addUserColours(final int index,
191 final jalview.binding.UserColours vUserColours)
192 throws java.lang.IndexOutOfBoundsException
194 this._userColoursList.add(index, vUserColours);
201 * @throws java.lang.IndexOutOfBoundsException
202 * if the index given is outside the bounds of the collection
204 public void addViewport(final jalview.binding.Viewport vViewport)
205 throws java.lang.IndexOutOfBoundsException
207 this._viewportList.addElement(vViewport);
215 * @throws java.lang.IndexOutOfBoundsException
216 * if the index given is outside the bounds of the collection
218 public void addViewport(final int index,
219 final jalview.binding.Viewport vViewport)
220 throws java.lang.IndexOutOfBoundsException
222 this._viewportList.add(index, vViewport);
226 * Method enumerateJGroup.
228 * @return an Enumeration over all jalview.binding.JGroup elements
230 public java.util.Enumeration enumerateJGroup()
232 return this._JGroupList.elements();
236 * Method enumerateJSeq.
238 * @return an Enumeration over all jalview.binding.JSeq elements
240 public java.util.Enumeration enumerateJSeq()
242 return this._JSeqList.elements();
246 * Method enumerateTree.
248 * @return an Enumeration over all jalview.binding.Tree elements
250 public java.util.Enumeration enumerateTree()
252 return this._treeList.elements();
256 * Method enumerateUserColours.
258 * @return an Enumeration over all jalview.binding.UserColours elements
260 public java.util.Enumeration enumerateUserColours()
262 return this._userColoursList.elements();
266 * Method enumerateViewport.
268 * @return an Enumeration over all jalview.binding.Viewport elements
270 public java.util.Enumeration enumerateViewport()
272 return this._viewportList.elements();
276 * Returns the value of field 'featureSettings'.
278 * @return the value of field 'FeatureSettings'.
280 public jalview.binding.FeatureSettings getFeatureSettings()
282 return this._featureSettings;
289 * @throws java.lang.IndexOutOfBoundsException
290 * if the index given is outside the bounds of the collection
291 * @return the value of the jalview.binding.JGroup at the given index
293 public jalview.binding.JGroup getJGroup(final int index)
294 throws java.lang.IndexOutOfBoundsException
296 // check bounds for index
297 if (index < 0 || index >= this._JGroupList.size())
299 throw new IndexOutOfBoundsException("getJGroup: Index value '"
300 + index + "' not in range [0.."
301 + (this._JGroupList.size() - 1) + "]");
304 return (jalview.binding.JGroup) _JGroupList.get(index);
308 * Method getJGroup.Returns the contents of the collection in an Array.
310 * Note: Just in case the collection contents are changing in another thread,
311 * we pass a 0-length Array of the correct type into the API call. This way we
312 * <i>know</i> that the Array returned is of exactly the correct length.
314 * @return this collection as an Array
316 public jalview.binding.JGroup[] getJGroup()
318 jalview.binding.JGroup[] array = new jalview.binding.JGroup[0];
319 return (jalview.binding.JGroup[]) this._JGroupList.toArray(array);
323 * Method getJGroupCount.
325 * @return the size of this collection
327 public int getJGroupCount()
329 return this._JGroupList.size();
336 * @throws java.lang.IndexOutOfBoundsException
337 * if the index given is outside the bounds of the collection
338 * @return the value of the jalview.binding.JSeq at the given index
340 public jalview.binding.JSeq getJSeq(final int index)
341 throws java.lang.IndexOutOfBoundsException
343 // check bounds for index
344 if (index < 0 || index >= this._JSeqList.size())
346 throw new IndexOutOfBoundsException("getJSeq: Index value '" + index
347 + "' not in range [0.." + (this._JSeqList.size() - 1) + "]");
350 return (jalview.binding.JSeq) _JSeqList.get(index);
354 * Method getJSeq.Returns the contents of the collection in an Array.
356 * Note: Just in case the collection contents are changing in another thread,
357 * we pass a 0-length Array of the correct type into the API call. This way we
358 * <i>know</i> that the Array returned is of exactly the correct length.
360 * @return this collection as an Array
362 public jalview.binding.JSeq[] getJSeq()
364 jalview.binding.JSeq[] array = new jalview.binding.JSeq[0];
365 return (jalview.binding.JSeq[]) this._JSeqList.toArray(array);
369 * Method getJSeqCount.
371 * @return the size of this collection
373 public int getJSeqCount()
375 return this._JSeqList.size();
382 * @throws java.lang.IndexOutOfBoundsException
383 * if the index given is outside the bounds of the collection
384 * @return the value of the jalview.binding.Tree at the given index
386 public jalview.binding.Tree getTree(final int index)
387 throws java.lang.IndexOutOfBoundsException
389 // check bounds for index
390 if (index < 0 || index >= this._treeList.size())
392 throw new IndexOutOfBoundsException("getTree: Index value '" + index
393 + "' not in range [0.." + (this._treeList.size() - 1) + "]");
396 return (jalview.binding.Tree) _treeList.get(index);
400 * Method getTree.Returns the contents of the collection in an Array.
402 * Note: Just in case the collection contents are changing in another thread,
403 * we pass a 0-length Array of the correct type into the API call. This way we
404 * <i>know</i> that the Array returned is of exactly the correct length.
406 * @return this collection as an Array
408 public jalview.binding.Tree[] getTree()
410 jalview.binding.Tree[] array = new jalview.binding.Tree[0];
411 return (jalview.binding.Tree[]) this._treeList.toArray(array);
415 * Method getTreeCount.
417 * @return the size of this collection
419 public int getTreeCount()
421 return this._treeList.size();
425 * Method getUserColours.
428 * @throws java.lang.IndexOutOfBoundsException
429 * if the index given is outside the bounds of the collection
430 * @return the value of the jalview.binding.UserColours at the given index
432 public jalview.binding.UserColours getUserColours(final int index)
433 throws java.lang.IndexOutOfBoundsException
435 // check bounds for index
436 if (index < 0 || index >= this._userColoursList.size())
438 throw new IndexOutOfBoundsException("getUserColours: Index value '"
439 + index + "' not in range [0.."
440 + (this._userColoursList.size() - 1) + "]");
443 return (jalview.binding.UserColours) _userColoursList.get(index);
447 * Method getUserColours.Returns the contents of the collection in an Array.
449 * Note: Just in case the collection contents are changing in another thread,
450 * we pass a 0-length Array of the correct type into the API call. This way we
451 * <i>know</i> that the Array returned is of exactly the correct length.
453 * @return this collection as an Array
455 public jalview.binding.UserColours[] getUserColours()
457 jalview.binding.UserColours[] array = new jalview.binding.UserColours[0];
458 return (jalview.binding.UserColours[]) this._userColoursList
463 * Method getUserColoursCount.
465 * @return the size of this collection
467 public int getUserColoursCount()
469 return this._userColoursList.size();
473 * Method getViewport.
476 * @throws java.lang.IndexOutOfBoundsException
477 * if the index given is outside the bounds of the collection
478 * @return the value of the jalview.binding.Viewport at the given index
480 public jalview.binding.Viewport getViewport(final int index)
481 throws java.lang.IndexOutOfBoundsException
483 // check bounds for index
484 if (index < 0 || index >= this._viewportList.size())
486 throw new IndexOutOfBoundsException("getViewport: Index value '"
487 + index + "' not in range [0.."
488 + (this._viewportList.size() - 1) + "]");
491 return (jalview.binding.Viewport) _viewportList.get(index);
495 * Method getViewport.Returns the contents of the collection in an Array.
497 * Note: Just in case the collection contents are changing in another thread,
498 * we pass a 0-length Array of the correct type into the API call. This way we
499 * <i>know</i> that the Array returned is of exactly the correct length.
501 * @return this collection as an Array
503 public jalview.binding.Viewport[] getViewport()
505 jalview.binding.Viewport[] array = new jalview.binding.Viewport[0];
506 return (jalview.binding.Viewport[]) this._viewportList.toArray(array);
510 * Method getViewportCount.
512 * @return the size of this collection
514 public int getViewportCount()
516 return this._viewportList.size();
522 * @return true if this object is valid according to the schema
524 public boolean isValid()
529 } catch (org.exolab.castor.xml.ValidationException vex)
540 * @throws org.exolab.castor.xml.MarshalException
541 * if object is null or if any SAXException is thrown during
543 * @throws org.exolab.castor.xml.ValidationException
544 * if this object is an invalid instance according to the schema
546 public void marshal(final java.io.Writer out)
547 throws org.exolab.castor.xml.MarshalException,
548 org.exolab.castor.xml.ValidationException
550 Marshaller.marshal(this, out);
557 * @throws java.io.IOException
558 * if an IOException occurs during marshaling
559 * @throws org.exolab.castor.xml.ValidationException
560 * if this object is an invalid instance according to the schema
561 * @throws org.exolab.castor.xml.MarshalException
562 * if object is null or if any SAXException is thrown during
565 public void marshal(final org.xml.sax.ContentHandler handler)
566 throws java.io.IOException,
567 org.exolab.castor.xml.MarshalException,
568 org.exolab.castor.xml.ValidationException
570 Marshaller.marshal(this, handler);
575 public void removeAllJGroup()
577 this._JGroupList.clear();
582 public void removeAllJSeq()
584 this._JSeqList.clear();
589 public void removeAllTree()
591 this._treeList.clear();
596 public void removeAllUserColours()
598 this._userColoursList.clear();
603 public void removeAllViewport()
605 this._viewportList.clear();
609 * Method removeJGroup.
612 * @return true if the object was removed from the collection.
614 public boolean removeJGroup(final jalview.binding.JGroup vJGroup)
616 boolean removed = _JGroupList.remove(vJGroup);
621 * Method removeJGroupAt.
624 * @return the element removed from the collection
626 public jalview.binding.JGroup removeJGroupAt(final int index)
628 java.lang.Object obj = this._JGroupList.remove(index);
629 return (jalview.binding.JGroup) obj;
636 * @return true if the object was removed from the collection.
638 public boolean removeJSeq(final jalview.binding.JSeq vJSeq)
640 boolean removed = _JSeqList.remove(vJSeq);
645 * Method removeJSeqAt.
648 * @return the element removed from the collection
650 public jalview.binding.JSeq removeJSeqAt(final int index)
652 java.lang.Object obj = this._JSeqList.remove(index);
653 return (jalview.binding.JSeq) obj;
660 * @return true if the object was removed from the collection.
662 public boolean removeTree(final jalview.binding.Tree vTree)
664 boolean removed = _treeList.remove(vTree);
669 * Method removeTreeAt.
672 * @return the element removed from the collection
674 public jalview.binding.Tree removeTreeAt(final int index)
676 java.lang.Object obj = this._treeList.remove(index);
677 return (jalview.binding.Tree) obj;
681 * Method removeUserColours.
683 * @param vUserColours
684 * @return true if the object was removed from the collection.
686 public boolean removeUserColours(
687 final jalview.binding.UserColours vUserColours)
689 boolean removed = _userColoursList.remove(vUserColours);
694 * Method removeUserColoursAt.
697 * @return the element removed from the collection
699 public jalview.binding.UserColours removeUserColoursAt(final int index)
701 java.lang.Object obj = this._userColoursList.remove(index);
702 return (jalview.binding.UserColours) obj;
706 * Method removeViewport.
709 * @return true if the object was removed from the collection.
711 public boolean removeViewport(final jalview.binding.Viewport vViewport)
713 boolean removed = _viewportList.remove(vViewport);
718 * Method removeViewportAt.
721 * @return the element removed from the collection
723 public jalview.binding.Viewport removeViewportAt(final int index)
725 java.lang.Object obj = this._viewportList.remove(index);
726 return (jalview.binding.Viewport) obj;
730 * Sets the value of field 'featureSettings'.
732 * @param featureSettings
733 * the value of field 'featureSettings'.
735 public void setFeatureSettings(
736 final jalview.binding.FeatureSettings featureSettings)
738 this._featureSettings = featureSettings;
746 * @throws java.lang.IndexOutOfBoundsException
747 * if the index given is outside the bounds of the collection
749 public void setJGroup(final int index,
750 final jalview.binding.JGroup vJGroup)
751 throws java.lang.IndexOutOfBoundsException
753 // check bounds for index
754 if (index < 0 || index >= this._JGroupList.size())
756 throw new IndexOutOfBoundsException("setJGroup: Index value '"
757 + index + "' not in range [0.."
758 + (this._JGroupList.size() - 1) + "]");
761 this._JGroupList.set(index, vJGroup);
767 * @param vJGroupArray
769 public void setJGroup(final jalview.binding.JGroup[] vJGroupArray)
774 for (int i = 0; i < vJGroupArray.length; i++)
776 this._JGroupList.add(vJGroupArray[i]);
785 * @throws java.lang.IndexOutOfBoundsException
786 * if the index given is outside the bounds of the collection
788 public void setJSeq(final int index, final jalview.binding.JSeq vJSeq)
789 throws java.lang.IndexOutOfBoundsException
791 // check bounds for index
792 if (index < 0 || index >= this._JSeqList.size())
794 throw new IndexOutOfBoundsException("setJSeq: Index value '" + index
795 + "' not in range [0.." + (this._JSeqList.size() - 1) + "]");
798 this._JSeqList.set(index, vJSeq);
806 public void setJSeq(final jalview.binding.JSeq[] vJSeqArray)
811 for (int i = 0; i < vJSeqArray.length; i++)
813 this._JSeqList.add(vJSeqArray[i]);
822 * @throws java.lang.IndexOutOfBoundsException
823 * if the index given is outside the bounds of the collection
825 public void setTree(final int index, final jalview.binding.Tree vTree)
826 throws java.lang.IndexOutOfBoundsException
828 // check bounds for index
829 if (index < 0 || index >= this._treeList.size())
831 throw new IndexOutOfBoundsException("setTree: Index value '" + index
832 + "' not in range [0.." + (this._treeList.size() - 1) + "]");
835 this._treeList.set(index, vTree);
843 public void setTree(final jalview.binding.Tree[] vTreeArray)
848 for (int i = 0; i < vTreeArray.length; i++)
850 this._treeList.add(vTreeArray[i]);
858 * @param vUserColours
859 * @throws java.lang.IndexOutOfBoundsException
860 * if the index given is outside the bounds of the collection
862 public void setUserColours(final int index,
863 final jalview.binding.UserColours vUserColours)
864 throws java.lang.IndexOutOfBoundsException
866 // check bounds for index
867 if (index < 0 || index >= this._userColoursList.size())
869 throw new IndexOutOfBoundsException("setUserColours: Index value '"
870 + index + "' not in range [0.."
871 + (this._userColoursList.size() - 1) + "]");
874 this._userColoursList.set(index, vUserColours);
880 * @param vUserColoursArray
882 public void setUserColours(
883 final jalview.binding.UserColours[] vUserColoursArray)
886 _userColoursList.clear();
888 for (int i = 0; i < vUserColoursArray.length; i++)
890 this._userColoursList.add(vUserColoursArray[i]);
899 * @throws java.lang.IndexOutOfBoundsException
900 * if the index given is outside the bounds of the collection
902 public void setViewport(final int index,
903 final jalview.binding.Viewport vViewport)
904 throws java.lang.IndexOutOfBoundsException
906 // check bounds for index
907 if (index < 0 || index >= this._viewportList.size())
909 throw new IndexOutOfBoundsException("setViewport: Index value '"
910 + index + "' not in range [0.."
911 + (this._viewportList.size() - 1) + "]");
914 this._viewportList.set(index, vViewport);
920 * @param vViewportArray
922 public void setViewport(final jalview.binding.Viewport[] vViewportArray)
925 _viewportList.clear();
927 for (int i = 0; i < vViewportArray.length; i++)
929 this._viewportList.add(vViewportArray[i]);
937 * @throws org.exolab.castor.xml.MarshalException
938 * if object is null or if any SAXException is thrown during
940 * @throws org.exolab.castor.xml.ValidationException
941 * if this object is an invalid instance according to the schema
942 * @return the unmarshaled jalview.binding.JalviewModelSequence
944 public static jalview.binding.JalviewModelSequence unmarshal(
945 final java.io.Reader reader)
946 throws org.exolab.castor.xml.MarshalException,
947 org.exolab.castor.xml.ValidationException
949 return (jalview.binding.JalviewModelSequence) Unmarshaller.unmarshal(
950 jalview.binding.JalviewModelSequence.class, reader);
956 * @throws org.exolab.castor.xml.ValidationException
957 * if this object is an invalid instance according to the schema
959 public void validate() throws org.exolab.castor.xml.ValidationException
961 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
962 validator.validate(this);