001 /* ParameterBlock.java --
002 Copyright (C) 2002 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package java.awt.image.renderable;
040
041 import java.awt.image.RenderedImage;
042 import java.io.Serializable;
043 import java.util.Vector;
044
045 public class ParameterBlock implements Cloneable, Serializable
046 {
047 private static final long serialVersionUID = -7577115551785240750L;
048 protected Vector<Object> sources;
049 protected Vector<Object> parameters;
050
051 public ParameterBlock()
052 {
053 this(new Vector<Object>(), new Vector<Object>());
054 }
055
056 public ParameterBlock(Vector<Object> sources)
057 {
058 this(sources, new Vector<Object>());
059 }
060
061 public ParameterBlock(Vector<Object> sources, Vector<Object> parameters)
062 {
063 this.sources = sources;
064 this.parameters = parameters;
065 }
066
067 public Object shallowClone()
068 {
069 try
070 {
071 return super.clone();
072 }
073 catch (CloneNotSupportedException e)
074 {
075 throw (Error) new InternalError().initCause(e); // impossible
076 }
077 }
078
079 public Object clone()
080 {
081 ParameterBlock pb = (ParameterBlock) shallowClone();
082 if (sources != null)
083 pb.sources = (Vector<Object>) sources.clone();
084 if (parameters != null)
085 pb.parameters = (Vector<Object>) parameters.clone();
086 return pb;
087 }
088
089 public ParameterBlock addSource(Object source)
090 {
091 sources.add(source);
092 return this;
093 }
094
095 public Object getSource(int index)
096 {
097 return sources.get(index);
098 }
099
100 public ParameterBlock setSource(Object source, int index)
101 {
102 sources.ensureCapacity(index);
103 sources.set(index, source);
104 return this;
105 }
106
107 public RenderedImage getRenderedSource(int index)
108 {
109 return (RenderedImage) sources.get(index);
110 }
111
112 public RenderableImage getRenderableSource(int index)
113 {
114 return (RenderableImage) sources.get(index);
115 }
116
117 public int getNumSources()
118 {
119 return sources.size();
120 }
121
122 public Vector<Object> getSources()
123 {
124 return sources;
125 }
126
127 public void setSources(Vector<Object> sources)
128 {
129 this.sources = sources;
130 }
131
132 public void removeSources()
133 {
134 if (sources != null)
135 sources.clear();
136 }
137
138 public int getNumParameters()
139 {
140 return parameters.size();
141 }
142
143 public Vector<Object> getParameters()
144 {
145 return parameters;
146 }
147
148 public void setParameters(Vector<Object> parameters)
149 {
150 this.parameters = parameters;
151 }
152
153 public void removeParameters()
154 {
155 if (parameters != null)
156 parameters.clear();
157 }
158
159 public ParameterBlock add(Object o)
160 {
161 parameters.add(o);
162 return this;
163 }
164
165 public ParameterBlock add(byte b)
166 {
167 return add(new Byte(b));
168 }
169
170 public ParameterBlock add(char c)
171 {
172 return add(new Character(c));
173 }
174
175 public ParameterBlock add(short s)
176 {
177 return add(new Short(s));
178 }
179
180 public ParameterBlock add(int i)
181 {
182 return add(new Integer(i));
183 }
184
185 public ParameterBlock add(long l)
186 {
187 return add(new Long(l));
188 }
189
190 public ParameterBlock add(float f)
191 {
192 return add(new Float(f));
193 }
194
195 public ParameterBlock add(double d)
196 {
197 return add(new Double(d));
198 }
199
200 public ParameterBlock set(Object o, int index)
201 {
202 parameters.ensureCapacity(index);
203 parameters.set(index, o);
204 return this;
205 }
206
207 public ParameterBlock set(byte b, int index)
208 {
209 return set(new Byte(b), index);
210 }
211
212 public ParameterBlock set(char c, int index)
213 {
214 return set(new Character(c), index);
215 }
216
217 public ParameterBlock set(short s, int index)
218 {
219 return set(new Short(s), index);
220 }
221
222 public ParameterBlock set(int i, int index)
223 {
224 return set(new Integer(i), index);
225 }
226
227 public ParameterBlock set(long l, int index)
228 {
229 return set(new Long(l), index);
230 }
231
232 public ParameterBlock set(float f, int index)
233 {
234 return set(new Float(f), index);
235 }
236
237 public ParameterBlock set(double d, int index)
238 {
239 return set(new Double(d), index);
240 }
241
242 public Object getObjectParameter(int index)
243 {
244 return parameters.get(index);
245 }
246
247 public byte getByteParameter(int index)
248 {
249 return ((Byte) parameters.get(index)).byteValue();
250 }
251
252 public char getCharParameter(int index)
253 {
254 return ((Character) parameters.get(index)).charValue();
255 }
256
257 public short getShortParameter(int index)
258 {
259 return ((Short) parameters.get(index)).shortValue();
260 }
261
262 public int getIntParameter(int index)
263 {
264 return ((Integer) parameters.get(index)).intValue();
265 }
266
267 public long getLongParameter(int index)
268 {
269 return ((Long) parameters.get(index)).longValue();
270 }
271
272 public float getFloatParameter(int index)
273 {
274 return ((Float) parameters.get(index)).floatValue();
275 }
276
277 public double getDoubleParameter(int index)
278 {
279 return ((Double) parameters.get(index)).doubleValue();
280 }
281
282 public Class[] getParamClasses()
283 {
284 int i = parameters.size();
285 Class[] result = new Class[i];
286 while (--i >= 0)
287 {
288 Class c = parameters.get(i).getClass();
289 if (c == Byte.class)
290 result[i] = byte.class;
291 else if (c == Character.class)
292 result[i] = char.class;
293 else if (c == Short.class)
294 result[i] = short.class;
295 else if (c == Integer.class)
296 result[i] = int.class;
297 else if (c == Long.class)
298 result[i] = long.class;
299 else if (c == Float.class)
300 result[i] = float.class;
301 else if (c == Double.class)
302 result[i] = double.class;
303 else
304 result[i] = c;
305 }
306 return result;
307 }
308 } // class ParameterBlock