1 /* ParameterBlock.java --
2    Copyright (C) 2002 Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
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.
10 
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.
15 
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20 
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.
25 
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. */
37 
38 
39 package java.awt.image.renderable;
40 
41 import java.awt.image.RenderedImage;
42 import java.io.Serializable;
43 import java.util.Vector;
44 
45 public class ParameterBlock implements Cloneable, Serializable
46 {
47   private static final long serialVersionUID = -7577115551785240750L;
48   protected Vector sources;
49   protected Vector parameters;
50 
ParameterBlock()51   public ParameterBlock()
52   {
53     this(new Vector(), new Vector());
54   }
55 
ParameterBlock(Vector sources)56   public ParameterBlock(Vector sources)
57   {
58     this(sources, new Vector());
59   }
60 
ParameterBlock(Vector sources, Vector parameters)61   public ParameterBlock(Vector sources, Vector parameters)
62   {
63     this.sources = sources;
64     this.parameters = parameters;
65   }
66 
shallowClone()67   public Object shallowClone()
68   {
69     try
70       {
71         return super.clone();
72       }
73     catch (CloneNotSupportedException e)
74       {
75         throw (Error) new InternalError().initCause(e); // impossible
76       }
77   }
78 
clone()79   public Object clone()
80   {
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;
87   }
88 
addSource(Object source)89   public ParameterBlock addSource(Object source)
90   {
91     sources.add(source);
92     return this;
93   }
94 
getSource(int index)95   public Object getSource(int index)
96   {
97     return sources.get(index);
98   }
99 
setSource(Object source, int index)100   public ParameterBlock setSource(Object source, int index)
101   {
102     sources.ensureCapacity(index);
103     sources.set(index, source);
104     return this;
105   }
106 
getRenderedSource(int index)107   public RenderedImage getRenderedSource(int index)
108   {
109     return (RenderedImage) sources.get(index);
110   }
111 
getRenderableSource(int index)112   public RenderableImage getRenderableSource(int index)
113   {
114     return (RenderableImage) sources.get(index);
115   }
116 
getNumSources()117   public int getNumSources()
118   {
119     return sources.size();
120   }
121 
getSources()122   public Vector getSources()
123   {
124     return sources;
125   }
126 
setSources(Vector sources)127   public void setSources(Vector sources)
128   {
129     this.sources = sources;
130   }
131 
removeSources()132   public void removeSources()
133   {
134     if (sources != null)
135       sources.clear();
136   }
137 
getNumParameters()138   public int getNumParameters()
139   {
140     return parameters.size();
141   }
142 
getParameters()143   public Vector getParameters()
144   {
145     return parameters;
146   }
147 
setParameters(Vector parameters)148   public void setParameters(Vector parameters)
149   {
150     this.parameters = parameters;
151   }
152 
removeParameters()153   public void removeParameters()
154   {
155     if (parameters != null)
156       parameters.clear();
157   }
158 
add(Object o)159   public ParameterBlock add(Object o)
160   {
161     parameters.add(o);
162     return this;
163   }
164 
add(byte b)165   public ParameterBlock add(byte b)
166   {
167     return add(new Byte(b));
168   }
169 
add(char c)170   public ParameterBlock add(char c)
171   {
172     return add(new Character(c));
173   }
174 
add(short s)175   public ParameterBlock add(short s)
176   {
177     return add(new Short(s));
178   }
179 
add(int i)180   public ParameterBlock add(int i)
181   {
182     return add(new Integer(i));
183   }
184 
add(long l)185   public ParameterBlock add(long l)
186   {
187     return add(new Long(l));
188   }
189 
add(float f)190   public ParameterBlock add(float f)
191   {
192     return add(new Float(f));
193   }
194 
add(double d)195   public ParameterBlock add(double d)
196   {
197     return add(new Double(d));
198   }
199 
set(Object o, int index)200   public ParameterBlock set(Object o, int index)
201   {
202     parameters.ensureCapacity(index);
203     parameters.set(index, o);
204     return this;
205   }
206 
set(byte b, int index)207   public ParameterBlock set(byte b, int index)
208   {
209     return set(new Byte(b), index);
210   }
211 
set(char c, int index)212   public ParameterBlock set(char c, int index)
213   {
214     return set(new Character(c), index);
215   }
216 
set(short s, int index)217   public ParameterBlock set(short s, int index)
218   {
219     return set(new Short(s), index);
220   }
221 
set(int i, int index)222   public ParameterBlock set(int i, int index)
223   {
224     return set(new Integer(i), index);
225   }
226 
set(long l, int index)227   public ParameterBlock set(long l, int index)
228   {
229     return set(new Long(l), index);
230   }
231 
set(float f, int index)232   public ParameterBlock set(float f, int index)
233   {
234     return set(new Float(f), index);
235   }
236 
set(double d, int index)237   public ParameterBlock set(double d, int index)
238   {
239     return set(new Double(d), index);
240   }
241 
getObjectParameter(int index)242   public Object getObjectParameter(int index)
243   {
244     return parameters.get(index);
245   }
246 
getByteParameter(int index)247   public byte getByteParameter(int index)
248   {
249     return ((Byte) parameters.get(index)).byteValue();
250   }
251 
getCharParameter(int index)252   public char getCharParameter(int index)
253   {
254     return ((Character) parameters.get(index)).charValue();
255   }
256 
getShortParameter(int index)257   public short getShortParameter(int index)
258   {
259     return ((Short) parameters.get(index)).shortValue();
260   }
261 
getIntParameter(int index)262   public int getIntParameter(int index)
263   {
264     return ((Integer) parameters.get(index)).intValue();
265   }
266 
getLongParameter(int index)267   public long getLongParameter(int index)
268   {
269     return ((Long) parameters.get(index)).longValue();
270   }
271 
getFloatParameter(int index)272   public float getFloatParameter(int index)
273   {
274     return ((Float) parameters.get(index)).floatValue();
275   }
276 
getDoubleParameter(int index)277   public double getDoubleParameter(int index)
278   {
279     return ((Double) parameters.get(index)).doubleValue();
280   }
281 
getParamClasses()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
309