类sun.awt.ConstrainableGraphics源码实例Demo

下面列出了怎么用sun.awt.ConstrainableGraphics的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk9   文件: EmptyClipRenderingTest.java
/**
 * Run the test: cycle through all the rectangles, use one as clip and
 * another as the area to render to.
 * Set the clip in the same way Swing does it when repainting:
 * first constrain the graphics to the damaged area, and repaint everything
 */
void runTest(Graphics2D destGraphics) {
    destGraphics.setColor(Color.black);
    destGraphics.fillRect(0, 0, IMG_W, IMG_H);

    destGraphics.setColor(Color.red);
    for (Rectangle clip : rects) {
        Graphics2D g2d = (Graphics2D)destGraphics.create();
        g2d.setColor(Color.red);
        // mimic what swing does in BufferStrategyPaintManager
        if (g2d instanceof ConstrainableGraphics) {
            ((ConstrainableGraphics)g2d).constrain(clip.x, clip.y,
                                                   clip.width, clip.height);
        }
        g2d.setClip(clip);

        for (Rectangle renderRegion : rects) {
            if (renderRegion != clip) {
                // from CellRendererPane's paintComponent
                Graphics2D rG = (Graphics2D)
                    g2d.create(renderRegion.x, renderRegion.y,
                               renderRegion.width, renderRegion.height);
                rG.fillRect(0,0, renderRegion.width, renderRegion.height);
            }
        }
    }
}
 
 类所在包
 类方法
 同包方法