]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/VRamBufferedImage.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / image / impl / VRamBufferedImage.java
index 962e0bba2985985f72be2eac762b024a742d3814..1a7be154eca7055381bce3fca3ea5388078c8ed0 100644 (file)
@@ -1,99 +1,99 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.image.impl;\r
-\r
-import java.awt.Color;\r
-import java.awt.Graphics2D;\r
-import java.awt.GraphicsConfiguration;\r
-import java.awt.RenderingHints;\r
-import java.awt.Shape;\r
-import java.awt.Transparency;\r
-import java.awt.geom.Rectangle2D;\r
-import java.awt.image.VolatileImage;\r
-\r
-import org.simantics.g2d.image.Image;\r
-\r
-/**\r
- * Video-ram cache suitable for rasterized PaintableSymbols.\r
- * \r
- * @see VRamImage\r
- * @author Toni Kalajainen\r
- */\r
-public class VRamBufferedImage extends ImageProxy {\r
-\r
-    Shape outline;\r
-    final GraphicsConfiguration gc;\r
-    VolatileImage image;\r
-    int wid, hei;\r
-\r
-    public VRamBufferedImage(Image original, GraphicsConfiguration gc) {\r
-        super(original);\r
-        assert(gc!=null);\r
-        this.gc = gc;\r
-        Rectangle2D bounds = original.getBounds();\r
-        wid = (int) Math.ceil( bounds.getWidth() );\r
-        hei = (int) Math.ceil( bounds.getHeight() );\r
-    }\r
-\r
-    synchronized VolatileImage restore()\r
-    {\r
-        if (image==null) {\r
-            image = gc.createCompatibleVolatileImage(\r
-                    wid, hei,\r
-                    Transparency.TRANSLUCENT);\r
-        }\r
-        int validateResult = image.validate(gc);\r
-        if (validateResult == VolatileImage.IMAGE_INCOMPATIBLE)\r
-            return null;\r
-\r
-        if (validateResult == VolatileImage.IMAGE_OK)\r
-            return image;\r
-\r
-        if (validateResult == VolatileImage.IMAGE_RESTORED /*raster.contentsLost()*/) {\r
-            Rectangle2D bounds = source.getBounds();\r
-            outline = source.getOutline();\r
-            Graphics2D target = image.createGraphics();\r
-            target.setBackground(new Color(255,255,255,0));\r
-            target.clearRect(0, 0, image.getWidth(), image.getHeight());\r
-            target.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
-            target.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);\r
-            target.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);\r
-            target.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);\r
-            target.translate(-bounds.getMinX(), -bounds.getMinY());\r
-            source.init(null);//new GraphicsContextImpl(new Rectangle2D.Double(0,0, image.getWidth(), image.getHeight()), null) );\r
-            target.dispose();\r
-            return image;\r
-        }\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return gc.hashCode() ^source.hashCode();\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (!(obj instanceof VRamBufferedImage)) return false;\r
-        VRamBufferedImage o = (VRamBufferedImage) obj;\r
-        return o.gc == gc && o.source.equals(source);\r
-    }\r
-\r
-    public Image getSource() {\r
-        return source;\r
-    }\r
-\r
-    public GraphicsConfiguration getGraphicsConfiguration() {\r
-        return gc;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.image.impl;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.Transparency;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.VolatileImage;
+
+import org.simantics.g2d.image.Image;
+
+/**
+ * Video-ram cache suitable for rasterized PaintableSymbols.
+ * 
+ * @see VRamImage
+ * @author Toni Kalajainen
+ */
+public class VRamBufferedImage extends ImageProxy {
+
+    Shape outline;
+    final GraphicsConfiguration gc;
+    VolatileImage image;
+    int wid, hei;
+
+    public VRamBufferedImage(Image original, GraphicsConfiguration gc) {
+        super(original);
+        assert(gc!=null);
+        this.gc = gc;
+        Rectangle2D bounds = original.getBounds();
+        wid = (int) Math.ceil( bounds.getWidth() );
+        hei = (int) Math.ceil( bounds.getHeight() );
+    }
+
+    synchronized VolatileImage restore()
+    {
+        if (image==null) {
+            image = gc.createCompatibleVolatileImage(
+                    wid, hei,
+                    Transparency.TRANSLUCENT);
+        }
+        int validateResult = image.validate(gc);
+        if (validateResult == VolatileImage.IMAGE_INCOMPATIBLE)
+            return null;
+
+        if (validateResult == VolatileImage.IMAGE_OK)
+            return image;
+
+        if (validateResult == VolatileImage.IMAGE_RESTORED /*raster.contentsLost()*/) {
+            Rectangle2D bounds = source.getBounds();
+            outline = source.getOutline();
+            Graphics2D target = image.createGraphics();
+            target.setBackground(new Color(255,255,255,0));
+            target.clearRect(0, 0, image.getWidth(), image.getHeight());
+            target.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            target.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+            target.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+            target.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+            target.translate(-bounds.getMinX(), -bounds.getMinY());
+            source.init(null);//new GraphicsContextImpl(new Rectangle2D.Double(0,0, image.getWidth(), image.getHeight()), null) );
+            target.dispose();
+            return image;
+        }
+        return null;
+    }
+
+    @Override
+    public int hashCode() {
+        return gc.hashCode() ^source.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof VRamBufferedImage)) return false;
+        VRamBufferedImage o = (VRamBufferedImage) obj;
+        return o.gc == gc && o.source.equals(source);
+    }
+
+    public Image getSource() {
+        return source;
+    }
+
+    public GraphicsConfiguration getGraphicsConfiguration() {
+        return gc;
+    }
+
+}