Home » openjdk-7 » java » awt » image » renderable » [javadoc | source]
java.awt.image.renderable
public class: ParameterBlock [javadoc | source]
java.lang.Object
   java.awt.image.renderable.ParameterBlock

All Implemented Interfaces:
    Cloneable, java$io$Serializable

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));
Field Summary
protected  Vector<Object> sources    A Vector of sources, stored as arbitrary Objects. 
protected  Vector<Object> parameters    A Vector of non-source parameters, stored as arbitrary Objects. 
Constructor:
 public ParameterBlock() 
 public ParameterBlock(Vector<Object> sources) 
    Constructs a ParameterBlock with a given Vector of sources.
    Parameters:
    sources - a Vector of source images
 public ParameterBlock(Vector<Object> sources,
    Vector<Object> parameters) 
    Constructs a ParameterBlock with a given Vector of sources and Vector of parameters.
    Parameters:
    sources - a Vector of source images
    parameters - a Vector of parameters to be used in the rendering operation
Method from java.awt.image.renderable.ParameterBlock Summary:
add,   add,   add,   add,   add,   add,   add,   add,   addSource,   clone,   getByteParameter,   getCharParameter,   getDoubleParameter,   getFloatParameter,   getIntParameter,   getLongParameter,   getNumParameters,   getNumSources,   getObjectParameter,   getParamClasses,   getParameters,   getRenderableSource,   getRenderedSource,   getShortParameter,   getSource,   getSources,   removeParameters,   removeSources,   set,   set,   set,   set,   set,   set,   set,   set,   setParameters,   setSource,   setSources,   shallowClone
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.image.renderable.ParameterBlock Detail:
 public ParameterBlock add(Object obj) 
    Adds an object to the list of parameters.
 public ParameterBlock add(byte b) 
    Adds a Byte to the list of parameters.
 public ParameterBlock add(char c) 
    Adds a Character to the list of parameters.
 public ParameterBlock add(short s) 
    Adds a Short to the list of parameters.
 public ParameterBlock add(int i) 
    Adds a Integer to the list of parameters.
 public ParameterBlock add(long l) 
    Adds a Long to the list of parameters.
 public ParameterBlock add(float f) 
    Adds a Float to the list of parameters.
 public ParameterBlock add(double d) 
    Adds a Double to the list of parameters.
 public ParameterBlock addSource(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.
 public Object clone() 
    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.
 public byte getByteParameter(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.
 public char getCharParameter(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.
 public double getDoubleParameter(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.
 public float getFloatParameter(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.
 public int getIntParameter(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.
 public long getLongParameter(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.
 public int getNumParameters() 
    Returns the number of parameters (not including source images).
 public int getNumSources() 
    Returns the number of source images.
 public Object getObjectParameter(int index) 
    Gets a parameter as an object.
 public Class[] getParamClasses() 
    Returns an array of Class objects describing the types of the parameters.
 public Vector<Object> getParameters() 
    Returns the entire Vector of parameters.
 public RenderableImage getRenderableSource(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.
 public RenderedImage getRenderedSource(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.
 public short getShortParameter(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.
 public Object getSource(int index) 
    Returns a source as a general Object. The caller must cast it into an appropriate type.
 public Vector<Object> getSources() 
    Returns the entire Vector of sources.
 public  void removeParameters() 
    Clears the list of parameters.
 public  void removeSources() 
    Clears the list of source images.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public ParameterBlock set(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.
 public  void setParameters(Vector<Object> parameters) 
    Sets the entire Vector of parameters to a given Vector.
 public ParameterBlock setSource(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.
 public  void setSources(Vector<Object> sources) 
    Sets the entire Vector of sources to a given Vector.
 public Object shallowClone() 
    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.