Revision: 670
Author: heuermh
Date: Thu Aug 20 14:13:09 2009
Log: Issue 69 ; moving POffscreenCanvas to core
http://code.google.com/p/piccolo2d/source/detail?r=670

Added:
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java
   
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/POffscreenCanvasTest.java
Deleted:
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
   
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java
Modified:
   
/piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java

=======================================
--- /dev/null
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java
        
Thu Aug 20 14:13:09 2009
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without  
modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,  
this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright  
notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other  
materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the  
Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from  
this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  
MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  
DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  
CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  
USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package edu.umd.cs.piccolo;
+
+import java.awt.Cursor;
+import java.awt.Graphics2D;
+
+import edu.umd.cs.piccolo.PCamera;
+import edu.umd.cs.piccolo.PComponent;
+import edu.umd.cs.piccolo.util.PBounds;
+import edu.umd.cs.piccolo.util.PPaintContext;
+import edu.umd.cs.piccolo.util.PUtil;
+
+/**
+ * Offscreen canvas.
+ */
+public final class POffscreenCanvas implements PComponent {
+
+    /** Bounds of this offscreen canvas. */
+    private final PBounds bounds;
+
+    /** Camera for this offscreen canvas. */
+    private PCamera camera;
+
+    /** Render quality. */
+    private int renderQuality = DEFAULT_RENDER_QUALITY;
+
+    /** Default render quality,  
<code>PPaintContext.HIGH_QUALITY_RENDERING</code>. */
+    static final int DEFAULT_RENDER_QUALITY =  
PPaintContext.HIGH_QUALITY_RENDERING;
+
+
+    /**
+     * Create a new offscreen canvas the specified width and height.
+     *
+     * @param width width of this offscreen canvas, must be at least zero
+     * @param height height of this offscreen canvas, must be at least zero
+     */
+    public POffscreenCanvas(final int width, final int height) {
+        if (width < 0) {
+            throw new IllegalArgumentException("width must be at least  
zero, was " + width);
+        }
+        if (height < 0) {
+            throw new IllegalArgumentException("height must be at least  
zero, was " + height);
+        }
+        bounds = new PBounds(0.0d, 0.0d, width, height);
+        setCamera(PUtil.createBasicScenegraph());
+    }
+
+    /**
+     * Render this offscreen canvas to the specified graphics.
+     *
+     * @param graphics graphics to render this offscreen canvas to, must  
not be
+     *            null
+     */
+    public void render(final Graphics2D graphics) {
+        if (graphics == null) {
+            throw new IllegalArgumentException("graphics must not be  
null");
+        }
+        final PPaintContext paintContext = new PPaintContext(graphics);
+        paintContext.setRenderQuality(renderQuality);
+        camera.fullPaint(paintContext);
+    }
+
+    /**
+     * Set the camera for this offscreen canvas to <code>camera</code>.
+     *
+     * @param camera camera for this offscreen canvas
+     */
+    public void setCamera(final PCamera camera) {
+        if (this.camera != null) {
+            this.camera.setComponent(null);
+        }
+        this.camera = camera;
+        if (camera != null) {
+            camera.setComponent(this);
+            camera.setBounds((PBounds) bounds.clone());
+        }
+    }
+
+    /**
+     * Return the camera for this offscreen canvas.
+     *
+     * @return the camera for this offscreen canvas
+     */
+    public PCamera getCamera() {
+        return camera;
+    }
+
+    /**
+     * Set the render quality hint for this offscreen canvas to
+     * <code>renderQuality</code>.
+     *
+     * @param renderQuality render quality hint, must be one of
+     *            <code>PPaintContext.HIGH_QUALITY_RENDERING</code> or
+     *            <code>PPaintContext.LOW_QUALITY_RENDERING</code>
+     */
+    public void setRenderQuality(final int renderQuality) {
+        if (renderQuality == PPaintContext.HIGH_QUALITY_RENDERING
+                || renderQuality == PPaintContext.LOW_QUALITY_RENDERING) {
+            this.renderQuality = renderQuality;
+        }
+        else {
+            throw new IllegalArgumentException("renderQuality must be one  
of PPaintContext.HIGH_QUALITY_RENDERING"
+                    + " or PPaintContext.LOW_QUALITY_RENDERING, was " +  
renderQuality);
+        }
+    }
+
+    /**
+     * Return the render quality hint for this offscreen canvas.
+     *
+     * @return the render quality hint for this offscreen canvas
+     */
+    public int getRenderQuality() {
+        return renderQuality;
+    }
+
+    /** {...@inheritdoc} */
+    public void paintImmediately() {
+        // empty
+    }
+
+    /** {...@inheritdoc} */
+    public void popCursor() {
+        // empty
+    }
+
+    /** {...@inheritdoc} */
+    public void pushCursor(final Cursor cursor) {
+        // empty
+    }
+
+    /** {...@inheritdoc} */
+    public void repaint(final PBounds repaintBounds) {
+        // empty
+    }
+
+    /** {...@inheritdoc} */
+    public void setInteracting(final boolean interacting) {
+        // empty
+    }
+}
=======================================
--- /dev/null
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/POffscreenCanvasTest.java
    
Thu Aug 20 14:13:09 2009
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without  
modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,  
this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright  
notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other  
materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the  
Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from  
this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  
MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  
DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  
CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  
USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package edu.umd.cs.piccolo;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+
+import junit.framework.TestCase;
+import edu.umd.cs.piccolo.PCamera;
+import edu.umd.cs.piccolo.nodes.PPath;
+import edu.umd.cs.piccolo.util.PPaintContext;
+
+/**
+ * Unit test for POffscreenCanvas.
+ */
+public class POffscreenCanvasTest extends TestCase {
+
+    public void testConstructor() {
+        final POffscreenCanvas canvas0 = new POffscreenCanvas(100, 100);
+        assertNotNull(canvas0);
+        final POffscreenCanvas canvas1 = new POffscreenCanvas(0, 0);
+        assertNotNull(canvas1);
+        final POffscreenCanvas canvas2 = new POffscreenCanvas(0, 100);
+        assertNotNull(canvas2);
+        final POffscreenCanvas canvas3 = new POffscreenCanvas(100, 0);
+        assertNotNull(canvas3);
+
+        try {
+            new POffscreenCanvas(-1, 100);
+            fail("ctr(-1, 100) expected IllegalArgumentException");
+        }
+        catch (final IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            new POffscreenCanvas(100, -1);
+            fail("ctr(100, -1) expected IllegalArgumentException");
+        }
+        catch (final IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            new POffscreenCanvas(-1, -1);
+            fail("ctr(-1, -1) expected IllegalArgumentException");
+        }
+        catch (final IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testCamera() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertNotNull(canvas);
+        final PCamera camera = canvas.getCamera();
+        assertNotNull(camera);
+        assertEquals(canvas, camera.getComponent());
+        final PCamera camera1 = new PCamera();
+        canvas.setCamera(camera1);
+        assertEquals(camera1, canvas.getCamera());
+        assertEquals(null, camera.getComponent());
+        assertEquals(canvas, camera1.getComponent());
+        canvas.setCamera(null);
+        assertEquals(null, camera1.getComponent());
+        assertEquals(null, canvas.getCamera());
+    }
+
+    public void testRenderEmpty() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        final BufferedImage image = new BufferedImage(100, 200,  
BufferedImage.TYPE_INT_ARGB);
+        final Graphics2D graphics = image.createGraphics();
+        canvas.render(graphics);
+        for (int x = 0; x < 100; x++) {
+            for (int y = 0; y < 200; y++) {
+                assertEquals(0, image.getRGB(x, y));
+            }
+        }
+    }
+
+    public void testRenderFull() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        final PPath rect = PPath.createRectangle(0.0f, 0.0f, 200.0f,  
300.0f);
+        rect.setPaint(new Color(255, 0, 0));
+        rect.setStroke(null);
+        rect.offset(-100.0d, -100.0d);
+        canvas.getCamera().getLayer(0).addChild(rect);
+        final BufferedImage image = new BufferedImage(100, 200,  
BufferedImage.TYPE_INT_ARGB);
+        final Graphics2D graphics = image.createGraphics();
+        canvas.render(graphics);
+        for (int x = 0; x < 100; x++) {
+            for (int y = 0; y < 200; y++) {
+                // red pixel, RGBA is 255, 0, 0, 255
+                assertEquals(-65536, image.getRGB(x, y));
+            }
+        }
+    }
+
+    public void testRenderNull() {
+        try {
+            final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+            canvas.render(null);
+            fail("render(null) expected IllegalArgumentException");
+        }
+        catch (final IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testRenderQuality() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertEquals(POffscreenCanvas.DEFAULT_RENDER_QUALITY,  
canvas.getRenderQuality());
+        canvas.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
+        assertEquals(PPaintContext.HIGH_QUALITY_RENDERING,  
canvas.getRenderQuality());
+        canvas.setRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
+        assertEquals(PPaintContext.LOW_QUALITY_RENDERING,  
canvas.getRenderQuality());
+
+        try {
+            canvas.setRenderQuality(-1);
+        }
+        catch (final IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testPaintImmediately() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.paintImmediately();
+    }
+
+    public void testPopCursor() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.popCursor();
+    }
+
+    public void testPushCursor() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.pushCursor(null);
+        canvas.pushCursor(Cursor.getDefaultCursor());
+    }
+
+    public void testInteracting() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.setInteracting(true);
+        canvas.setInteracting(false);
+    }
+}
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
     
Thu Jul 30 14:59:39 2009
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without  
modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,  
this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright  
notice, this list of conditions
- * and the following disclaimer in the documentation and/or other  
materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the  
Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from  
this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  
MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  
DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  
CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  
USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolox;
-
-import java.awt.Cursor;
-import java.awt.Graphics2D;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PComponent;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * Offscreen canvas.
- */
-public final class POffscreenCanvas implements PComponent {
-
-    /** Bounds of this offscreen canvas. */
-    private final PBounds bounds;
-
-    /** Camera for this offscreen canvas. */
-    private PCamera camera;
-
-    /** Render quality. */
-    private int renderQuality = DEFAULT_RENDER_QUALITY;
-
-    /**
-     * Default render quality,  
<code>PPaintContext.HIGH_QUALITY_RENDERING</code>
-     * .
-     */
-    static final int DEFAULT_RENDER_QUALITY =  
PPaintContext.HIGH_QUALITY_RENDERING;
-
-    /**
-     * Create a new offscreen canvas the specified width and height.
-     *
-     * @param width width of this offscreen canvas, must be at least zero
-     * @param height height of this offscreen canvas, must be at least zero
-     */
-    public POffscreenCanvas(final int width, final int height) {
-        if (width < 0) {
-            throw new IllegalArgumentException("width must be at least  
zero, was " + width);
-        }
-        if (height < 0) {
-            throw new IllegalArgumentException("height must be at least  
zero, was " + height);
-        }
-        bounds = new PBounds(0.0d, 0.0d, width, height);
-        setCamera(PUtil.createBasicScenegraph());
-    }
-
-    /**
-     * Render this offscreen canvas to the specified graphics.
-     *
-     * @param graphics graphics to render this offscreen canvas to, must  
not be
-     *            null
-     */
-    public void render(final Graphics2D graphics) {
-        if (graphics == null) {
-            throw new IllegalArgumentException("graphics must not be  
null");
-        }
-        final PPaintContext paintContext = new PPaintContext(graphics);
-        paintContext.setRenderQuality(renderQuality);
-        camera.fullPaint(paintContext);
-    }
-
-    /**
-     * Set the camera for this offscreen canvas to <code>camera</code>.
-     *
-     * @param camera camera for this offscreen canvas
-     */
-    public void setCamera(final PCamera camera) {
-        if (this.camera != null) {
-            this.camera.setComponent(null);
-        }
-        this.camera = camera;
-        if (camera != null) {
-            camera.setComponent(this);
-            camera.setBounds((PBounds) bounds.clone());
-        }
-    }
-
-    /**
-     * Return the camera for this offscreen canvas.
-     *
-     * @return the camera for this offscreen canvas
-     */
-    public PCamera getCamera() {
-        return camera;
-    }
-
-    /**
-     * Set the render quality hint for this offscreen canvas to
-     * <code>renderQuality</code>.
-     *
-     * @param renderQuality render quality hint, must be one of
-     *            <code>PPaintContext.HIGH_QUALITY_RENDERING</code> or
-     *            <code>PPaintContext.LOW_QUALITY_RENDERING</code>
-     */
-    public void setRenderQuality(final int renderQuality) {
-        if (renderQuality == PPaintContext.HIGH_QUALITY_RENDERING
-                || renderQuality == PPaintContext.LOW_QUALITY_RENDERING) {
-            this.renderQuality = renderQuality;
-        }
-        else {
-            throw new IllegalArgumentException("renderQuality must be one  
of PPaintContext.HIGH_QUALITY_RENDERING"
-                    + " or PPaintContext.LOW_QUALITY_RENDERING, was " +  
renderQuality);
-        }
-    }
-
-    /**
-     * Return the render quality hint for this offscreen canvas.
-     *
-     * @return the render quality hint for this offscreen canvas
-     */
-    public int getRenderQuality() {
-        return renderQuality;
-    }
-
-    /** {...@inheritdoc} */
-    public void paintImmediately() {
-        // empty
-    }
-
-    /** {...@inheritdoc} */
-    public void popCursor() {
-        // empty
-    }
-
-    /** {...@inheritdoc} */
-    public void pushCursor(final Cursor cursor) {
-        // empty
-    }
-
-    /** {...@inheritdoc} */
-    public void repaint(final PBounds repaintBounds) {
-        // empty
-    }
-
-    /** {...@inheritdoc} */
-    public void setInteracting(final boolean interacting) {
-        // empty
-    }
-}
=======================================
---  
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java
         
Tue Jul 28 12:46:54 2009
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without  
modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,  
this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright  
notice, this list of conditions
- * and the following disclaimer in the documentation and/or other  
materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the  
Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from  
this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  
MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  
DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  
CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  
USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolox;
-
-import java.awt.Color;
-import java.awt.Cursor;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-
-import junit.framework.TestCase;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * Unit test for POffscreenCanvas.
- */
-public class POffscreenCanvasTest extends TestCase {
-
-    public void testConstructor() {
-        final POffscreenCanvas canvas0 = new POffscreenCanvas(100, 100);
-        assertNotNull(canvas0);
-        final POffscreenCanvas canvas1 = new POffscreenCanvas(0, 0);
-        assertNotNull(canvas1);
-        final POffscreenCanvas canvas2 = new POffscreenCanvas(0, 100);
-        assertNotNull(canvas2);
-        final POffscreenCanvas canvas3 = new POffscreenCanvas(100, 0);
-        assertNotNull(canvas3);
-
-        try {
-            new POffscreenCanvas(-1, 100);
-            fail("ctr(-1, 100) expected IllegalArgumentException");
-        }
-        catch (final IllegalArgumentException e) {
-            // expected
-        }
-        try {
-            new POffscreenCanvas(100, -1);
-            fail("ctr(100, -1) expected IllegalArgumentException");
-        }
-        catch (final IllegalArgumentException e) {
-            // expected
-        }
-        try {
-            new POffscreenCanvas(-1, -1);
-            fail("ctr(-1, -1) expected IllegalArgumentException");
-        }
-        catch (final IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testCamera() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        assertNotNull(canvas);
-        final PCamera camera = canvas.getCamera();
-        assertNotNull(camera);
-        assertEquals(canvas, camera.getComponent());
-        final PCamera camera1 = new PCamera();
-        canvas.setCamera(camera1);
-        assertEquals(camera1, canvas.getCamera());
-        assertEquals(null, camera.getComponent());
-        assertEquals(canvas, camera1.getComponent());
-        canvas.setCamera(null);
-        assertEquals(null, camera1.getComponent());
-        assertEquals(null, canvas.getCamera());
-    }
-
-    public void testRenderEmpty() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        final BufferedImage image = new BufferedImage(100, 200,  
BufferedImage.TYPE_INT_ARGB);
-        final Graphics2D graphics = image.createGraphics();
-        canvas.render(graphics);
-        for (int x = 0; x < 100; x++) {
-            for (int y = 0; y < 200; y++) {
-                assertEquals(0, image.getRGB(x, y));
-            }
-        }
-    }
-
-    public void testRenderFull() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        final PPath rect = PPath.createRectangle(0.0f, 0.0f, 200.0f,  
300.0f);
-        rect.setPaint(new Color(255, 0, 0));
-        rect.setStroke(null);
-        rect.offset(-100.0d, -100.0d);
-        canvas.getCamera().getLayer(0).addChild(rect);
-        final BufferedImage image = new BufferedImage(100, 200,  
BufferedImage.TYPE_INT_ARGB);
-        final Graphics2D graphics = image.createGraphics();
-        canvas.render(graphics);
-        for (int x = 0; x < 100; x++) {
-            for (int y = 0; y < 200; y++) {
-                // red pixel, RGBA is 255, 0, 0, 255
-                assertEquals(-65536, image.getRGB(x, y));
-            }
-        }
-    }
-
-    public void testRenderNull() {
-        try {
-            final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-            canvas.render(null);
-            fail("render(null) expected IllegalArgumentException");
-        }
-        catch (final IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testRenderQuality() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        assertEquals(POffscreenCanvas.DEFAULT_RENDER_QUALITY,  
canvas.getRenderQuality());
-        canvas.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
-        assertEquals(PPaintContext.HIGH_QUALITY_RENDERING,  
canvas.getRenderQuality());
-        canvas.setRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
-        assertEquals(PPaintContext.LOW_QUALITY_RENDERING,  
canvas.getRenderQuality());
-
-        try {
-            canvas.setRenderQuality(-1);
-        }
-        catch (final IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testPaintImmediately() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        canvas.paintImmediately();
-    }
-
-    public void testPopCursor() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        canvas.popCursor();
-    }
-
-    public void testPushCursor() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        canvas.pushCursor(null);
-        canvas.pushCursor(Cursor.getDefaultCursor());
-    }
-
-    public void testInteracting() {
-        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
-        canvas.setInteracting(true);
-        canvas.setInteracting(false);
-    }
-}
=======================================
---  
/piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java
     
Tue Jul 28 12:46:54 2009
+++  
/piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java
     
Thu Aug 20 14:13:09 2009
@@ -38,10 +38,10 @@
  import java.awt.geom.Rectangle2D;
  import java.awt.image.BufferStrategy;

+import edu.umd.cs.piccolo.POffscreenCanvas;
  import edu.umd.cs.piccolo.activities.PActivity;
  import edu.umd.cs.piccolo.nodes.PPath;
  import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolox.POffscreenCanvas;

  /**
   * Offscreen canvas example.

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to