From 782521f8db8894112b023182e50f709a0b711846 Mon Sep 17 00:00:00 2001 From: lehtonen Date: Tue, 9 Mar 2010 08:06:21 +0000 Subject: [PATCH] Fixed h2d EditorCanvas VolatileImage handling. Previously the VolatileImage double buffer would not receive any contents on my workstation since the image was not properly validated. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14705 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/h2d/canvas/EditorCanvas.java | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java b/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java index 92145066..f68900f8 100644 --- a/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java +++ b/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java @@ -32,7 +32,9 @@ import org.simantics.scenegraph.g2d.G2DRenderingHints; public class EditorCanvas extends Canvas { - IDiagramEditor editor; + private static final long serialVersionUID = -387207508390377519L; + + IDiagramEditor editor; EventHandler eventHandler = new EventHandler(); //BufferedImage background; @@ -74,28 +76,35 @@ public class EditorCanvas extends Canvas { private VolatileImage doubleBuffer; @Override public void paint(Graphics _g) { - if(doubleBuffer == null || - doubleBuffer.getWidth() != getWidth() || doubleBuffer.getHeight() != getHeight()) { - doubleBuffer = createVolatileImage(getWidth(), getHeight()); - editor.setViewDimensions(new Dimension(getWidth(), getHeight())); - } - Graphics2D g = (Graphics2D)doubleBuffer.getGraphics(); - - g.setBackground(Color.WHITE); - g.setColor(Color.WHITE); - //g.setPaint(new GradientPaint(0.f, 0.f, Color.white, 2000.f, 1600.f, Color.BLUE, false)); - //g.setPaint(new TexturePaint(background, getBounds())); - g.fillRect(0, 0, doubleBuffer.getWidth(), doubleBuffer.getHeight()); - - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - g.setRenderingHint(G2DRenderingHints.KEY_CONTROL_BOUNDS, getBounds()); - - g.setClip(0, 0, getWidth(), getHeight()); - - editor.getSceneGraph().render(g); - + do { + if (doubleBuffer == null + || doubleBuffer.getWidth() != getWidth() + || doubleBuffer.getHeight() != getHeight() + || doubleBuffer.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) + { + doubleBuffer = createVolatileImage(getWidth(), getHeight()); + editor.setViewDimensions(new Dimension(getWidth(), getHeight())); + } + + Graphics2D g = (Graphics2D)doubleBuffer.getGraphics(); + + g.setBackground(Color.WHITE); + g.setColor(Color.WHITE); + //g.setPaint(new GradientPaint(0.f, 0.f, Color.white, 2000.f, 1600.f, Color.BLUE, false)); + //g.setPaint(new TexturePaint(background, getBounds())); + g.fillRect(0, 0, doubleBuffer.getWidth(), doubleBuffer.getHeight()); + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g.setRenderingHint(G2DRenderingHints.KEY_CONTROL_BOUNDS, getBounds()); + + g.setClip(0, 0, getWidth(), getHeight()); + + editor.getSceneGraph().render(g); + g.dispose(); + } while (doubleBuffer.contentsLost()); + _g.drawImage(doubleBuffer, 0, 0, this); } -- 2.47.1