You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2011/11/09 19:13:32 UTC

svn commit: r1199897 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Author: noelgrandin
Date: Wed Nov  9 18:13:31 2011
New Revision: 1199897

URL: http://svn.apache.org/viewvc?rev=1199897&view=rev
Log:
attempt fix for PIVOT-815, printing problem with applets

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1199897&r1=1199896&r2=1199897&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Wed Nov  9 18:13:31 2011
@@ -21,6 +21,7 @@ import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
+import java.awt.PrintGraphics;
 import java.awt.RenderingHints;
 import java.awt.Transparency;
 import java.awt.dnd.DnDConstants;
@@ -429,6 +430,11 @@ public abstract class ApplicationContext
             // (for some reason, AWT does not do this automatically)
             graphics.clipRect(0, 0, getWidth(), getHeight());
 
+            if (graphics instanceof PrintGraphics) {
+            	print(graphics);
+            	return;
+            }
+            
             java.awt.Rectangle clipBounds = graphics.getClipBounds();
             if (clipBounds != null
                 && !clipBounds.isEmpty()) {
@@ -458,6 +464,25 @@ public abstract class ApplicationContext
         public void update(Graphics graphics) {
             paint(graphics);
         }
+        
+        @Override 
+        public void print(Graphics graphics) { 
+        	// Intersect the clip region with the bounds of this component
+        	// (for some reason, AWT does not do this automatically)
+        	graphics.clipRect(0, 0, getWidth(), getHeight());
+        
+        	java.awt.Rectangle clipBounds = graphics.getClipBounds();
+        	if (clipBounds != null
+        			&& !clipBounds.isEmpty()) {
+        		try {
+        			// When printing, there is no point in using offscreen buffers.
+        			paintDisplay((Graphics2D)graphics);
+        		} catch (RuntimeException exception) {
+        			System.err.println("Exception thrown during print(): " + exception);
+        			throw exception;
+        		}
+        	}
+        }
 
         /**
          * Attempts to paint the display using an offscreen buffer.