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