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