模块 java.desktop

类 AbstractRegionPainter

java.lang.Object
javax.swing.plaf.nimbus.AbstractRegionPainter
所有已实现的接口:
Painter<JComponent>

public abstract class AbstractRegionPainter extends Object implements Painter <JComponent >
用于定义用于在 Nimbus 中渲染区域或组件的 Painter 实例的便捷基类。
  • 内部类总结

    内部类
    修饰符和类型
    描述
    protected static class 
    一个封装状态的类,在绘画时很有用。
  • 构造方法总结

    构造方法
    修饰符
    构造方法
    描述
    protected
    创建一个新的 AbstractRegionPainter
  • 方法总结

    修饰符和类型
    方法
    描述
    protected void
    配置给定的 Graphics2D。
    protected final float
    decodeAnchorX(float x, float dx)
    解码并返回一个浮点值,表示给定控制点的编码 X 值的锚点的实际像素位置,以及从该控制点到锚点的偏移距离。
    protected final float
    decodeAnchorY(float y, float dy)
    解码并返回一个浮点值,表示锚点的实际像素位置,给定控制点的编码 Y 值,以及从该控制点到锚点的偏移距离。
    protected final Color
    decodeColor(Color color1, Color color2, float midPoint)
    解码并返回一种颜色,该颜色源自其他两种颜色之间的偏移量。
    protected final Color
    decodeColor(String key, float hOffset, float sOffset, float bOffset, int aOffset)
    解码并返回一种颜色,该颜色派生自 UI 默认值中的基色。
    protected final LinearGradientPaint
    decodeGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color[] colors)
    给定用于创建 LinearGradientPaint 的参数,此方法将创建并返回线性渐变绘画。
    protected final RadialGradientPaint
    decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors)
    给定用于创建 RadialGradientPaint 的参数,此方法将创建并返回径向渐变绘制。
    protected final float
    decodeX(float x)
    解码并返回一个浮点值,表示给定编码 X 值的实际像素位置。
    protected final float
    decodeY(float y)
    解码并返回一个浮点值,表示给定编码 y 值的实际像素位置。
    protected abstract void
    doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys)
    实际上执行绘画操作。
    protected final Color
    getComponentColor(JComponent c, String property, Color defaultColor, float saturationOffset, float brightnessOffset, int alphaOffset)
    从给定的 JComponent 获取颜色属性。
    protected Object[]
    获取绘制器实现希望包含在图像缓存查找中的任何额外属性。
    获取此绘画操作的 PaintContext。
    final void
    paint(Graphics2D g, JComponent c, int w, int h)
    呈现给定的 Graphics2D 对象。

    在类 java.lang.Object 中声明的方法

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造方法详细信息

    • AbstractRegionPainter

      protected AbstractRegionPainter()
      创建一个新的 AbstractRegionPainter
  • 方法详情

    • paint

      public final void paint(Graphics2D  g, JComponent  c, int w, int h)

      呈现给定的 Graphics2D 对象。此方法的实现 may 修改 Graphics2D 上的状态,并且不需要在完成后恢复该状态。在大多数情况下,建议调用者传入一个临时图形对象。 Graphics2D 绝不能为空。

      paint 方法可能会尊重图形对象上的状态,但也可能不会。例如,Painter 实现可能会或可能不会遵守在图形上设置抗锯齿渲染提示。

      提供的对象参数充当可选的配置参数。例如,它可以是 Component 类型。一个 Painter 期望它可以从那个 Component 读取状态并使用该状态进行绘画。例如,一个实现可能会读取 backgroundColor 并使用它。

      通常,为了提高可重用性,大多数标准 Painter 都会忽略此参数。因此,它们可以在任何上下文中重复使用。 object 可能为空。如果对象参数为 null,实现不得抛出 NullPointerException。

      最后,widthheight 参数指定 Painter 应该绘制的宽度和高度。更具体地说,指定的宽度和高度指示绘制器它应该在此宽度和高度内完全绘制。 g 参数上的任何指定剪辑都将进一步限制该区域。

      例如,假设我有一个绘制渐变的 Painter 实现。渐变从白色变为黑色。它“伸展”以填充绘制区域。因此,如果我使用这个 Painter 绘制一个 500 x 500 的区域,最左边将是黑色,最右边将是白色,并且将在两者之间绘制平滑的渐变。然后我可以在不修改的情况下重复使用 Painter 来绘制一个 20x20 大小的区域。该区域也将在左侧为黑色,在右侧为白色,并在其间绘制平滑的渐变。

      指定者:
      paint 在接口 Painter<JComponent>
      参数:
      g - 要渲染到的 Graphics2D。这不能为空。
      c - 一个可选的配置参数。这可能为空。
      w - 要绘制的区域的宽度。
      h - 要绘制的区域的高度。
    • getExtendedCacheKeys

      protected Object [] getExtendedCacheKeys(JComponent  c)
      获取绘制器实现希望包含在图像缓存查找中的任何额外属性。每次调用 paint(g, c, w, h) 方法时都会检查这一点。
      参数:
      c - 当前绘制调用中的组件
      返回:
      要包含在缓存键中的额外对象数组
    • getPaintContext

      protected abstract AbstractRegionPainter.PaintContext  getPaintContext()

      获取此绘画操作的 PaintContext。每次绘制都会调用此方法,因此应该很快并且不会产生垃圾。 PaintContext 包含缓存提示等信息。它还包含在运行时解码点所需的数据,例如拉伸insets、定义编码点的画布大小以及拉伸insets是否反转。

      此方法允许子类将可能具有不同画布大小等的不同状态的绘画打包到一个 AbstractRegionPainter 实现中。

      返回:
      与此绘制操作关联的 PaintContext。
    • configureGraphics

      protected void configureGraphics(Graphics2D  g)

      配置给定的 Graphics2D。通常,渲染提示或合成规则会在绘画之前应用于 Graphics2D 对象,这会影响所有后续绘画操作。此方法提供了一个方便的挂钩,用于在渲染之前配置 Graphics 对象,无论渲染操作是对中间缓冲区还是直接对显示器执行。

      参数:
      g - 要配置的 Graphics2D 对象。不会为空。
    • doPaint

      protected abstract void doPaint(Graphics2D  g, JComponent  c, int width, int height, Object [] extendedCacheKeys)
      实际上执行绘画操作。子类必须实现这个方法。传递的图形对象可能表示要渲染到的实际表面,或者它可能是中间缓冲区。它也已被预翻译。简单地渲染组件,就好像它位于 0, 0 并且具有 width 的宽度和 height 的高度。出于性能原因,您可能希望从 Graphics2D 对象读取剪辑并仅在该空间内渲染。
      参数:
      g - 要绘制到的 Graphics2D 表面
      c - 与绘图事件相关的 JComponent。例如,如果正在呈现的区域是 Button,那么 c 将是一个 JButton。如果正在绘制的区域是 ScrollBarSlider,那么该组件将是 JScrollBar。该值可能为空。
      width - 要绘制的区域的宽度。请注意,在绘制前景的情况下,此值可能与 c.getWidth() 不同。
      height - 要绘制的区域的高度。请注意,在绘制前景的情况下,此值可能与 c.getHeight() 不同。
      extendedCacheKeys - 调用 getExtendedCacheKeys() 的结果
    • decodeX

      protected final float decodeX(float x)
      解码并返回一个浮点值,表示给定编码 X 值的实际像素位置。
      参数:
      x - 编码的 x 值(0...1,或 1...2,或 2...3)
      返回:
      解码后的 x 值
      抛出:
      IllegalArgumentException - 如果 x < 0x > 3
    • decodeY

      protected final float decodeY(float y)
      解码并返回一个浮点值,表示给定编码 y 值的实际像素位置。
      参数:
      y - 编码的 y 值(0...1,或 1...2,或 2...3)
      返回:
      解码后的 y 值
      抛出:
      IllegalArgumentException - 如果 y < 0y > 3
    • decodeAnchorX

      protected final float decodeAnchorX(float x, float dx)
      解码并返回一个浮点值,表示给定控制点的编码 X 值的锚点的实际像素位置,以及从该控制点到锚点的偏移距离。
      参数:
      x - 贝塞尔曲线控制点的编码 x 值(0...1,或 1...2,或 2...3)
      dx - 从控制点 x 到锚点的偏移距离
      返回:
      控制点的解码 x 位置
      抛出:
      IllegalArgumentException - 如果 x < 0x > 3
    • decodeAnchorY

      protected final float decodeAnchorY(float y, float dy)
      解码并返回一个浮点值,表示锚点的实际像素位置,给定控制点的编码 Y 值,以及从该控制点到锚点的偏移距离。
      参数:
      y - 贝塞尔曲线控制点的编码 y 值(0...1,或 1...2,或 2...3)
      dy - 从控制点 y 到锚点的偏移距离
      返回:
      控制点的解码 y 位置
      抛出:
      IllegalArgumentException - 如果 y < 0y > 3
    • decodeColor

      protected final Color  decodeColor(String  key, float hOffset, float sOffset, float bOffset, int aOffset)
      解码并返回一种颜色,该颜色派生自 UI 默认值中的基色。
      参数:
      key - 与定义基色的 UIManager 的 UI Defaults 表中的值对应的键
      hOffset - 用于推导的色调偏移。
      sOffset - 用于推导的饱和偏移量。
      bOffset - 用于推导的亮度偏移。
      aOffset - 用于推导的 alpha 偏移量。在 0...255 之间
      返回:
      派生颜色,如果父 uiDefault 颜色发生变化,其颜色值也会发生变化。
    • decodeColor

      protected final Color  decodeColor(Color  color1, Color  color2, float midPoint)
      解码并返回一种颜色,该颜色源自其他两种颜色之间的偏移量。
      参数:
      color1 - 第一种颜色
      color2 - 第二种颜色
      midPoint - 颜色1和颜色2之间的偏移量,值为0.0是颜色1,1.0是颜色2;
      返回:
      派生色
    • decodeGradient

      protected final LinearGradientPaint  decodeGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color [] colors)
      给定用于创建 LinearGradientPaint 的参数,此方法将创建并返回线性渐变绘画。此方法的一个主要目的是避免创建起点和终点相等的 LinearGradientPaint。在这种情况下,结束 y 点会稍微增加以避免重叠。
      参数:
      x1 - x1
      y1 - y1
      x2 - x2
      y2 - y2
      midpoints - 中点
      colors - 颜色
      返回:
      一个有效的 LinearGradientPaint。此方法从不返回 null。
      抛出:
      NullPointerException - 如果 midpoints 数组为空,或 colors 数组为空,
      IllegalArgumentException - 如果起点和终点是相同的点,或者 midpoints.length != colors.length ,或者 colors 的大小小于 2,或者 midpoints 值小于 0.0 或大于 1.0,或者 midpoints 未按严格递增顺序提供
    • decodeRadialGradient

      protected final RadialGradientPaint  decodeRadialGradient(float x, float y, float r, float[] midpoints, Color [] colors)
      给定用于创建 RadialGradientPaint 的参数,此方法将创建并返回径向渐变绘制。此方法的一个主要目的是避免创建半径为非正数的 RadialGradientPaint。在这种情况下,只需稍微增加半径即可避免 0。
      参数:
      x - x 坐标
      y - y 坐标
      r - 半径
      midpoints - 中点
      colors - 颜色
      返回:
      有效的 RadialGradientPaint。此方法从不返回 null。
      抛出:
      NullPointerException - 如果 midpoints 数组为空,或 colors 数组为空
      IllegalArgumentException - 如果 r 为非正数,或 midpoints.length != colors.length,或 colors 的大小小于 2,或 midpoints 值小于 0.0 或大于 1.0,或 midpoints 未按严格递增顺序提供
    • getComponentColor

      protected final Color  getComponentColor(JComponent  c, String  property, Color  defaultColor, float saturationOffset, float brightnessOffset, int alphaOffset)
      从给定的 JComponent 获取颜色属性。首先检查 getXXX() 方法,如果失败则检查具有键 property 的客户端属性。如果仍然无法返回颜色,则返回 defaultColor
      参数:
      c - 从中获取颜色属性的组件
      property - bean 样式属性或客户端属性的名称
      defaultColor - 如果未从组件获取颜色,则返回的颜色。
      saturationOffset - 添加修改返回颜色的 HSB 饱和度组件(如果返回默认颜色则忽略)。
      brightnessOffset - 添加修改返回颜色的 HSB 亮度组件(如果返回默认颜色则忽略)。
      alphaOffset - 添加修改返回颜色的 ARGB alpha 组件(如果返回默认颜色则忽略)。
      返回:
      从组件或 defaultColor 获得的颜色