]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/testcases/org/simantics/scenegraph/tests/SVGIODemoFrame.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / testcases / org / simantics / scenegraph / tests / SVGIODemoFrame.java
diff --git a/bundles/org.simantics.scenegraph/testcases/org/simantics/scenegraph/tests/SVGIODemoFrame.java b/bundles/org.simantics.scenegraph/testcases/org/simantics/scenegraph/tests/SVGIODemoFrame.java
new file mode 100644 (file)
index 0000000..f46155f
--- /dev/null
@@ -0,0 +1,94 @@
+package org.simantics.scenegraph.tests;\r
+\r
+import java.awt.*;\r
+import java.net.*;\r
+import java.io.*;\r
+\r
+import javax.swing.*;\r
+\r
+import com.kitfox.svg.*;\r
+import com.kitfox.svg.app.beans.*;\r
+\r
+\r
+class IconPanel extends JPanel\r
+{\r
+    public static final long serialVersionUID = 0;\r
+    \r
+    SVGIcon icon;\r
+    \r
+    public IconPanel() {\r
+        setPreferredSize(new Dimension(400, 400));\r
+    }\r
+\r
+    public void load() throws IOException\r
+    {\r
+        InputStream is = getClass().getResourceAsStream("test_caption_frame.svg");\r
+        URI uri = SVGCache.getSVGUniverse().loadSVG(is, "myImage");\r
+        System.out.println("loaded: " + uri);\r
+        icon = new SVGIcon();\r
+        icon.setSvgURI(uri);\r
+    }\r
+    \r
+    public void paintComponent(Graphics g)\r
+    {\r
+        Graphics2D g2d = (Graphics2D) g;\r
+        final int width = getWidth();\r
+        final int height = getHeight();\r
+        \r
+        g.setColor(getBackground());\r
+        g.fillRect(0, 0, width, height);\r
+        g2d.scale(10, 10);\r
+        icon.paintIcon(this, g, width/20, height/20);\r
+    }\r
+    \r
+}\r
+\r
+/**\r
+ * @author  kitfox\r
+ */\r
+public class SVGIODemoFrame extends javax.swing.JFrame\r
+{\r
+    public static final long serialVersionUID = 0;\r
+    \r
+    IconPanel panel = new IconPanel();\r
+    \r
+    /** Creates new form SVGIconDemo */\r
+    public SVGIODemoFrame()\r
+    {\r
+        initComponents();\r
+        try {\r
+            panel.load();\r
+        } catch (IOException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        this.getContentPane().add(panel, BorderLayout.CENTER);\r
+        \r
+        pack();\r
+    }\r
+    \r
+    /** This method is called from within the constructor to\r
+     * initialize the form.\r
+     * WARNING: Do NOT modify this code. The content of this method is\r
+     * always regenerated by the Form Editor.\r
+     */\r
+    private void initComponents()\r
+    {\r
+\r
+        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);\r
+        setLayout(new java.awt.BorderLayout());\r
+\r
+    }\r
+    \r
+    public static void main(String args[])\r
+    {\r
+        java.awt.EventQueue.invokeLater(new Runnable()\r
+        {\r
+            public void run()\r
+            {\r
+                new SVGIODemoFrame().setVisible(true);\r
+            }\r
+        });\r
+    }\r
+    \r
+}
\ No newline at end of file