| 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 | |
| 51 | public ParameterBlock() |
| 52 | { |
| 53 | this(new Vector(), new Vector()); |
| 54 | } |
| 55 | |
| 56 | public ParameterBlock(Vector sources) |
| 57 | { |
| 58 | this(sources, new Vector()); |
| 59 | } |
| 60 | |
| 61 | public ParameterBlock(Vector sources, Vector parameters) |
| 62 | { |
| 63 | this.sources = sources; |
| 64 | this.parameters = parameters; |
| 65 | } |
| 66 | |
| 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 | |
| 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 | |
| 89 | public ParameterBlock addSource(Object source) |
| 90 | { |
| 91 | sources.add(source); |
| 92 | return this; |
| 93 | } |
| 94 | |
| 95 | public Object getSource(int index) |
| 96 | { |
| 97 | return sources.get(index); |
| 98 | } |
| 99 | |
| 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 getSources() |
| 123 | { |
| 124 | return sources; |
| 125 | } |
| 126 | |
| 127 | public void setSources(Vector 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 getParameters() |
| 144 | { |
| 145 | return parameters; |
| 146 | } |
| 147 | |
| 148 | public void setParameters(Vector 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 |