FileDocCategorySizeDatePackage
ParameterBlock.javaAPI DocJava SE 5 API26518Fri Aug 26 14:56:56 BST 2005java.awt.image.renderable

ParameterBlock

public class ParameterBlock extends Object implements Serializable, Cloneable
A ParameterBlock encapsulates all the information about sources and parameters (Objects) required by a RenderableImageOp, or other classes that process images.

Although it is possible to place arbitrary objects in the source Vector, users of this class may impose semantic constraints such as requiring all sources to be RenderedImages or RenderableImage. ParameterBlock itself is merely a container and performs no checking on source or parameter types.

All parameters in a ParameterBlock are objects; convenience add and set methods are available that take arguments of base type and construct the appropriate subclass of Number (such as Integer or Float). Corresponding get methods perform a downward cast and have return values of base type; an exception will be thrown if the stored values do not have the correct type. There is no way to distinguish between the results of "short s; add(s)" and "add(new Short(s))".

Note that the get and set methods operate on references. Therefore, one must be careful not to share references between ParameterBlocks when this is inappropriate. For example, to create a new ParameterBlock that is equal to an old one except for an added source, one might be tempted to write:

ParameterBlock addSource(ParameterBlock pb, RenderableImage im) {
ParameterBlock pb1 = new ParameterBlock(pb.getSources());
pb1.addSource(im);
return pb1;
}

This code will have the side effect of altering the original ParameterBlock, since the getSources operation returned a reference to its source Vector. Both pb and pb1 share their source Vector, and a change in either is visible to both.

A correct way to write the addSource function is to clone the source Vector:

ParameterBlock addSource (ParameterBlock pb, RenderableImage im) {
ParameterBlock pb1 = new ParameterBlock(pb.getSources().clone());
pb1.addSource(im);
return pb1;
}

The clone method of ParameterBlock has been defined to perform a clone of both the source and parameter Vectors for this reason. A standard, shallow clone is available as shallowClone.

The addSource, setSource, add, and set methods are defined to return 'this' after adding their argument. This allows use of syntax like:

ParameterBlock pb = new ParameterBlock();
op = new RenderableImageOp("operation", pb.add(arg1).add(arg2));

Fields Summary
protected Vector
sources
A Vector of sources, stored as arbitrary Objects.
protected Vector
parameters
A Vector of non-source parameters, stored as arbitrary Objects.
Constructors Summary
public ParameterBlock()
A dummy constructor.


        
      
public ParameterBlock(Vector sources)
Constructs a ParameterBlock with a given Vector of sources.

param
sources a Vector of source images

        setSources(sources);
    
public ParameterBlock(Vector sources, Vector parameters)
Constructs a ParameterBlock with a given Vector of sources and Vector of parameters.

param
sources a Vector of source images
param
parameters a Vector of parameters to be used in the rendering operation

        setSources(sources);
        setParameters(parameters);
    
Methods Summary
public java.awt.image.renderable.ParameterBlockadd(java.lang.Object obj)
Adds an object to the list of parameters.

param
obj the Object to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        parameters.addElement(obj);
        return this;
    
public java.awt.image.renderable.ParameterBlockadd(byte b)
Adds a Byte to the list of parameters.

param
b the byte to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Byte(b));
    
public java.awt.image.renderable.ParameterBlockadd(char c)
Adds a Character to the list of parameters.

param
c the char to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Character(c));
    
public java.awt.image.renderable.ParameterBlockadd(short s)
Adds a Short to the list of parameters.

param
s the short to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Short(s));
    
public java.awt.image.renderable.ParameterBlockadd(int i)
Adds a Integer to the list of parameters.

param
i the int to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Integer(i));
    
public java.awt.image.renderable.ParameterBlockadd(long l)
Adds a Long to the list of parameters.

param
l the long to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Long(l));
    
public java.awt.image.renderable.ParameterBlockadd(float f)
Adds a Float to the list of parameters.

param
f the float to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Float(f));
    
public java.awt.image.renderable.ParameterBlockadd(double d)
Adds a Double to the list of parameters.

param
d the double to add to the parameters Vector
return
a new ParameterBlock containing the specified parameter.

        return add(new Double(d));
    
public java.awt.image.renderable.ParameterBlockaddSource(java.lang.Object source)
Adds an image to end of the list of sources. The image is stored as an object in order to allow new node types in the future.

param
source an image object to be stored in the source list.
return
a new ParameterBlock containing the specified source.

        sources.addElement(source);
        return this;
    
public java.lang.Objectclone()
Creates a copy of a ParameterBlock. The source and parameter Vectors are cloned, but the actual sources and parameters are copied by reference. This allows modifications to the order and number of sources and parameters in the clone to be invisible to the original ParameterBlock. Changes to the shared sources or parameters themselves will still be visible.

return
an Object clone of the ParameterBlock.

        ParameterBlock theClone;

        try {
            theClone = (ParameterBlock) super.clone();
        } catch (Exception e) {
            // We can't be here since we implement Cloneable.
            return null;
        }

        if (sources != null) {
            theClone.setSources((Vector)sources.clone());
        }
        if (parameters != null) {
            theClone.setParameters((Vector)parameters.clone());
        }
        return (Object) theClone;
    
public bytegetByteParameter(int index)
A convenience method to return a parameter as a byte. An exception is thrown if the parameter is null or not a Byte.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a byte value.
throws
ClassCastException if the parameter at the specified index is not a Byte
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Byte)parameters.elementAt(index)).byteValue();
    
public chargetCharParameter(int index)
A convenience method to return a parameter as a char. An exception is thrown if the parameter is null or not a Character.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a char value.
throws
ClassCastException if the parameter at the specified index is not a Character
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Character)parameters.elementAt(index)).charValue();
    
public doublegetDoubleParameter(int index)
A convenience method to return a parameter as a double. An exception is thrown if the parameter is null or not a Double.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a double value.
throws
ClassCastException if the parameter at the specified index is not a Double
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Double)parameters.elementAt(index)).doubleValue();
    
public floatgetFloatParameter(int index)
A convenience method to return a parameter as a float. An exception is thrown if the parameter is null or not a Float.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a float value.
throws
ClassCastException if the parameter at the specified index is not a Float
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Float)parameters.elementAt(index)).floatValue();
    
public intgetIntParameter(int index)
A convenience method to return a parameter as an int. An exception is thrown if the parameter is null or not an Integer.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a int value.
throws
ClassCastException if the parameter at the specified index is not a Integer
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Integer)parameters.elementAt(index)).intValue();
    
public longgetLongParameter(int index)
A convenience method to return a parameter as a long. An exception is thrown if the parameter is null or not a Long.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a long value.
throws
ClassCastException if the parameter at the specified index is not a Long
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Long)parameters.elementAt(index)).longValue();
    
public intgetNumParameters()
Returns the number of parameters (not including source images).

return
the number of parameters in the parameters Vector.

        return parameters.size();
    
public intgetNumSources()
Returns the number of source images.

return
the number of source images in the sources Vector.

        return sources.size();
    
public java.lang.ObjectgetObjectParameter(int index)
Gets a parameter as an object.

param
index the index of the parameter to get
return
an Object representing the the parameter at the specified index into the parameters Vector.

        return parameters.elementAt(index);
    
public java.lang.Class[]getParamClasses()
Returns an array of Class objects describing the types of the parameters.

return
an array of Class objects.

        int numParams = getNumParameters();
        Class [] classes = new Class[numParams];
        int i;

        for (i = 0; i < numParams; i++) {
            Object obj = getObjectParameter(i);
            if (obj instanceof Byte) {
              classes[i] = byte.class;
            } else if (obj instanceof Character) {
              classes[i] = char.class;
            } else if (obj instanceof Short) {
              classes[i] = short.class;
            } else if (obj instanceof Integer) {
              classes[i] = int.class;
            } else if (obj instanceof Long) {
              classes[i] = long.class;
            } else if (obj instanceof Float) {
              classes[i] = float.class;
            } else if (obj instanceof Double) {
              classes[i] = double.class;
            } else {
              classes[i] = obj.getClass();
            }
        }
        
        return classes;
    
public java.util.VectorgetParameters()
Returns the entire Vector of parameters.

return
the parameters Vector.
see
#setParameters(Vector)

        return parameters;
    
public java.awt.image.renderable.RenderableImagegetRenderableSource(int index)
Returns a source as a RenderableImage. This method is a convenience method. An exception will be thrown if the sources is not a RenderableImage.

param
index the index of the source to be returned
return
a RenderableImage that represents the source image that is at the specified index in the sources Vector.

        return (RenderableImage) sources.elementAt(index);
    
public java.awt.image.RenderedImagegetRenderedSource(int index)
Returns a source as a RenderedImage. This method is a convenience method. An exception will be thrown if the source is not a RenderedImage.

param
index the index of the source to be returned
return
a RenderedImage that represents the source image that is at the specified index in the sources Vector.

        return (RenderedImage) sources.elementAt(index);
    
public shortgetShortParameter(int index)
A convenience method to return a parameter as a short. An exception is thrown if the parameter is null or not a Short.

param
index the index of the parameter to be returned.
return
the parameter at the specified index as a short value.
throws
ClassCastException if the parameter at the specified index is not a Short
throws
NullPointerException if the parameter at the specified index is null
throws
ArrayIndexOutOfBoundsException if index is negative or not less than the current size of this ParameterBlock object

        return ((Short)parameters.elementAt(index)).shortValue();
    
public java.lang.ObjectgetSource(int index)
Returns a source as a general Object. The caller must cast it into an appropriate type.

param
index the index of the source to be returned.
return
an Object that represents the source located at the specified index in the sources Vector.
see
#setSource(Object, int)

        return sources.elementAt(index);
    
public java.util.VectorgetSources()
Returns the entire Vector of sources.

return
the sources Vector.
see
#setSources(Vector)

        return sources;
    
public voidremoveParameters()
Clears the list of parameters.

        parameters = new Vector();
    
public voidremoveSources()
Clears the list of source images.

        sources = new Vector();
    
public java.awt.image.renderable.ParameterBlockset(java.lang.Object obj, int index)
Replaces an Object in the list of parameters. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
obj the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        int oldSize = parameters.size();
        int newSize = index + 1;
        if (oldSize < newSize) {
            parameters.setSize(newSize);
        }
        parameters.setElementAt(obj, index);
        return this;
    
public java.awt.image.renderable.ParameterBlockset(byte b, int index)
Replaces an Object in the list of parameters with a Byte. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
b the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Byte(b), index);
    
public java.awt.image.renderable.ParameterBlockset(char c, int index)
Replaces an Object in the list of parameters with a Character. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
c the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Character(c), index);
    
public java.awt.image.renderable.ParameterBlockset(short s, int index)
Replaces an Object in the list of parameters with a Short. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
s the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Short(s), index);
    
public java.awt.image.renderable.ParameterBlockset(int i, int index)
Replaces an Object in the list of parameters with an Integer. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
i the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Integer(i), index);
    
public java.awt.image.renderable.ParameterBlockset(long l, int index)
Replaces an Object in the list of parameters with a Long. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
l the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Long(l), index);
    
public java.awt.image.renderable.ParameterBlockset(float f, int index)
Replaces an Object in the list of parameters with a Float. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
f the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Float(f), index);
    
public java.awt.image.renderable.ParameterBlockset(double d, int index)
Replaces an Object in the list of parameters with a Double. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
d the parameter that replaces the parameter at the specified index in the parameters Vector
param
index the index of the parameter to be replaced with the specified parameter
return
a new ParameterBlock containing the specified parameter.

        return set(new Double(d), index);
    
public voidsetParameters(java.util.Vector parameters)
Sets the entire Vector of parameters to a given Vector.

param
parameters the specified Vector of parameters
see
#getParameters

        this.parameters = parameters;
    
public java.awt.image.renderable.ParameterBlocksetSource(java.lang.Object source, int index)
Replaces an entry in the list of source with a new source. If the index lies beyond the current source list, the list is extended with nulls as needed.

param
source the specified source image
param
index the index into the sources Vector at which to insert the specified source
return
a new ParameterBlock that contains the specified source at the specified index.
see
#getSource(int)

        int oldSize = sources.size();
        int newSize = index + 1;
        if (oldSize < newSize) {
            sources.setSize(newSize);
        }
        sources.setElementAt(source, index);
        return this;
    
public voidsetSources(java.util.Vector sources)
Sets the entire Vector of sources to a given Vector.

param
sources the Vector of source images
see
#getSources

        this.sources = sources;
    
public java.lang.ObjectshallowClone()
Creates a shallow copy of a ParameterBlock. The source and parameter Vectors are copied by reference -- additions or changes will be visible to both versions.

return
an Object clone of the ParameterBlock.

        try {
            return super.clone();
        } catch (Exception e) {
            // We can't be here since we implement Cloneable.
            return null;
        }