java.lang.Object
java.awt.image.renderable.ParameterBlock
- 所有已实现的接口:
-
Serializable,Cloneable
ParameterBlock封装了RenderableImageOp或其他处理图像的类所需的所有关于源和参数(对象)的信息。
虽然可以将任意对象放入源Vector中,但此类的用户可能会施加语义约束,例如要求所有源都是RenderedImages或RenderableImage。 ParameterBlock本身仅是一个容器,不对源或参数类型进行检查。
ParameterBlock中的所有参数都是对象;提供了方便的add和set方法,这些方法接受基本类型的参数并构造Number的适当子类(例如Integer或Float)。相应的get方法执行向下转换,并具有基本类型的返回值;如果存储的值类型不正确,则会抛出异常。无法区分“short s; add(s)”和“add(Short.valueOf(s))”的结果。
请注意,get和set方法操作的是引用。因此,在不适当的情况下,必须小心不要在ParameterBlock之间共享引用。例如,要创建一个新的ParameterBlock,它与旧的ParameterBlock相等,只是添加了一个源,可能会尝试编写:
ParameterBlock addSource(ParameterBlock pb, RenderableImage im) {
ParameterBlock pb1 = new ParameterBlock(pb.getSources());
pb1.addSource(im);
return pb1;
}
此代码将具有更改原始ParameterBlock的副作用,因为getSources操作返回对其源Vector的引用。pb和pb1都共享其源Vector,对任一者的更改对另一个都是可见的。
编写addSource函数的正确方法是克隆源Vector:
ParameterBlock addSource (ParameterBlock pb, RenderableImage im) {
ParameterBlock pb1 = new ParameterBlock(pb.getSources().clone());
pb1.addSource(im);
return pb1;
}
ParameterBlock的clone方法已被定义为执行源和参数Vector的克隆,因此可以进行这种操作。标准的浅克隆可通过shallowClone获得。
addSource、setSource、add和set方法被定义为在添加参数后返回'this'。这允许使用如下语法:
ParameterBlock pb = new ParameterBlock();
op = new RenderableImageOp("operation", pb.add(arg1).add(arg2));
- 参见:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescription一个虚拟构造函数。ParameterBlock(Vector<Object> sources) 使用给定的源Vector构造一个ParameterBlock。ParameterBlock(Vector<Object> sources, Vector<Object> parameters) 使用给定的源Vector和参数Vector构造一个ParameterBlock。 -
Method Summary
Modifier and TypeMethodDescriptionadd(byte b) 向参数列表中添加一个Byte。add(char c) 向参数列表中添加一个Character。add(double d) 向参数列表中添加一个Double。add(float f) 向参数列表中添加一个Float。add(int i) 向参数列表中添加一个Integer。add(long l) 向参数列表中添加一个Long。add(short s) 向参数列表中添加一个Short。向参数列表中添加一个对象。将图像添加到源列表的末尾。clone()创建一个ParameterBlock的副本。bytegetByteParameter(int index) 作为byte返回参数的便利方法。chargetCharParameter(int index) 作为char返回参数的便利方法。doublegetDoubleParameter(int index) 作为double返回参数的便利方法。floatgetFloatParameter(int index) 作为float返回参数的便利方法。intgetIntParameter(int index) 作为int返回参数的便利方法。longgetLongParameter(int index) 作为long返回参数的便利方法。int返回参数的数量(不包括源图像)。int返回源图像的数量。getObjectParameter(int index) 作为对象获取参数。Class<?>[]返回描述参数类型的Class对象数组。返回整个参数Vector。getRenderableSource(int index) 将源作为RenderableImage返回。getRenderedSource(int index) 将源作为RenderedImage返回。shortgetShortParameter(int index) 作为short返回参数的便利方法。getSource(int index) 将源作为一般对象返回。返回整个源Vector。void清除参数列表。void清除源图像列表。set(byte b, int index) 用Byte替换参数列表中的对象。set(char c, int index) 用Character替换参数列表中的对象。set(double d, int index) 用Double替换参数列表中的对象。set(float f, int index) 用Float替换参数列表中的对象。set(int i, int index) 用Integer替换参数列表中的对象。set(long l, int index) 用Long替换参数列表中的对象。set(short s, int index) 用Short替换参数列表中的对象。替换参数列表中的对象。voidsetParameters(Vector<Object> parameters) 将整个参数Vector设置为给定的Vector。用新源替换源列表中的条目。voidsetSources(Vector<Object> sources) 将整个源Vector设置为给定的Vector。创建一个ParameterBlock的浅拷贝。
-
Field Details
-
sources
一个源的Vector,存储为任意对象。 -
parameters
一个非源参数的Vector,存储为任意对象。
-
-
Constructor Details
-
ParameterBlock
public ParameterBlock()一个虚拟构造函数。 -
ParameterBlock
使用给定的源Vector构造一个ParameterBlock。- 参数:
-
sources- 源图像的Vector
-
ParameterBlock
使用给定的源Vector和参数Vector构造一个ParameterBlock。- 参数:
-
sources- 源图像的Vector -
parameters- 用于渲染操作的参数Vector
-
-
Method Details
-
shallowClone
创建一个ParameterBlock的浅拷贝。源和参数Vector通过引用复制 -- 添加或更改将对两个版本都可见。- 返回:
-
ParameterBlock的对象克隆。
-
clone
创建一个ParameterBlock的副本。源和参数Vector被克隆,但实际的源和参数是通过引用复制的。这允许对克隆中的源和参数的顺序和数量进行修改,而对原始ParameterBlock是不可见的。对共享的源或参数本身的更改仍然可见。 -
addSource
将图像添加到源列表的末尾。图像以对象形式存储,以允许将来添加新的节点类型。- 参数:
-
source- 要存储在源列表中的图像对象。 - 返回:
-
包含指定
source的新ParameterBlock。
-
getSource
将源作为一般对象返回。调用者必须将其转换为适当的类型。- 参数:
-
index- 要返回的源的索引。 - 返回:
-
代表位于
sourcesVector中指定索引处的源的Object。 - 参见:
-
setSource
用新源替换源列表中的条目。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
source- 指定的源图像 -
index- 要在sourcesVector中的指定source插入的索引 - 返回:
-
包含指定
source在指定index处的新ParameterBlock。 - 参见:
-
getRenderedSource
将源作为RenderedImage返回。这是一个便利方法。如果源不是RenderedImage,则会抛出异常。- 参数:
-
index- 要返回的源的索引 - 返回:
-
代表
sources Vector中指定索引处的源图像的RenderedImage。
-
getRenderableSource
将源作为RenderableImage返回。这是一个便利方法。如果源不是RenderableImage,则会抛出异常。- 参数:
-
index- 要返回的源的索引 - 返回:
-
代表
sources Vector中指定索引处的源图像的RenderableImage。
-
getNumSources
public int getNumSources()返回源图像的数量。- 返回:
-
sources Vector中源图像的数量。
-
getSources
返回整个源Vector。- 返回:
-
sources Vector。 - 参见:
-
setSources
将整个源向量设置为给定的向量。- 参数:
-
sources- 源图像的Vector - 参见:
-
removeSources
public void removeSources()清除源图像列表。 -
getNumParameters
public int getNumParameters()返回参数的数量(不包括源图像)。- 返回:
-
parametersVector中参数的数量。
-
getParameters
返回整个参数向量。- 返回:
-
parameters Vector。 - 参见:
-
setParameters
将整个参数向量设置为给定的向量。- 参数:
-
parameters- 指定的参数Vector - 参见:
-
removeParameters
public void removeParameters()清除参数列表。 -
add
将对象添加到参数列表中。- 参数:
-
obj- 要添加到parameters Vector中的Object - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将字节添加到参数列表中。- 参数:
-
b- 要添加到parameters Vector中的字节 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将字符添加到参数列表中。- 参数:
-
c- 要添加到parameters Vector中的字符 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将短整数添加到参数列表中。- 参数:
-
s- 要添加到parameters Vector中的短整数 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将整数添加到参数列表中。- 参数:
-
i- 要添加到parameters Vector中的整数 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将长整数添加到参数列表中。- 参数:
-
l- 要添加到parameters Vector中的长整数 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将浮点数添加到参数列表中。- 参数:
-
f- 要添加到parameters Vector中的浮点数 - 返回:
-
包含指定参数的新
ParameterBlock。
-
add
将双精度浮点数添加到参数列表中。- 参数:
-
d- 要添加到parameters Vector中的双精度浮点数 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
obj- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用字节替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
b- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用字符替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
c- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用短整数替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
s- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用整数替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
i- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用长整数替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
l- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用浮点数替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
f- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
set
用双精度浮点数替换参数列表中的对象。如果索引超出当前源列表,则根据需要扩展列表以包含空值。- 参数:
-
d- 替换parameters Vector中指定索引处的参数 -
index- 要替换为指定参数的参数的索引 - 返回:
-
包含指定参数的新
ParameterBlock。
-
getObjectParameter
获取参数作为对象。- 参数:
-
index- 要获取的参数的索引 - 返回:
-
表示
parametersVector中指定索引处参数的Object。
-
getByteParameter
public byte getByteParameter(int index) 作为字节返回参数的便利方法。如果参数为null或不是Byte,则抛出异常。- 参数:
-
index- 要返回的参数的索引 - 返回:
-
指定索引处的参数作为
byte值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Byte -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getCharParameter
public char getCharParameter(int index) 作为字符返回参数的便利方法。如果参数为null或不是Character,则抛出异常。- 参数:
-
index- 要返回的参数的索引 - 返回:
-
指定索引处的参数作为
char值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Character -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getShortParameter
public short getShortParameter(int index) 作为短整数返回参数的便利方法。如果参数为null或不是Short,则抛出异常。- 参数:
-
index- 要返回的参数的索引。 - 返回:
-
指定索引处的参数作为
short值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Short -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getIntParameter
public int getIntParameter(int index) 一个方便的方法,将参数作为int返回。如果参数为null或不是Integer,则会抛出异常。- 参数:
-
index- 要返回的参数的索引。 - 返回:
-
指定索引处的参数作为
int值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Integer -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getLongParameter
public long getLongParameter(int index) 一个方便的方法,将参数作为long返回。如果参数为null或不是Long,则会抛出异常。- 参数:
-
index- 要返回的参数的索引。 - 返回:
-
指定索引处的参数作为
long值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Long -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getFloatParameter
public float getFloatParameter(int index) 一个方便的方法,将参数作为float返回。如果参数为null或不是Float,则会抛出异常。- 参数:
-
index- 要返回的参数的索引。 - 返回:
-
指定索引处的参数作为
float值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Float -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getDoubleParameter
public double getDoubleParameter(int index) 一个方便的方法,将参数作为double返回。如果参数为null或不是Double,则会抛出异常。- 参数:
-
index- 要返回的参数的索引。 - 返回:
-
指定索引处的参数作为
double值。 - 抛出:
-
ClassCastException- 如果指定索引处的参数不是Double -
NullPointerException- 如果指定索引处的参数为null -
ArrayIndexOutOfBoundsException- 如果index为负数或不小于此ParameterBlock对象的当前大小
-
getParamClasses
返回描述参数类型的Class对象数组。- 返回:
-
一个
Class对象数组。
-