Author: allain.lalonde
Date: Wed Jul 15 09:39:14 2009
New Revision: 469

Modified:
    piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java

Log:
Part of a solution to Issue #53; made toImage not use GraphicsEnvironment  
in the case of running in Headless mode.

Modified:  
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java
==============================================================================
--- piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java       
 
(original)
+++ piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java       
 
Wed Jul 15 09:39:14 2009
@@ -2469,10 +2469,17 @@
       * @param height pixel height of the resulting image
       * @return a new image representing this node and its descendents
       */
-    public Image toImage(int width, int height, Paint backGroundPaint) {
-        GraphicsConfiguration graphicsConfiguration =  
GraphicsEnvironment.getLocalGraphicsEnvironment()
-                .getDefaultScreenDevice().getDefaultConfiguration();
-        BufferedImage result =  
graphicsConfiguration.createCompatibleImage(width, height,  
Transparency.TRANSLUCENT);
+    public Image toImage(int width, int height, Paint backGroundPaint) {
+        BufferedImage result;
+
+        if (GraphicsEnvironment.isHeadless()) {
+            result = new BufferedImage(width, height,  
BufferedImage.TYPE_INT_ARGB);
+        }
+        else {
+            GraphicsConfiguration graphicsConfiguration =  
GraphicsEnvironment.getLocalGraphicsEnvironment()
+            .getDefaultScreenDevice().getDefaultConfiguration();
+            result =  graphicsConfiguration.createCompatibleImage(width,  
height, Transparency.TRANSLUCENT);
+        }

          return toImage(result, backGroundPaint);
      }

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

Reply via email to