下面列出了怎么用sun.awt.ConstrainableGraphics的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
}
}
}