]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.scenegraph.tests;\r
2 \r
3 import java.awt.*;\r
4 import java.net.*;\r
5 import java.io.*;\r
6 \r
7 import javax.swing.*;\r
8 \r
9 import com.kitfox.svg.*;\r
10 import com.kitfox.svg.app.beans.*;\r
11 \r
12 \r
13 class IconPanel extends JPanel\r
14 {\r
15     public static final long serialVersionUID = 0;\r
16     \r
17     SVGIcon icon;\r
18     \r
19     public IconPanel() {\r
20         setPreferredSize(new Dimension(400, 400));\r
21     }\r
22 \r
23     public void load() throws IOException\r
24     {\r
25         InputStream is = getClass().getResourceAsStream("test_caption_frame.svg");\r
26         URI uri = SVGCache.getSVGUniverse().loadSVG(is, "myImage");\r
27         System.out.println("loaded: " + uri);\r
28         icon = new SVGIcon();\r
29         icon.setSvgURI(uri);\r
30     }\r
31     \r
32     public void paintComponent(Graphics g)\r
33     {\r
34         Graphics2D g2d = (Graphics2D) g;\r
35         final int width = getWidth();\r
36         final int height = getHeight();\r
37         \r
38         g.setColor(getBackground());\r
39         g.fillRect(0, 0, width, height);\r
40         g2d.scale(10, 10);\r
41         icon.paintIcon(this, g, width/20, height/20);\r
42     }\r
43     \r
44 }\r
45 \r
46 /**\r
47  * @author  kitfox\r
48  */\r
49 public class SVGIODemoFrame extends javax.swing.JFrame\r
50 {\r
51     public static final long serialVersionUID = 0;\r
52     \r
53     IconPanel panel = new IconPanel();\r
54     \r
55     /** Creates new form SVGIconDemo */\r
56     public SVGIODemoFrame()\r
57     {\r
58         initComponents();\r
59         try {\r
60             panel.load();\r
61         } catch (IOException e) {\r
62             e.printStackTrace();\r
63         }\r
64 \r
65         this.getContentPane().add(panel, BorderLayout.CENTER);\r
66         \r
67         pack();\r
68     }\r
69     \r
70     /** This method is called from within the constructor to\r
71      * initialize the form.\r
72      * WARNING: Do NOT modify this code. The content of this method is\r
73      * always regenerated by the Form Editor.\r
74      */\r
75     private void initComponents()\r
76     {\r
77 \r
78         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);\r
79         setLayout(new java.awt.BorderLayout());\r
80 \r
81     }\r
82     \r
83     public static void main(String args[])\r
84     {\r
85         java.awt.EventQueue.invokeLater(new Runnable()\r
86         {\r
87             public void run()\r
88             {\r
89                 new SVGIODemoFrame().setVisible(true);\r
90             }\r
91         });\r
92     }\r
93     \r
94 }