Revision: 627
Author: allain.lalonde
Date: Thu Jul 30 12:23:57 2009
Log: Refactored PCacheCamera to cleanup and made it work in Headless mode.
http://code.google.com/p/piccolo2d/source/detail?r=627
Modified:
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java
=======================================
---
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java
Tue Jul 28 12:46:54 2009
+++
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java
Thu Jul 30 12:23:57 2009
@@ -56,7 +56,7 @@
*
*/
private static final long serialVersionUID = 1L;
- private BufferedImage paintBuffer;
+ private transient BufferedImage paintBuffer;
private boolean imageAnimate;
private PBounds imageAnimateBounds;
@@ -65,15 +65,28 @@
*/
protected BufferedImage getPaintBuffer() {
final PBounds fRef = getFullBoundsReference();
- // TODO eclipse formatting made this ugly
- if (paintBuffer == null || paintBuffer.getWidth() < fRef.getWidth()
- || paintBuffer.getHeight() < fRef.getHeight()) {
- paintBuffer =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
- .getDefaultConfiguration().createCompatibleImage((int)
Math.ceil(fRef.getWidth()),
- (int) Math.ceil(fRef.getHeight()));
+ if (paintBuffer == null || isBufferSmallerThanBounds(fRef)) {
+ paintBuffer = buildPaintBuffer(fRef);
}
return paintBuffer;
}
+
+ private boolean isBufferSmallerThanBounds(final PBounds bounds) {
+ return paintBuffer.getWidth() < bounds.getWidth() ||
paintBuffer.getHeight() < bounds.getHeight();
+ }
+
+ private BufferedImage buildPaintBuffer(final PBounds fRef) {
+ final int newBufferWidth = (int) Math.ceil(fRef.getWidth());
+ final int newBufferHeight = (int) Math.ceil(fRef.getHeight());
+
+ if (GraphicsEnvironment.isHeadless()) {
+ return new BufferedImage(newBufferWidth, newBufferHeight,
BufferedImage.TYPE_4BYTE_ABGR);
+ }
+ else {
+ return
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()
+ .createCompatibleImage(newBufferWidth,
newBufferHeight);
+ }
+ }
/**
* Caches the information necessary to animate from the current view
bounds
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---