]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/svg/AnimatedSVGImage.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / svg / AnimatedSVGImage.java
index a3625f7475c0bd3a22b392c073c7c7c58b651f2e..afbc586863918897adc56770787554c6ed8d71b5 100644 (file)
-/*******************************************************************************\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.svg;\r
-\r
-import java.awt.Point;\r
-import java.awt.Shape;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.EnumSet;\r
-\r
-import org.simantics.g2d.image.Image;\r
-import org.simantics.scenegraph.Node;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.nodes.AnimatedSVGNode;\r
-import org.simantics.scenegraph.g2d.nodes.SVGNode;\r
-import org.simantics.utils.datastructures.cache.IFactory;\r
-import org.simantics.utils.datastructures.cache.ProvisionException;\r
-\r
-/**\r
- * This is a SVG implementation to the PaintableSymbol interface.\r
- */\r
-public class AnimatedSVGImage implements Image {\r
-\r
-    static EnumSet<Feature> caps = EnumSet.of(Feature.Vector);\r
-\r
-    private Rectangle2D bounds;\r
-    private final String nodeIdentifier;\r
-    private final String svgDocument;\r
-    private final String svgScript;\r
-    private Point targetSize;\r
-\r
-//    public static AnimatedSVGImage loadFromURL(String nodeIdentifier, URL url) throws IOException {\r
-//        InputStream in = url.openStream();\r
-//        try {\r
-//            return new AnimatedSVGImage(nodeIdentifier, in);\r
-//        } finally {\r
-//            in.close();\r
-//        }\r
-//    }\r
-\r
-    public static IFactory<Image> createFactoryFromString(String nodeIdentifier, String svgDocument) {\r
-        return createFactoryFromString(svgDocument, null);\r
-    }\r
-\r
-    public static IFactory<Image> createFactoryFromString(String nodeIdentifier, String svgDocument, String svgScript, Point targetSize) {\r
-        return new AnimatedSVGFactory(nodeIdentifier, svgDocument, svgScript, targetSize);\r
-    }\r
-\r
-    static class AnimatedSVGFactory implements IFactory<Image> {\r
-        String nodeIdentifier;\r
-        String document;\r
-        String script;\r
-        Point targetSize;\r
-        public AnimatedSVGFactory(String nodeIdentifier, String document, String script, Point referenceSize) {\r
-            if (nodeIdentifier == null)\r
-                throw new NullPointerException("nodeIdentifier is null");\r
-            if (document == null)\r
-                throw new NullPointerException("document is null");\r
-            if (script == null)\r
-                throw new NullPointerException("script is null");\r
-\r
-            this.nodeIdentifier = nodeIdentifier;\r
-            this.document = document;\r
-            this.script = script;\r
-            this.targetSize = referenceSize;\r
-        }\r
-        public Image get() throws ProvisionException {\r
-            return new AnimatedSVGImage(nodeIdentifier, document, script, targetSize);\r
-        }\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (!obj.getClass().equals(getClass()))\r
-                return false;\r
-\r
-            AnimatedSVGFactory other = (AnimatedSVGFactory)obj;\r
-\r
-            if (!nodeIdentifier.equals(other.nodeIdentifier))\r
-                return false;\r
-            if (targetSize != null) {\r
-                if (!targetSize.equals(other.targetSize))\r
-                    return false;\r
-            } else {\r
-                if (other.targetSize != null)\r
-                    return false;\r
-            }\r
-\r
-            return document.equals(other.document);\r
-        }\r
-        @Override\r
-        public int hashCode() {\r
-            return nodeIdentifier.hashCode() * 31 + document.hashCode() + 123;\r
-        }\r
-    }\r
-\r
-//    public AnimatedSVGImage(String nodeIdentifier, String svgDocument)\r
-//    {\r
-//        this(nodeIdentifier, svgDocument, null);\r
-//    }\r
-\r
-    public AnimatedSVGImage(String nodeIdentifier, String svgDocument, String svgScript, Point targetSize)\r
-    {\r
-        if (nodeIdentifier == null)\r
-            throw new NullPointerException("nodeIdentifier is null");\r
-        if (svgDocument == null)\r
-            throw new NullPointerException("svgDocument is null");\r
-        if (svgScript == null)\r
-            throw new NullPointerException("svgScript is null");\r
-\r
-        this.nodeIdentifier = nodeIdentifier;\r
-        this.svgDocument = svgDocument;\r
-        this.svgScript = svgScript;\r
-        this.targetSize = targetSize;\r
-        //this.bounds = SVGNode.getBounds(svgDocument);\r
-    }\r
-\r
-//    public AnimatedSVGImage(String nodeIdentifier, InputStream svgInput)\r
-//    {\r
-//        if (nodeIdentifier == null)\r
-//            throw new NullPointerException("nodeIdentifier is null");\r
-//\r
-//        String data = "";\r
-//        try {\r
-//            BufferedReader reader = new BufferedReader(new InputStreamReader(svgInput));\r
-//            String line = "";\r
-//            while((line = reader.readLine()) != null) {\r
-//                data += line+"\n";\r
-//            }\r
-//        } catch(IOException e) {\r
-//        }\r
-//\r
-//        this.nodeIdentifier = nodeIdentifier;\r
-//        this.bounds = SVGNode.getBounds(data);\r
-//        this.svgDocument = data;\r
-//    }\r
-\r
-    @Override\r
-    public Node init(G2DParentNode parent) {\r
-        // FIXME: mipmaps enabled here by default, since some apps just don't work without them.\r
-        // Figure out a way to pass the mipmap argument from above\r
-\r
-        AnimatedSVGNode node = parent.getOrCreateNode(nodeIdentifier, AnimatedSVGNode.class);\r
-        node.setData(svgDocument);\r
-        node.setScript(svgScript);\r
-        node.setTargetSize(targetSize);\r
-        // If this is set to false, rendered graphics will pixelate and disppear during rotation. See #2396.\r
-        node.useMipMap(true);\r
-        return node;\r
-    }\r
-    \r
-       @Override\r
-       public Rectangle2D getBounds() {\r
-           if(bounds == null) bounds = SVGNode.getBounds(svgDocument);\r
-               return bounds;\r
-       }\r
-    \r
-       @Override\r
-       public Shape getOutline() {\r
-        return getBounds();\r
-    }\r
-\r
-    @Override\r
-    public void addImageListener(ImageListener listener) {\r
-    }\r
-\r
-    @Override\r
-    public EnumSet<Feature> getFeatures() {\r
-        return caps;\r
-    }\r
-\r
-    @Override\r
-    public void removeImageListener(ImageListener listener) {\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.svg;
+
+import java.awt.Point;
+import java.awt.Shape;
+import java.awt.geom.Rectangle2D;
+import java.util.EnumSet;
+
+import org.simantics.g2d.image.Image;
+import org.simantics.scenegraph.Node;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.nodes.AnimatedSVGNode;
+import org.simantics.scenegraph.g2d.nodes.SVGNode;
+import org.simantics.utils.datastructures.cache.IFactory;
+import org.simantics.utils.datastructures.cache.ProvisionException;
+
+/**
+ * This is a SVG implementation to the PaintableSymbol interface.
+ */
+public class AnimatedSVGImage implements Image {
+
+    static EnumSet<Feature> caps = EnumSet.of(Feature.Vector);
+
+    private Rectangle2D bounds;
+    private final String nodeIdentifier;
+    private final String svgDocument;
+    private final String svgScript;
+    private Point targetSize;
+
+//    public static AnimatedSVGImage loadFromURL(String nodeIdentifier, URL url) throws IOException {
+//        InputStream in = url.openStream();
+//        try {
+//            return new AnimatedSVGImage(nodeIdentifier, in);
+//        } finally {
+//            in.close();
+//        }
+//    }
+
+    public static IFactory<Image> createFactoryFromString(String nodeIdentifier, String svgDocument) {
+        return createFactoryFromString(svgDocument, null);
+    }
+
+    public static IFactory<Image> createFactoryFromString(String nodeIdentifier, String svgDocument, String svgScript, Point targetSize) {
+        return new AnimatedSVGFactory(nodeIdentifier, svgDocument, svgScript, targetSize);
+    }
+
+    static class AnimatedSVGFactory implements IFactory<Image> {
+        String nodeIdentifier;
+        String document;
+        String script;
+        Point targetSize;
+        public AnimatedSVGFactory(String nodeIdentifier, String document, String script, Point referenceSize) {
+            if (nodeIdentifier == null)
+                throw new NullPointerException("nodeIdentifier is null");
+            if (document == null)
+                throw new NullPointerException("document is null");
+            if (script == null)
+                throw new NullPointerException("script is null");
+
+            this.nodeIdentifier = nodeIdentifier;
+            this.document = document;
+            this.script = script;
+            this.targetSize = referenceSize;
+        }
+        public Image get() throws ProvisionException {
+            return new AnimatedSVGImage(nodeIdentifier, document, script, targetSize);
+        }
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (!obj.getClass().equals(getClass()))
+                return false;
+
+            AnimatedSVGFactory other = (AnimatedSVGFactory)obj;
+
+            if (!nodeIdentifier.equals(other.nodeIdentifier))
+                return false;
+            if (targetSize != null) {
+                if (!targetSize.equals(other.targetSize))
+                    return false;
+            } else {
+                if (other.targetSize != null)
+                    return false;
+            }
+
+            return document.equals(other.document);
+        }
+        @Override
+        public int hashCode() {
+            return nodeIdentifier.hashCode() * 31 + document.hashCode() + 123;
+        }
+    }
+
+//    public AnimatedSVGImage(String nodeIdentifier, String svgDocument)
+//    {
+//        this(nodeIdentifier, svgDocument, null);
+//    }
+
+    public AnimatedSVGImage(String nodeIdentifier, String svgDocument, String svgScript, Point targetSize)
+    {
+        if (nodeIdentifier == null)
+            throw new NullPointerException("nodeIdentifier is null");
+        if (svgDocument == null)
+            throw new NullPointerException("svgDocument is null");
+        if (svgScript == null)
+            throw new NullPointerException("svgScript is null");
+
+        this.nodeIdentifier = nodeIdentifier;
+        this.svgDocument = svgDocument;
+        this.svgScript = svgScript;
+        this.targetSize = targetSize;
+        //this.bounds = SVGNode.getBounds(svgDocument);
+    }
+
+//    public AnimatedSVGImage(String nodeIdentifier, InputStream svgInput)
+//    {
+//        if (nodeIdentifier == null)
+//            throw new NullPointerException("nodeIdentifier is null");
+//
+//        String data = "";
+//        try {
+//            BufferedReader reader = new BufferedReader(new InputStreamReader(svgInput));
+//            String line = "";
+//            while((line = reader.readLine()) != null) {
+//                data += line+"\n";
+//            }
+//        } catch(IOException e) {
+//        }
+//
+//        this.nodeIdentifier = nodeIdentifier;
+//        this.bounds = SVGNode.getBounds(data);
+//        this.svgDocument = data;
+//    }
+
+    @Override
+    public Node init(G2DParentNode parent) {
+        // FIXME: mipmaps enabled here by default, since some apps just don't work without them.
+        // Figure out a way to pass the mipmap argument from above
+
+        AnimatedSVGNode node = parent.getOrCreateNode(nodeIdentifier, AnimatedSVGNode.class);
+        node.setData(svgDocument);
+        node.setScript(svgScript);
+        node.setTargetSize(targetSize);
+        // If this is set to false, rendered graphics will pixelate and disppear during rotation. See #2396.
+        node.useMipMap(true);
+        return node;
+    }
+    
+       @Override
+       public Rectangle2D getBounds() {
+           if(bounds == null) bounds = SVGNode.getBounds(svgDocument);
+               return bounds;
+       }
+    
+       @Override
+       public Shape getOutline() {
+        return getBounds();
+    }
+
+    @Override
+    public void addImageListener(ImageListener listener) {
+    }
+
+    @Override
+    public EnumSet<Feature> getFeatures() {
+        return caps;
+    }
+
+    @Override
+    public void removeImageListener(ImageListener listener) {
+    }
+
+}