001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor V. Stolyarov
019: * @version $Revision$
020: */package java.awt.image.renderable;
021:
022: import java.awt.image.RenderedImage;
023: import java.io.Serializable;
024: import java.util.Vector;
025:
026: public class ParameterBlock implements Cloneable, Serializable {
027:
028: private static final long serialVersionUID = -7577115551785240750L;
029:
030: protected Vector<Object> sources = new Vector<Object>();
031:
032: protected Vector<Object> parameters = new Vector<Object>();
033:
034: public ParameterBlock(Vector<Object> sources,
035: Vector<Object> parameters) {
036: setSources(sources);
037: setParameters(parameters);
038: }
039:
040: public ParameterBlock(Vector<Object> sources) {
041: setSources(sources);
042: }
043:
044: public ParameterBlock() {
045: }
046:
047: public ParameterBlock setSource(Object source, int index) {
048: if (sources.size() < index + 1) {
049: sources.setSize(index + 1);
050: }
051: sources.setElementAt(source, index);
052: return this ;
053: }
054:
055: public ParameterBlock set(Object obj, int index) {
056: if (parameters.size() < index + 1) {
057: parameters.setSize(index + 1);
058: }
059: parameters.setElementAt(obj, index);
060: return this ;
061: }
062:
063: public ParameterBlock addSource(Object source) {
064: sources.addElement(source);
065: return this ;
066: }
067:
068: public ParameterBlock add(Object obj) {
069: parameters.addElement(obj);
070: return this ;
071: }
072:
073: public void setSources(Vector<Object> sources) {
074: this .sources = sources;
075: }
076:
077: public void setParameters(Vector<Object> parameters) {
078: this .parameters = parameters;
079: }
080:
081: public Vector<Object> getSources() {
082: return sources;
083: }
084:
085: public Vector<Object> getParameters() {
086: return parameters;
087: }
088:
089: public Object getSource(int index) {
090: return sources.elementAt(index);
091: }
092:
093: public Object getObjectParameter(int index) {
094: return parameters.elementAt(index);
095: }
096:
097: public Object shallowClone() {
098: try {
099: return super .clone();
100: } catch (Exception e) {
101: return null;
102: }
103: }
104:
105: @SuppressWarnings("unchecked")
106: @Override
107: public Object clone() {
108: ParameterBlock replica;
109: try {
110: replica = (ParameterBlock) super .clone();
111: } catch (Exception e) {
112: return null;
113: }
114: if (sources != null) {
115: replica.setSources((Vector<Object>) (sources.clone()));
116: }
117: if (parameters != null) {
118: replica
119: .setParameters((Vector<Object>) (parameters.clone()));
120: }
121: return replica;
122: }
123:
124: public Class[] getParamClasses() {
125: int count = parameters.size();
126: Class paramClasses[] = new Class[count];
127:
128: for (int i = 0; i < count; i++) {
129: paramClasses[i] = parameters.elementAt(i).getClass();
130: }
131: return paramClasses;
132: }
133:
134: public RenderableImage getRenderableSource(int index) {
135: return (RenderableImage) sources.elementAt(index);
136: }
137:
138: public ParameterBlock set(short s, int index) {
139: return set(new Short(s), index);
140: }
141:
142: public ParameterBlock add(short s) {
143: return add(new Short(s));
144: }
145:
146: public ParameterBlock set(long l, int index) {
147: return set(new Long(l), index);
148: }
149:
150: public ParameterBlock add(long l) {
151: return add(new Long(l));
152: }
153:
154: public ParameterBlock set(int i, int index) {
155: return set(new Integer(i), index);
156: }
157:
158: public ParameterBlock add(int i) {
159: return add(new Integer(i));
160: }
161:
162: public ParameterBlock set(float f, int index) {
163: return set(new Float(f), index);
164: }
165:
166: public ParameterBlock add(float f) {
167: return add(new Float(f));
168: }
169:
170: public ParameterBlock set(double d, int index) {
171: return set(new Double(d), index);
172: }
173:
174: public ParameterBlock add(double d) {
175: return add(new Double(d));
176: }
177:
178: public ParameterBlock set(char c, int index) {
179: return set(new Character(c), index);
180: }
181:
182: public ParameterBlock add(char c) {
183: return add(new Character(c));
184: }
185:
186: public ParameterBlock set(byte b, int index) {
187: return set(new Byte(b), index);
188: }
189:
190: public ParameterBlock add(byte b) {
191: return add(new Byte(b));
192: }
193:
194: public RenderedImage getRenderedSource(int index) {
195: return (RenderedImage) sources.elementAt(index);
196: }
197:
198: public short getShortParameter(int index) {
199: return ((Short) parameters.elementAt(index)).shortValue();
200: }
201:
202: public long getLongParameter(int index) {
203: return ((Long) parameters.elementAt(index)).longValue();
204: }
205:
206: public int getIntParameter(int index) {
207: return ((Integer) parameters.elementAt(index)).intValue();
208: }
209:
210: public float getFloatParameter(int index) {
211: return ((Float) parameters.elementAt(index)).floatValue();
212: }
213:
214: public double getDoubleParameter(int index) {
215: return ((Double) parameters.elementAt(index)).doubleValue();
216: }
217:
218: public char getCharParameter(int index) {
219: return ((Character) parameters.elementAt(index)).charValue();
220: }
221:
222: public byte getByteParameter(int index) {
223: return ((Byte) parameters.elementAt(index)).byteValue();
224: }
225:
226: public void removeSources() {
227: sources.removeAllElements();
228: }
229:
230: public void removeParameters() {
231: parameters.removeAllElements();
232: }
233:
234: public int getNumSources() {
235: return sources.size();
236: }
237:
238: public int getNumParameters() {
239: return parameters.size();
240: }
241: }
|