public PaintJob(Box clip, Color background) { bufferCache = Context.instance().bufferedImageCache; bufferedImagePool = Context.instance().bufferedImagePool; this.clip = clip; buffer = bufferedImagePool.acquire(clip.getSize()); rootGraphics = buffer.createGraphics(); rootGraphics.setBackground(background); rootGraphics.clearRect(0, 0, clip.width, clip.height); composite = rootGraphics.getComposite(); }
public BufferedImage buildBufferFor(Panel panel) { Dimension dimension = new Dimension(panel.getWidth(), panel.getHeight()); BufferedImage buffer = bufferedImagePool.acquire(dimension); Graphics2D graphics = buffer.createGraphics(); graphics.setBackground(Colors.TRANSPARENT); graphics.clearRect(0, 0, panel.getWidth(), panel.getHeight()); panel.paintOn(graphics); graphics.dispose(); bufferCache.cache(panel, buffer); return buffer; }
public void paintClipFor(Panel panel, Graphics2D graphics) { if (panel.canBeBuffered()) { BufferedImage panelBuffer = bufferCache.retrieve(panel); if (shouldBuildBufferFor(panel, panelBuffer)) { bufferedImagePool.recycle(panelBuffer); panelBuffer = buildBufferFor(panel); } graphics.drawImage(panelBuffer, 0, 0, null); } else { panel.paintOn(graphics); } }