2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
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.
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.
21 package jalview.binding;
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
27 import jalview.util.MessageManager;
29 import org.exolab.castor.xml.Marshaller;
30 import org.exolab.castor.xml.Unmarshaller;
33 * Class JalviewModelSequence.
35 * @version $Revision$ $Date$
37 public class JalviewModelSequence implements java.io.Serializable
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private java.util.Vector _JSeqList;
52 private java.util.Vector _JGroupList;
55 * Field _viewportList.
57 private java.util.Vector _viewportList;
60 * Field _userColoursList.
62 private java.util.Vector _userColoursList;
67 private java.util.Vector _treeList;
70 * Field _featureSettings.
72 private jalview.binding.FeatureSettings _featureSettings;
78 public JalviewModelSequence()
81 this._JSeqList = new java.util.Vector();
82 this._JGroupList = new java.util.Vector();
83 this._viewportList = new java.util.Vector();
84 this._userColoursList = new java.util.Vector();
85 this._treeList = new java.util.Vector();
96 * @throws java.lang.IndexOutOfBoundsException
97 * if the index given is outside the bounds of the collection
99 public void addJGroup(final jalview.binding.JGroup vJGroup)
100 throws java.lang.IndexOutOfBoundsException
102 this._JGroupList.addElement(vJGroup);
110 * @throws java.lang.IndexOutOfBoundsException
111 * if the index given is outside the bounds of the collection
113 public void addJGroup(final int index,
114 final jalview.binding.JGroup vJGroup)
115 throws java.lang.IndexOutOfBoundsException
117 this._JGroupList.add(index, vJGroup);
124 * @throws java.lang.IndexOutOfBoundsException
125 * if the index given is outside the bounds of the collection
127 public void addJSeq(final jalview.binding.JSeq vJSeq)
128 throws java.lang.IndexOutOfBoundsException
130 this._JSeqList.addElement(vJSeq);
138 * @throws java.lang.IndexOutOfBoundsException
139 * if the index given is outside the bounds of the collection
141 public void addJSeq(final int index, final jalview.binding.JSeq vJSeq)
142 throws java.lang.IndexOutOfBoundsException
144 this._JSeqList.add(index, vJSeq);
151 * @throws java.lang.IndexOutOfBoundsException
152 * if the index given is outside the bounds of the collection
154 public void addTree(final jalview.binding.Tree vTree)
155 throws java.lang.IndexOutOfBoundsException
157 this._treeList.addElement(vTree);
165 * @throws java.lang.IndexOutOfBoundsException
166 * if the index given is outside the bounds of the collection
168 public void addTree(final int index, final jalview.binding.Tree vTree)
169 throws java.lang.IndexOutOfBoundsException
171 this._treeList.add(index, vTree);
177 * @param vUserColours
178 * @throws java.lang.IndexOutOfBoundsException
179 * if the index given is outside the bounds of the collection
181 public void addUserColours(final jalview.binding.UserColours vUserColours)
182 throws java.lang.IndexOutOfBoundsException
184 this._userColoursList.addElement(vUserColours);
191 * @param vUserColours
192 * @throws java.lang.IndexOutOfBoundsException
193 * if the index given is outside the bounds of the collection
195 public void addUserColours(final int index,
196 final jalview.binding.UserColours vUserColours)
197 throws java.lang.IndexOutOfBoundsException
199 this._userColoursList.add(index, vUserColours);
206 * @throws java.lang.IndexOutOfBoundsException
207 * if the index given is outside the bounds of the collection
209 public void addViewport(final jalview.binding.Viewport vViewport)
210 throws java.lang.IndexOutOfBoundsException
212 this._viewportList.addElement(vViewport);
220 * @throws java.lang.IndexOutOfBoundsException
221 * if the index given is outside the bounds of the collection
223 public void addViewport(final int index,
224 final jalview.binding.Viewport vViewport)
225 throws java.lang.IndexOutOfBoundsException
227 this._viewportList.add(index, vViewport);
231 * Method enumerateJGroup.
233 * @return an Enumeration over all jalview.binding.JGroup elements
235 public java.util.Enumeration enumerateJGroup()
237 return this._JGroupList.elements();
241 * Method enumerateJSeq.
243 * @return an Enumeration over all jalview.binding.JSeq elements
245 public java.util.Enumeration enumerateJSeq()
247 return this._JSeqList.elements();
251 * Method enumerateTree.
253 * @return an Enumeration over all jalview.binding.Tree elements
255 public java.util.Enumeration enumerateTree()
257 return this._treeList.elements();
261 * Method enumerateUserColours.
263 * @return an Enumeration over all jalview.binding.UserColours elements
265 public java.util.Enumeration enumerateUserColours()
267 return this._userColoursList.elements();
271 * Method enumerateViewport.
273 * @return an Enumeration over all jalview.binding.Viewport elements
275 public java.util.Enumeration enumerateViewport()
277 return this._viewportList.elements();
281 * Returns the value of field 'featureSettings'.
283 * @return the value of field 'FeatureSettings'.
285 public jalview.binding.FeatureSettings getFeatureSettings()
287 return this._featureSettings;
294 * @throws java.lang.IndexOutOfBoundsException
295 * if the index given is outside the bounds of the collection
296 * @return the value of the jalview.binding.JGroup at the given index
298 public jalview.binding.JGroup getJGroup(final int index)
299 throws java.lang.IndexOutOfBoundsException
301 // check bounds for index
302 if (index < 0 || index >= this._JGroupList.size())
304 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
306 Integer.valueOf(index).toString(),
307 Integer.valueOf((this._JGroupList.size() - 1)).toString()
311 return (jalview.binding.JGroup) _JGroupList.get(index);
315 * Method getJGroup.Returns the contents of the collection in an Array.
317 * Note: Just in case the collection contents are changing in another thread,
318 * we pass a 0-length Array of the correct type into the API call. This way we
319 * <i>know</i> that the Array returned is of exactly the correct length.
321 * @return this collection as an Array
323 public jalview.binding.JGroup[] getJGroup()
325 jalview.binding.JGroup[] array = new jalview.binding.JGroup[0];
326 return (jalview.binding.JGroup[]) this._JGroupList.toArray(array);
330 * Method getJGroupCount.
332 * @return the size of this collection
334 public int getJGroupCount()
336 return this._JGroupList.size();
343 * @throws java.lang.IndexOutOfBoundsException
344 * if the index given is outside the bounds of the collection
345 * @return the value of the jalview.binding.JSeq at the given index
347 public jalview.binding.JSeq getJSeq(final int index)
348 throws java.lang.IndexOutOfBoundsException
350 // check bounds for index
351 if (index < 0 || index >= this._JSeqList.size())
353 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
355 Integer.valueOf(index).toString(),
356 Integer.valueOf((this._JSeqList.size() - 1)).toString()
360 return (jalview.binding.JSeq) _JSeqList.get(index);
364 * Method getJSeq.Returns the contents of the collection in an Array.
366 * Note: Just in case the collection contents are changing in another thread,
367 * we pass a 0-length Array of the correct type into the API call. This way we
368 * <i>know</i> that the Array returned is of exactly the correct length.
370 * @return this collection as an Array
372 public jalview.binding.JSeq[] getJSeq()
374 jalview.binding.JSeq[] array = new jalview.binding.JSeq[0];
375 return (jalview.binding.JSeq[]) this._JSeqList.toArray(array);
379 * Method getJSeqCount.
381 * @return the size of this collection
383 public int getJSeqCount()
385 return this._JSeqList.size();
392 * @throws java.lang.IndexOutOfBoundsException
393 * if the index given is outside the bounds of the collection
394 * @return the value of the jalview.binding.Tree at the given index
396 public jalview.binding.Tree getTree(final int index)
397 throws java.lang.IndexOutOfBoundsException
399 // check bounds for index
400 if (index < 0 || index >= this._treeList.size())
402 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
404 Integer.valueOf(index).toString(),
405 Integer.valueOf((this._treeList.size() - 1)).toString()
409 return (jalview.binding.Tree) _treeList.get(index);
413 * Method getTree.Returns the contents of the collection in an Array.
415 * Note: Just in case the collection contents are changing in another thread,
416 * we pass a 0-length Array of the correct type into the API call. This way we
417 * <i>know</i> that the Array returned is of exactly the correct length.
419 * @return this collection as an Array
421 public jalview.binding.Tree[] getTree()
423 jalview.binding.Tree[] array = new jalview.binding.Tree[0];
424 return (jalview.binding.Tree[]) this._treeList.toArray(array);
428 * Method getTreeCount.
430 * @return the size of this collection
432 public int getTreeCount()
434 return this._treeList.size();
438 * Method getUserColours.
441 * @throws java.lang.IndexOutOfBoundsException
442 * if the index given is outside the bounds of the collection
443 * @return the value of the jalview.binding.UserColours at the given index
445 public jalview.binding.UserColours getUserColours(final int index)
446 throws java.lang.IndexOutOfBoundsException
448 // check bounds for index
449 if (index < 0 || index >= this._userColoursList.size())
451 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
453 Integer.valueOf(index).toString(),
454 Integer.valueOf((this._userColoursList.size() - 1)).toString()
458 return (jalview.binding.UserColours) _userColoursList.get(index);
462 * Method getUserColours.Returns the contents of the collection in an Array.
464 * Note: Just in case the collection contents are changing in another thread,
465 * we pass a 0-length Array of the correct type into the API call. This way we
466 * <i>know</i> that the Array returned is of exactly the correct length.
468 * @return this collection as an Array
470 public jalview.binding.UserColours[] getUserColours()
472 jalview.binding.UserColours[] array = new jalview.binding.UserColours[0];
473 return (jalview.binding.UserColours[]) this._userColoursList
478 * Method getUserColoursCount.
480 * @return the size of this collection
482 public int getUserColoursCount()
484 return this._userColoursList.size();
488 * Method getViewport.
491 * @throws java.lang.IndexOutOfBoundsException
492 * if the index given is outside the bounds of the collection
493 * @return the value of the jalview.binding.Viewport at the given index
495 public jalview.binding.Viewport getViewport(final int index)
496 throws java.lang.IndexOutOfBoundsException
498 // check bounds for index
499 if (index < 0 || index >= this._viewportList.size())
501 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
503 Integer.valueOf(index).toString(),
504 Integer.valueOf((this._viewportList.size() - 1)).toString()
508 return (jalview.binding.Viewport) _viewportList.get(index);
512 * Method getViewport.Returns the contents of the collection in an Array.
514 * Note: Just in case the collection contents are changing in another thread,
515 * we pass a 0-length Array of the correct type into the API call. This way we
516 * <i>know</i> that the Array returned is of exactly the correct length.
518 * @return this collection as an Array
520 public jalview.binding.Viewport[] getViewport()
522 jalview.binding.Viewport[] array = new jalview.binding.Viewport[0];
523 return (jalview.binding.Viewport[]) this._viewportList.toArray(array);
527 * Method getViewportCount.
529 * @return the size of this collection
531 public int getViewportCount()
533 return this._viewportList.size();
539 * @return true if this object is valid according to the schema
541 public boolean isValid()
546 } catch (org.exolab.castor.xml.ValidationException vex)
557 * @throws org.exolab.castor.xml.MarshalException
558 * if object is null or if any SAXException is thrown during
560 * @throws org.exolab.castor.xml.ValidationException
561 * if this object is an invalid instance according to the schema
563 public void marshal(final java.io.Writer out)
564 throws org.exolab.castor.xml.MarshalException,
565 org.exolab.castor.xml.ValidationException
567 Marshaller.marshal(this, out);
574 * @throws java.io.IOException
575 * if an IOException occurs during marshaling
576 * @throws org.exolab.castor.xml.ValidationException
577 * if this object is an invalid instance according to the schema
578 * @throws org.exolab.castor.xml.MarshalException
579 * if object is null or if any SAXException is thrown during
582 public void marshal(final org.xml.sax.ContentHandler handler)
583 throws java.io.IOException,
584 org.exolab.castor.xml.MarshalException,
585 org.exolab.castor.xml.ValidationException
587 Marshaller.marshal(this, handler);
592 public void removeAllJGroup()
594 this._JGroupList.clear();
599 public void removeAllJSeq()
601 this._JSeqList.clear();
606 public void removeAllTree()
608 this._treeList.clear();
613 public void removeAllUserColours()
615 this._userColoursList.clear();
620 public void removeAllViewport()
622 this._viewportList.clear();
626 * Method removeJGroup.
629 * @return true if the object was removed from the collection.
631 public boolean removeJGroup(final jalview.binding.JGroup vJGroup)
633 boolean removed = _JGroupList.remove(vJGroup);
638 * Method removeJGroupAt.
641 * @return the element removed from the collection
643 public jalview.binding.JGroup removeJGroupAt(final int index)
645 java.lang.Object obj = this._JGroupList.remove(index);
646 return (jalview.binding.JGroup) obj;
653 * @return true if the object was removed from the collection.
655 public boolean removeJSeq(final jalview.binding.JSeq vJSeq)
657 boolean removed = _JSeqList.remove(vJSeq);
662 * Method removeJSeqAt.
665 * @return the element removed from the collection
667 public jalview.binding.JSeq removeJSeqAt(final int index)
669 java.lang.Object obj = this._JSeqList.remove(index);
670 return (jalview.binding.JSeq) obj;
677 * @return true if the object was removed from the collection.
679 public boolean removeTree(final jalview.binding.Tree vTree)
681 boolean removed = _treeList.remove(vTree);
686 * Method removeTreeAt.
689 * @return the element removed from the collection
691 public jalview.binding.Tree removeTreeAt(final int index)
693 java.lang.Object obj = this._treeList.remove(index);
694 return (jalview.binding.Tree) obj;
698 * Method removeUserColours.
700 * @param vUserColours
701 * @return true if the object was removed from the collection.
703 public boolean removeUserColours(
704 final jalview.binding.UserColours vUserColours)
706 boolean removed = _userColoursList.remove(vUserColours);
711 * Method removeUserColoursAt.
714 * @return the element removed from the collection
716 public jalview.binding.UserColours removeUserColoursAt(final int index)
718 java.lang.Object obj = this._userColoursList.remove(index);
719 return (jalview.binding.UserColours) obj;
723 * Method removeViewport.
726 * @return true if the object was removed from the collection.
728 public boolean removeViewport(final jalview.binding.Viewport vViewport)
730 boolean removed = _viewportList.remove(vViewport);
735 * Method removeViewportAt.
738 * @return the element removed from the collection
740 public jalview.binding.Viewport removeViewportAt(final int index)
742 java.lang.Object obj = this._viewportList.remove(index);
743 return (jalview.binding.Viewport) obj;
747 * Sets the value of field 'featureSettings'.
749 * @param featureSettings
750 * the value of field 'featureSettings'.
752 public void setFeatureSettings(
753 final jalview.binding.FeatureSettings featureSettings)
755 this._featureSettings = featureSettings;
763 * @throws java.lang.IndexOutOfBoundsException
764 * if the index given is outside the bounds of the collection
766 public void setJGroup(final int index,
767 final jalview.binding.JGroup vJGroup)
768 throws java.lang.IndexOutOfBoundsException
770 // check bounds for index
771 if (index < 0 || index >= this._JGroupList.size())
773 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
775 Integer.valueOf(index).toString(),
776 Integer.valueOf((this._JGroupList.size() - 1)).toString()
780 this._JGroupList.set(index, vJGroup);
786 * @param vJGroupArray
788 public void setJGroup(final jalview.binding.JGroup[] vJGroupArray)
793 for (int i = 0; i < vJGroupArray.length; i++)
795 this._JGroupList.add(vJGroupArray[i]);
804 * @throws java.lang.IndexOutOfBoundsException
805 * if the index given is outside the bounds of the collection
807 public void setJSeq(final int index, final jalview.binding.JSeq vJSeq)
808 throws java.lang.IndexOutOfBoundsException
810 // check bounds for index
811 if (index < 0 || index >= this._JSeqList.size())
813 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
815 Integer.valueOf(index).toString(),
816 Integer.valueOf((this._JSeqList.size() - 1)).toString()
820 this._JSeqList.set(index, vJSeq);
828 public void setJSeq(final jalview.binding.JSeq[] vJSeqArray)
833 for (int i = 0; i < vJSeqArray.length; i++)
835 this._JSeqList.add(vJSeqArray[i]);
844 * @throws java.lang.IndexOutOfBoundsException
845 * if the index given is outside the bounds of the collection
847 public void setTree(final int index, final jalview.binding.Tree vTree)
848 throws java.lang.IndexOutOfBoundsException
850 // check bounds for index
851 if (index < 0 || index >= this._treeList.size())
853 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
855 Integer.valueOf(index).toString(),
856 Integer.valueOf((this._treeList.size() - 1)).toString()
860 this._treeList.set(index, vTree);
868 public void setTree(final jalview.binding.Tree[] vTreeArray)
873 for (int i = 0; i < vTreeArray.length; i++)
875 this._treeList.add(vTreeArray[i]);
883 * @param vUserColours
884 * @throws java.lang.IndexOutOfBoundsException
885 * if the index given is outside the bounds of the collection
887 public void setUserColours(final int index,
888 final jalview.binding.UserColours vUserColours)
889 throws java.lang.IndexOutOfBoundsException
891 // check bounds for index
892 if (index < 0 || index >= this._userColoursList.size())
894 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
896 Integer.valueOf(index).toString(),
897 Integer.valueOf((this._userColoursList.size() - 1)).toString()
901 this._userColoursList.set(index, vUserColours);
907 * @param vUserColoursArray
909 public void setUserColours(
910 final jalview.binding.UserColours[] vUserColoursArray)
913 _userColoursList.clear();
915 for (int i = 0; i < vUserColoursArray.length; i++)
917 this._userColoursList.add(vUserColoursArray[i]);
926 * @throws java.lang.IndexOutOfBoundsException
927 * if the index given is outside the bounds of the collection
929 public void setViewport(final int index,
930 final jalview.binding.Viewport vViewport)
931 throws java.lang.IndexOutOfBoundsException
933 // check bounds for index
934 if (index < 0 || index >= this._viewportList.size())
936 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
938 Integer.valueOf(index).toString(),
939 Integer.valueOf((this._viewportList.size() - 1)).toString()
943 this._viewportList.set(index, vViewport);
949 * @param vViewportArray
951 public void setViewport(final jalview.binding.Viewport[] vViewportArray)
954 _viewportList.clear();
956 for (int i = 0; i < vViewportArray.length; i++)
958 this._viewportList.add(vViewportArray[i]);
966 * @throws org.exolab.castor.xml.MarshalException
967 * if object is null or if any SAXException is thrown during
969 * @throws org.exolab.castor.xml.ValidationException
970 * if this object is an invalid instance according to the schema
971 * @return the unmarshaled jalview.binding.JalviewModelSequence
973 public static jalview.binding.JalviewModelSequence unmarshal(
974 final java.io.Reader reader)
975 throws org.exolab.castor.xml.MarshalException,
976 org.exolab.castor.xml.ValidationException
978 return (jalview.binding.JalviewModelSequence) Unmarshaller.unmarshal(
979 jalview.binding.JalviewModelSequence.class, reader);
985 * @throws org.exolab.castor.xml.ValidationException
986 * if this object is an invalid instance according to the schema
988 public void validate() throws org.exolab.castor.xml.ValidationException
990 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
991 validator.validate(this);