public abstract class AbstractRegionPainter extends Object implements Painter<JComponent>
| Modifier and Type | Class and Description | 
|---|---|
| protected static class  | AbstractRegionPainter.PaintContext
              一个类封装状态在绘画时有用。 
             | 
| Modifier | Constructor and Description | 
|---|---|
| protected  | AbstractRegionPainter()
              创建一个新的AbstractRegionPainter 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| protected void | configureGraphics(Graphics2D g)
              配置给定的Graphics2D。 
             | 
| protected float | decodeAnchorX(float x, float dx)
              解码并返回给定控制点的编码X值的锚定点的实际像素位置的浮点值,以及从该控制点到锚点的偏移距离。 
             | 
| protected float | decodeAnchorY(float y, float dy)
              解码并返回一个浮点值,表示给定控制点的编码Y值的锚点的实际像素位置,以及从该控制点到锚点的偏移距离。 
             | 
| protected Color | decodeColor(Color color1, Color color2, float midPoint)
              解码并返回从两个其他颜色之间的偏移导出的颜色。 
             | 
| protected Color | decodeColor(String key, float hOffset, float sOffset, float bOffset, int aOffset)
              解码并返回从UI默认值中的基色导出的颜色。 
             | 
| protected LinearGradientPaint | decodeGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color[] colors)
              给定用于创建LinearGradientPaint的参数,此方法将创建并返回一个线性渐变画线。 
             | 
| protected RadialGradientPaint | decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors)
              给定用于创建RadialGradientPaint的参数,此方法将创建并返回径向渐变画。 
             | 
| protected float | decodeX(float x)
              解码并返回表示给定编码X值的实际像素位置的浮点值。 
             | 
| protected float | decodeY(float y)
              解码并返回表示给定编码的y值的实际像素位置的浮点值。 
             | 
| protected abstract void | doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys)
              实际执行绘画操作。 
             | 
| protected Color | getComponentColor(JComponent c, String property, Color defaultColor, float saturationOffset, float brightnessOffset, int alphaOffset)
              从给定的JComponent获取颜色属性。 
             | 
| protected Object[] | getExtendedCacheKeys(JComponent c)
              获取绘图器实现想要包含在图像缓存查找中的任何额外的属性。 
             | 
| protected abstract AbstractRegionPainter.PaintContext | getPaintContext()
              获取此Paint操作的PaintContext。 
             | 
| void | paint(Graphics2D g, JComponent c, int w, int h) 
             给予给定的 Graphics2D对象。 | 
public final void paint(Graphics2D g, JComponent c, int w, int h)
 给予给定的Graphics2D对象。 这个方法的实现可以修改状态Graphics2D ,并且不需要完成时恢复该状态。 在大多数情况下,建议呼叫者传递一个临时图形对象。 Graphics2D绝对不能为空。 
 图形对象上的状态可能会被paint方法所paint ,但可能不是。 例如,设置在显卡的抗锯齿呈现提示可能会或可能不会被尊重Painter实施。 
 提供的对象参数充当可选配置参数。 例如,它可以是类型Component 。 一个Painter ,期望它可以从该Component读取状态并使用状态进行绘画。 例如,一个实现可以读取backgroundColor并使用它。 
 一般来说,为了提高可重用性,大多数标准Painter忽略此参数。 因此,它们可以在任何情况下重复使用。 object可能为null。 如果对象参数为空,则实现不能抛出NullPointerException。 
 最后, width和height参数指定Painter应该绘制的宽度和高度。 更具体地说,指定的宽度和高度指示画家应该在该宽度和高度内完全绘制。 g参数上的任何指定剪辑将进一步限制该区域。 
 例如,假设我有一个绘制渐变的Painter实现。 渐变从白色变成黑色。 它“延伸”填满绘画区域。 因此,如果我用这个Painter绘制一个500×500的区域,最左边的颜色将是黑色,最右边是白色,并且之间画一个平滑的渐变。 我可以不用修改,重用Painter来绘制一个20x20的区域。 这个区域也将在左边是黑色,右边是白色,并且之间画一个平滑的渐变。 
paint在接口 
            Painter<JComponent> 
           g - 要渲染的Graphics2D。 
            这不能为空。 
           c - 可选配置参数。 
            这可能是空的。 
           w - 要涂漆的区域的宽度。 
           h - 要涂漆的面积的高度。 
           protected Object[] getExtendedCacheKeys(JComponent c)
c - 当前paint调用的组件 
           protected abstract AbstractRegionPainter.PaintContext getPaintContext()
获取此Paint操作的PaintContext。 这种方法是在每个油漆上调用的,所以应该是快速的,不会产生垃圾。 PaintContext包含缓存提示等信息。 它还包含在运行时解码点所需的数据,例如拉伸插图,编码点定义的画布大小以及拉伸插入是否反转。
这种方法允许子类将不同状态的绘图与可能不同的画布大小等打包成一个AbstractRegionPainter实现。
protected void configureGraphics(Graphics2D g)
配置给定的Graphics2D。 通常,渲染提示或合成规则在绘制之前应用于Graphics2D对象,这将影响所有后续的绘制操作。 该方法提供了一种方便的钩子,用于在渲染之前配置Graphics对象,而不管渲染操作是执行到中间缓冲还是直接执行到显示。
g - 要配置的Graphics2D对象。 
            不会为空 
           protected abstract void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys)
width ,高度为height 。 
           出于性能原因,您可能需要从Graphics2D对象读取剪辑,并且仅在该空间内呈现。 
          g - 要绘制的Graphics2D曲面 
           c - 与事件相关的JComponent。 
            例如,如果渲染的区域是Button,那么c将是一个JButton。 
            如果绘制的区域是ScrollBarSlider,那么该组件将是JScrollBar。 
            该值可能为null。 
           width - 要绘制的区域的宽度。 
            请注意,在绘制前景的情况下,该值可能与c.getWidth()不同。 
           height - 要绘画的地区的高度。 
            请注意,在绘制前景的情况下,该值可能与c.getHeight()不同。 
           extendedCacheKeys - 调用getExtendedCacheKeys()的结果 
           protected final float decodeX(float x)
x - 编码的x值(0 ... 1或1 ... 2或2 ... 3) 
           IllegalArgumentException - 如果是 
            x < 0或 
            x > 3 
           protected final float decodeY(float y)
y - 编码的y值(0 ... 1或1 ... 2或2 ... 3) 
           IllegalArgumentException - 如果 
            y < 0或 
            y > 3 
           protected final float decodeAnchorX(float x,
                                    float dx) 
          x - 贝塞尔控制点(0 ... 1或1 ... 2或2 ... 3)的编码x值, 
           dx - 从控制点x到锚的偏移距离 
           IllegalArgumentException - 如果 
            x < 0或 
            x > 3 
           protected final float decodeAnchorY(float y,
                                    float dy) 
          y - 贝塞尔控制点(0 ... 1或1 ... 2或2 ... 3)的编码y值, 
           dy - 从控制点y到锚点的偏移距离 
           IllegalArgumentException - 如果 
            y < 0或 
            y > 3 
           protected final Color decodeColor(String key, float hOffset, float sOffset, float bOffset, int aOffset)
key - 与定义基色的UIManager的UI Defaults表中的值对应的键 
           hOffset - 用于派生的色调偏移。 
           sOffset - 用于推导的饱和偏移。 
           bOffset - 用于推导的亮度偏移。 
           aOffset - 用于派生的alpha偏移量。 
            介于0 ... 255之间 
           protected final Color decodeColor(Color color1, Color color2, float midPoint)
color1 - 第一种颜色 
           color2 - 第二种颜色 
           midPoint - 颜色1和颜色2之间的偏移值为0.0是颜色1和1.0是颜色2; 
           protected final LinearGradientPaint decodeGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color[] colors)
x1 - 
           y1 - 
           x2 - 
           y2 - 
           midpoints - 
           colors - 
           NullPointerException - 如果 
            midpoints数组为空,或 
            colors数组为空, 
           IllegalArgumentException - 如果起点和终点是相同的点,或者 
            midpoints.length != colors.length或 
            colors的大小小于2,或者 
            midpoints值小于0.0或大于1.0,或 
            midpoints不以严格的增加顺序提供 
           protected final RadialGradientPaint decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors)
x - 
           y - 
           r - 
           midpoints - 
           colors - 
           NullPointerException - 如果 
            midpoints数组为空,或者 
            colors数组为空 
           IllegalArgumentException - 如果 
            r为非正数,或 
            midpoints.length != colors.length或 
            colors小于2,或 
            midpoints值小于0.0或大于1.0,或 
            midpoints严格增加的顺序提供 
           protected final Color getComponentColor(JComponent c, String property, Color defaultColor, float saturationOffset, float brightnessOffset, int alphaOffset)
getXXX()方法,如果该失败检查客户端属性与密钥property 。 
           如果仍然没有返回颜色,则返回defaultColor 。 
          c - 从中获取颜色属性的组件 
           property - bean样式属性或客户端属性的名称 
           defaultColor - 如果从组件中没有获得颜色,则返回的颜色。 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.