2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 FeatureSettings.
35 * @version $Revision$ $Date$
37 public class FeatureSettings implements java.io.Serializable
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private java.util.Vector _settingList;
53 public FeatureSettings()
56 this._settingList = new java.util.Vector();
67 * @throws java.lang.IndexOutOfBoundsException
68 * if the index given is outside the bounds of the collection
70 public void addSetting(final jalview.binding.Setting vSetting)
71 throws java.lang.IndexOutOfBoundsException
73 this._settingList.addElement(vSetting);
81 * @throws java.lang.IndexOutOfBoundsException
82 * if the index given is outside the bounds of the collection
84 public void addSetting(final int index,
85 final jalview.binding.Setting vSetting)
86 throws java.lang.IndexOutOfBoundsException
88 this._settingList.add(index, vSetting);
92 * Method enumerateSetting.
94 * @return an Enumeration over all jalview.binding.Setting elements
96 public java.util.Enumeration enumerateSetting()
98 return this._settingList.elements();
105 * @throws java.lang.IndexOutOfBoundsException
106 * if the index given is outside the bounds of the collection
107 * @return the value of the jalview.binding.Setting at the given index
109 public jalview.binding.Setting getSetting(final int index)
110 throws java.lang.IndexOutOfBoundsException
112 // check bounds for index
113 if (index < 0 || index >= this._settingList.size())
115 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
117 Integer.valueOf(index).toString(),
118 Integer.valueOf((this._settingList.size() - 1)).toString()
122 return (jalview.binding.Setting) _settingList.get(index);
126 * Method getSetting.Returns the contents of the collection in an Array.
128 * Note: Just in case the collection contents are changing in another thread,
129 * we pass a 0-length Array of the correct type into the API call. This way we
130 * <i>know</i> that the Array returned is of exactly the correct length.
132 * @return this collection as an Array
134 public jalview.binding.Setting[] getSetting()
136 jalview.binding.Setting[] array = new jalview.binding.Setting[0];
137 return (jalview.binding.Setting[]) this._settingList.toArray(array);
141 * Method getSettingCount.
143 * @return the size of this collection
145 public int getSettingCount()
147 return this._settingList.size();
153 * @return true if this object is valid according to the schema
155 public boolean isValid()
160 } catch (org.exolab.castor.xml.ValidationException vex)
171 * @throws org.exolab.castor.xml.MarshalException
172 * if object is null or if any SAXException is thrown during
174 * @throws org.exolab.castor.xml.ValidationException
175 * if this object is an invalid instance according to the schema
177 public void marshal(final java.io.Writer out)
178 throws org.exolab.castor.xml.MarshalException,
179 org.exolab.castor.xml.ValidationException
181 Marshaller.marshal(this, out);
188 * @throws java.io.IOException
189 * if an IOException occurs during marshaling
190 * @throws org.exolab.castor.xml.ValidationException
191 * if this object is an invalid instance according to the schema
192 * @throws org.exolab.castor.xml.MarshalException
193 * if object is null or if any SAXException is thrown during
196 public void marshal(final org.xml.sax.ContentHandler handler)
197 throws java.io.IOException,
198 org.exolab.castor.xml.MarshalException,
199 org.exolab.castor.xml.ValidationException
201 Marshaller.marshal(this, handler);
206 public void removeAllSetting()
208 this._settingList.clear();
212 * Method removeSetting.
215 * @return true if the object was removed from the collection.
217 public boolean removeSetting(final jalview.binding.Setting vSetting)
219 boolean removed = _settingList.remove(vSetting);
224 * Method removeSettingAt.
227 * @return the element removed from the collection
229 public jalview.binding.Setting removeSettingAt(final int index)
231 java.lang.Object obj = this._settingList.remove(index);
232 return (jalview.binding.Setting) obj;
240 * @throws java.lang.IndexOutOfBoundsException
241 * if the index given is outside the bounds of the collection
243 public void setSetting(final int index,
244 final jalview.binding.Setting vSetting)
245 throws java.lang.IndexOutOfBoundsException
247 // check bounds for index
248 if (index < 0 || index >= this._settingList.size())
250 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
252 Integer.valueOf(index).toString(),
253 Integer.valueOf((this._settingList.size() - 1)).toString()
257 this._settingList.set(index, vSetting);
263 * @param vSettingArray
265 public void setSetting(final jalview.binding.Setting[] vSettingArray)
268 _settingList.clear();
270 for (int i = 0; i < vSettingArray.length; i++)
272 this._settingList.add(vSettingArray[i]);
280 * @throws org.exolab.castor.xml.MarshalException
281 * if object is null or if any SAXException is thrown during
283 * @throws org.exolab.castor.xml.ValidationException
284 * if this object is an invalid instance according to the schema
285 * @return the unmarshaled jalview.binding.FeatureSettings
287 public static jalview.binding.FeatureSettings unmarshal(
288 final java.io.Reader reader)
289 throws org.exolab.castor.xml.MarshalException,
290 org.exolab.castor.xml.ValidationException
292 return (jalview.binding.FeatureSettings) Unmarshaller.unmarshal(
293 jalview.binding.FeatureSettings.class, reader);
299 * @throws org.exolab.castor.xml.ValidationException
300 * if this object is an invalid instance according to the schema
302 public void validate() throws org.exolab.castor.xml.ValidationException
304 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
305 validator.validate(this);