extended Colour element with additional optional attributes for graduated colour
[jalview.git] / src / jalview / binding / FeatureSettings.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 FeatureSettings.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class FeatureSettings implements java.io.Serializable {
34
35
36       //--------------------------/
37      //- Class/Member Variables -/
38     //--------------------------/
39
40     /**
41      * Field _settingList.
42      */
43     private java.util.Vector _settingList;
44
45
46       //----------------/
47      //- Constructors -/
48     //----------------/
49
50     public FeatureSettings() {
51         super();
52         this._settingList = new java.util.Vector();
53     }
54
55
56       //-----------/
57      //- Methods -/
58     //-----------/
59
60     /**
61      * 
62      * 
63      * @param vSetting
64      * @throws java.lang.IndexOutOfBoundsException if the index
65      * given is outside the bounds of the collection
66      */
67     public void addSetting(
68             final jalview.binding.Setting vSetting)
69     throws java.lang.IndexOutOfBoundsException {
70         this._settingList.addElement(vSetting);
71     }
72
73     /**
74      * 
75      * 
76      * @param index
77      * @param vSetting
78      * @throws java.lang.IndexOutOfBoundsException if the index
79      * given is outside the bounds of the collection
80      */
81     public void addSetting(
82             final int index,
83             final jalview.binding.Setting vSetting)
84     throws java.lang.IndexOutOfBoundsException {
85         this._settingList.add(index, vSetting);
86     }
87
88     /**
89      * Method enumerateSetting.
90      * 
91      * @return an Enumeration over all jalview.binding.Setting
92      * elements
93      */
94     public java.util.Enumeration enumerateSetting(
95     ) {
96         return this._settingList.elements();
97     }
98
99     /**
100      * Method getSetting.
101      * 
102      * @param index
103      * @throws java.lang.IndexOutOfBoundsException if the index
104      * given is outside the bounds of the collection
105      * @return the value of the jalview.binding.Setting at the
106      * given index
107      */
108     public jalview.binding.Setting getSetting(
109             final int index)
110     throws java.lang.IndexOutOfBoundsException {
111         // check bounds for index
112         if (index < 0 || index >= this._settingList.size()) {
113             throw new IndexOutOfBoundsException("getSetting: Index value '" + index + "' not in range [0.." + (this._settingList.size() - 1) + "]");
114         }
115         
116         return (jalview.binding.Setting) _settingList.get(index);
117     }
118
119     /**
120      * Method getSetting.Returns the contents of the collection in
121      * an Array.  <p>Note:  Just in case the collection contents
122      * are changing in another thread, we pass a 0-length Array of
123      * the correct type into the API call.  This way we <i>know</i>
124      * that the Array returned is of exactly the correct length.
125      * 
126      * @return this collection as an Array
127      */
128     public jalview.binding.Setting[] getSetting(
129     ) {
130         jalview.binding.Setting[] array = new jalview.binding.Setting[0];
131         return (jalview.binding.Setting[]) this._settingList.toArray(array);
132     }
133
134     /**
135      * Method getSettingCount.
136      * 
137      * @return the size of this collection
138      */
139     public int getSettingCount(
140     ) {
141         return this._settingList.size();
142     }
143
144     /**
145      * Method isValid.
146      * 
147      * @return true if this object is valid according to the schema
148      */
149     public boolean isValid(
150     ) {
151         try {
152             validate();
153         } catch (org.exolab.castor.xml.ValidationException vex) {
154             return false;
155         }
156         return true;
157     }
158
159     /**
160      * 
161      * 
162      * @param out
163      * @throws org.exolab.castor.xml.MarshalException if object is
164      * null or if any SAXException is thrown during marshaling
165      * @throws org.exolab.castor.xml.ValidationException if this
166      * object is an invalid instance according to the schema
167      */
168     public void marshal(
169             final java.io.Writer out)
170     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
171         Marshaller.marshal(this, out);
172     }
173
174     /**
175      * 
176      * 
177      * @param handler
178      * @throws java.io.IOException if an IOException occurs during
179      * marshaling
180      * @throws org.exolab.castor.xml.ValidationException if this
181      * object is an invalid instance according to the schema
182      * @throws org.exolab.castor.xml.MarshalException if object is
183      * null or if any SAXException is thrown during marshaling
184      */
185     public void marshal(
186             final org.xml.sax.ContentHandler handler)
187     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
188         Marshaller.marshal(this, handler);
189     }
190
191     /**
192      */
193     public void removeAllSetting(
194     ) {
195         this._settingList.clear();
196     }
197
198     /**
199      * Method removeSetting.
200      * 
201      * @param vSetting
202      * @return true if the object was removed from the collection.
203      */
204     public boolean removeSetting(
205             final jalview.binding.Setting vSetting) {
206         boolean removed = _settingList.remove(vSetting);
207         return removed;
208     }
209
210     /**
211      * Method removeSettingAt.
212      * 
213      * @param index
214      * @return the element removed from the collection
215      */
216     public jalview.binding.Setting removeSettingAt(
217             final int index) {
218         java.lang.Object obj = this._settingList.remove(index);
219         return (jalview.binding.Setting) obj;
220     }
221
222     /**
223      * 
224      * 
225      * @param index
226      * @param vSetting
227      * @throws java.lang.IndexOutOfBoundsException if the index
228      * given is outside the bounds of the collection
229      */
230     public void setSetting(
231             final int index,
232             final jalview.binding.Setting vSetting)
233     throws java.lang.IndexOutOfBoundsException {
234         // check bounds for index
235         if (index < 0 || index >= this._settingList.size()) {
236             throw new IndexOutOfBoundsException("setSetting: Index value '" + index + "' not in range [0.." + (this._settingList.size() - 1) + "]");
237         }
238         
239         this._settingList.set(index, vSetting);
240     }
241
242     /**
243      * 
244      * 
245      * @param vSettingArray
246      */
247     public void setSetting(
248             final jalview.binding.Setting[] vSettingArray) {
249         //-- copy array
250         _settingList.clear();
251         
252         for (int i = 0; i < vSettingArray.length; i++) {
253                 this._settingList.add(vSettingArray[i]);
254         }
255     }
256
257     /**
258      * Method unmarshal.
259      * 
260      * @param reader
261      * @throws org.exolab.castor.xml.MarshalException if object is
262      * null or if any SAXException is thrown during marshaling
263      * @throws org.exolab.castor.xml.ValidationException if this
264      * object is an invalid instance according to the schema
265      * @return the unmarshaled jalview.binding.FeatureSettings
266      */
267     public static jalview.binding.FeatureSettings unmarshal(
268             final java.io.Reader reader)
269     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
270         return (jalview.binding.FeatureSettings) Unmarshaller.unmarshal(jalview.binding.FeatureSettings.class, reader);
271     }
272
273     /**
274      * 
275      * 
276      * @throws org.exolab.castor.xml.ValidationException if this
277      * object is an invalid instance according to the schema
278      */
279     public void validate(
280     )
281     throws org.exolab.castor.xml.ValidationException {
282         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
283         validator.validate(this);
284     }
285
286 }