模块 java.desktop

类 ParameterBlock

java.lang.Object
java.awt.image.renderable.ParameterBlock
所有已实现的接口:
Serializable , Cloneable

public class ParameterBlock extends Object implements Cloneable , Serializable
ParameterBlock 封装了 RenderableImageOp 或其他处理图像的类所需的有关源和参数(对象)的所有信息。

尽管可以在源 Vector 中放置任意对象,但此类的用户可能会施加语义约束,例如要求所有源都是 RenderedImages 或 RenderableImage。 ParameterBlock 本身只是一个容器,不对源或参数类型执行检查。

ParameterBlock 中的所有参数都是对象;方便的 add 和 set 方法可用,它们采用基本类型的参数并构造 Number 的适当子类(例如 Integer 或 Float)。相应的 get 方法执行向下转换并具有基本类型的返回值;如果存储值的类型不正确,将抛出异常。没有办法区分“short s; add(s)”和“add(new Short(s))”的结果。

请注意,get 和 set 方法对引用进行操作。因此,必须注意不要在不合适的情况下在 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 的克隆方法已被定义为执行源向量和参数向量的克隆。一个标准的浅克隆可以作为 shallowClone 获得。

addSource、setSource、add 和 set 方法被定义为在添加其参数后返回“this”。这允许使用如下语法:

 ParameterBlock pb = new ParameterBlock();
 op = new RenderableImageOp("operation", pb.add(arg1).add(arg2));
 
参见:
  • 字段详细信息

    • sources

      protected Vector <Object > sources
      源向量,存储为任意对象。
    • parameters

      protected Vector <Object > parameters
      非源参数的向量,存储为任意对象。
  • 构造方法详细信息

    • ParameterBlock

      public ParameterBlock()
      虚拟构造方法。
    • ParameterBlock

      public ParameterBlock(Vector <Object > sources)
      使用给定的源向量构造一个 ParameterBlock
      参数:
      sources - 源图像的 Vector
    • ParameterBlock

      public ParameterBlock(Vector <Object > sources, Vector <Object > parameters)
      使用给定的源向量和参数向量构造一个 ParameterBlock
      参数:
      sources - 源图像的 Vector
      parameters - 一个 Vector 参数用于渲染操作
  • 方法详情

    • shallowClone

      public Object  shallowClone()
      创建 ParameterBlock 的浅表副本。源和参数 Vectors 是通过引用复制的——添加或更改对两个版本都是可见的。
      返回:
      ParameterBlock 的对象克隆。
    • clone

      public Object  clone()
      创建 ParameterBlock 的副本。源和参数 Vectors 被克隆,但实际的源和参数是通过引用复制的。这允许对克隆中源和参数的顺序和数量的修改对原始 ParameterBlock 不可见。对共享源或参数本身的更改仍然可见。
      重写:
      clone 在类 Object
      返回:
      ParameterBlock 的对象克隆。
      参见:
    • addSource

      public ParameterBlock  addSource(Object  source)
      将图像添加到源列表的末尾。图像存储为对象,以便将来允许新的节点类型。
      参数:
      source - 要存储在源列表中的图像对象。
      返回:
      一个新的 ParameterBlock 包含指定的 source
    • getSource

      public Object  getSource(int index)
      将源作为一般对象返回。调用者必须将其转换为适当的类型。
      参数:
      index - 要返回的源的索引。
      返回:
      Object 表示位于 sources Vector 中指定索引处的源。
      参见:
    • setSource

      public ParameterBlock  setSource(Object  source, int index)
      用新源替换源列表中的条目。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      source - 指定的源图像
      index - 在 sources Vector 中插入指定 source 的索引
      返回:
      一个新的 ParameterBlock 在指定的 index 处包含指定的 source
      参见:
    • getRenderedSource

      public RenderedImage  getRenderedSource(int index)
      将源作为 RenderedImage 返回。此方法是一种方便的方法。如果源不是 RenderedImage,将抛出异常。
      参数:
      index - 要返回的源的索引
      返回:
      RenderedImage 表示位于 sources Vector 中指定索引处的源图像。
    • getRenderableSource

      public RenderableImage  getRenderableSource(int index)
      将源作为 RenderableImage 返回。此方法是一种方便的方法。如果源不是 RenderableImage,将抛出异常。
      参数:
      index - 要返回的源的索引
      返回:
      RenderableImage 表示位于 sources Vector 中指定索引处的源图像。
    • getNumSources

      public int getNumSources()
      返回源图像的数量。
      返回:
      sources Vector 中的源图像数量。
    • getSources

      public Vector <Object > getSources()
      返回源的整个向量。
      返回:
      sources Vector
      参见:
    • setSources

      public void setSources(Vector <Object > sources)
      将整个 Vector of sources 设置为给定的 Vector。
      参数:
      sources - 源图像的 Vector
      参见:
    • removeSources

      public void removeSources()
      清除源图像列表。
    • getNumParameters

      public int getNumParameters()
      返回参数的数量(不包括源图像)。
      返回:
      parameters Vector 中的参数数量。
    • getParameters

      public Vector <Object > getParameters()
      返回整个参数向量。
      返回:
      parameters Vector
      参见:
    • setParameters

      public void setParameters(Vector <Object > parameters)
      将整个参数 Vector 设置为给定 Vector。
      参数:
      parameters - 参数的指定Vector
      参见:
    • removeParameters

      public void removeParameters()
      清除参数列表。
    • add

      public ParameterBlock  add(Object  obj)
      将对象添加到参数列表。
      参数:
      obj - 添加到 parameters VectorObject
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(byte b)
      将一个字节添加到参数列表中。
      参数:
      b - 添加到 parameters Vector 的字节
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(char c)
      将一个字符添加到参数列表中。
      参数:
      c - 添加到 parameters Vector 的字符
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(short s)
      将 Short 添加到参数列表中。
      参数:
      s - 添加到 parameters Vector 的短线
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(int i)
      将整数添加到参数列表。
      参数:
      i - 添加到 parameters Vector 的整数
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(long l)
      将 Long 添加到参数列表中。
      参数:
      l - 添加到 parameters Vector 的长
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(float f)
      将 Float 添加到参数列表中。
      参数:
      f - 添加到 parameters Vector 的浮点数
      返回:
      包含指定参数的新 ParameterBlock
    • add

      public ParameterBlock  add(double d)
      将 Double 添加到参数列表。
      参数:
      d - 添加到 parameters Vector 的双倍
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(Object  obj, int index)
      替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      obj - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(byte b, int index)
      用字节替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      b - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(char c, int index)
      用字符替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      c - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(short s, int index)
      用 Short 替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      s - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(int i, int index)
      用整数替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      i - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(long l, int index)
      用 Long 替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      l - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(float f, int index)
      用 Float 替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      f - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • set

      public ParameterBlock  set(double d, int index)
      用 Double 替换参数列表中的对象。如果索引位于当前源列表之外,则根据需要用空值扩展列表。
      参数:
      d - 替换 parameters Vector 中指定索引处的参数的参数
      index - 要替换为指定参数的参数的索引
      返回:
      包含指定参数的新 ParameterBlock
    • getObjectParameter

      public Object  getObjectParameter(int index)
      获取参数作为对象。
      参数:
      index - 要获取的参数的索引
      返回:
      Object 表示指定索引处的参数到 parameters Vector 中。
    • getByteParameter

      public byte getByteParameter(int index)
      将参数作为字节返回的便捷方法。如果参数是 null 或不是 Byte 则抛出异常。
      参数:
      index - 要返回的参数的索引。
      返回:
      指定索引处的参数作为 byte 值。
      抛出:
      ClassCastException - 如果指定索引处的参数不是 Byte
      NullPointerException - 如果指定索引处的参数是 null
      ArrayIndexOutOfBoundsException - 如果 index 为负数或不小于此 ParameterBlock 对象的当前大小
    • getCharParameter

      public char getCharParameter(int index)
      将参数作为 char 返回的便捷方法。如果参数是 null 或不是 Character 则抛出异常。
      参数:
      index - 要返回的参数的索引。
      返回:
      指定索引处的参数作为 char 值。
      抛出:
      ClassCastException - 如果指定索引处的参数不是 Character
      NullPointerException - 如果指定索引处的参数是 null
      ArrayIndexOutOfBoundsException - 如果 index 为负数或不小于此 ParameterBlock 对象的当前大小
    • getShortParameter

      public short getShortParameter(int index)
      一种将参数作为 short 返回的便捷方法。如果参数是 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)
      一种将参数作为浮点数返回的便捷方法。如果参数是 null 或不是 Float 则抛出异常。
      参数:
      index - 要返回的参数的索引。
      返回:
      指定索引处的参数作为 float 值。
      抛出:
      ClassCastException - 如果指定索引处的参数不是 Float
      NullPointerException - 如果指定索引处的参数是 null
      ArrayIndexOutOfBoundsException - 如果 index 为负数或不小于此 ParameterBlock 对象的当前大小
    • getDoubleParameter

      public double getDoubleParameter(int index)
      将参数作为双精度值返回的便捷方法。如果参数是 null 或不是 Double 则抛出异常。
      参数:
      index - 要返回的参数的索引。
      返回:
      指定索引处的参数作为double值。
      抛出:
      ClassCastException - 如果指定索引处的参数不是 Double
      NullPointerException - 如果指定索引处的参数是 null
      ArrayIndexOutOfBoundsException - 如果 index 为负数或不小于此 ParameterBlock 对象的当前大小
    • getParamClasses

      public Class <?>[] getParamClasses()
      返回描述参数类型的 Class 对象数组。
      返回:
      Class 对象的数组。