2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / image / renderable / ParameterBlock.java
bloba54209d32d5b4d904c4cf083b12bca44fe508ba9
1 /* ParameterBlock.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.image.renderable;
41 import java.awt.image.RenderedImage;
42 import java.io.Serializable;
43 import java.util.Vector;
45 public class ParameterBlock implements Cloneable, Serializable
47 private static final long serialVersionUID = -7577115551785240750L;
48 protected Vector sources;
49 protected Vector parameters;
51 public ParameterBlock()
53 this(new Vector(), new Vector());
56 public ParameterBlock(Vector sources)
58 this(sources, new Vector());
61 public ParameterBlock(Vector sources, Vector parameters)
63 this.sources = sources;
64 this.parameters = parameters;
67 public Object shallowClone()
69 try
71 return super.clone();
73 catch (CloneNotSupportedException e)
75 throw (Error) new InternalError().initCause(e); // impossible
79 public Object clone()
81 ParameterBlock pb = (ParameterBlock) shallowClone();
82 if (sources != null)
83 pb.sources = (Vector) sources.clone();
84 if (parameters != null)
85 pb.parameters = (Vector) parameters.clone();
86 return pb;
89 public ParameterBlock addSource(Object source)
91 sources.add(source);
92 return this;
95 public Object getSource(int index)
97 return sources.get(index);
100 public ParameterBlock setSource(Object source, int index)
102 sources.ensureCapacity(index);
103 sources.set(index, source);
104 return this;
107 public RenderedImage getRenderedSource(int index)
109 return (RenderedImage) sources.get(index);
112 public RenderableImage getRenderableSource(int index)
114 return (RenderableImage) sources.get(index);
117 public int getNumSources()
119 return sources.size();
122 public Vector getSources()
124 return sources;
127 public void setSources(Vector sources)
129 this.sources = sources;
132 public void removeSources()
134 if (sources != null)
135 sources.clear();
138 public int getNumParameters()
140 return parameters.size();
143 public Vector getParameters()
145 return parameters;
148 public void setParameters(Vector parameters)
150 this.parameters = parameters;
153 public void removeParameters()
155 if (parameters != null)
156 parameters.clear();
159 public ParameterBlock add(Object o)
161 parameters.add(o);
162 return this;
165 public ParameterBlock add(byte b)
167 return add(new Byte(b));
170 public ParameterBlock add(char c)
172 return add(new Character(c));
175 public ParameterBlock add(short s)
177 return add(new Short(s));
180 public ParameterBlock add(int i)
182 return add(new Integer(i));
185 public ParameterBlock add(long l)
187 return add(new Long(l));
190 public ParameterBlock add(float f)
192 return add(new Float(f));
195 public ParameterBlock add(double d)
197 return add(new Double(d));
200 public ParameterBlock set(Object o, int index)
202 parameters.ensureCapacity(index);
203 parameters.set(index, o);
204 return this;
207 public ParameterBlock set(byte b, int index)
209 return set(new Byte(b), index);
212 public ParameterBlock set(char c, int index)
214 return set(new Character(c), index);
217 public ParameterBlock set(short s, int index)
219 return set(new Short(s), index);
222 public ParameterBlock set(int i, int index)
224 return set(new Integer(i), index);
227 public ParameterBlock set(long l, int index)
229 return set(new Long(l), index);
232 public ParameterBlock set(float f, int index)
234 return set(new Float(f), index);
237 public ParameterBlock set(double d, int index)
239 return set(new Double(d), index);
242 public Object getObjectParameter(int index)
244 return parameters.get(index);
247 public byte getByteParameter(int index)
249 return ((Byte) parameters.get(index)).byteValue();
252 public char getCharParameter(int index)
254 return ((Character) parameters.get(index)).charValue();
257 public short getShortParameter(int index)
259 return ((Short) parameters.get(index)).shortValue();
262 public int getIntParameter(int index)
264 return ((Integer) parameters.get(index)).intValue();
267 public long getLongParameter(int index)
269 return ((Long) parameters.get(index)).longValue();
272 public float getFloatParameter(int index)
274 return ((Float) parameters.get(index)).floatValue();
277 public double getDoubleParameter(int index)
279 return ((Double) parameters.get(index)).doubleValue();
282 public Class[] getParamClasses()
284 int i = parameters.size();
285 Class[] result = new Class[i];
286 while (--i >= 0)
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;
306 return result;
308 } // class ParameterBlock