Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.fullthrust.client;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.io.PrintWriter;
- import java.io.StringReader;
- import java.io.StringWriter;
- import java.net.URI;
- import javax.swing.JPanel;
- import com.kitfox.svg.SVGCache;
- import com.kitfox.svg.SVGElement;
- import com.kitfox.svg.SVGElementException;
- import com.kitfox.svg.SVGException;
- import com.kitfox.svg.animation.AnimationElement;
- import com.kitfox.svg.app.beans.SVGIcon;
- class TestPanel extends JPanel
- {
- public static final long serialVersionUID = 0;
- final SVGIcon icon;
- URI uri;
- SVGElement root;
- public TestPanel()
- {
- StringReader reader = new StringReader(makeDynamicSVG());
- uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
- icon = new SVGIcon();
- icon.setAntiAlias(true);
- icon.setSvgURI(uri);
- root = icon.getSvgUniverse().getDiagram(uri).getRoot();
- setPreferredSize(new Dimension(400, 400));
- }
- public void paintComponent(Graphics g)
- {
- final int width = getWidth();
- final int height = getHeight();
- g.setColor(getBackground());
- g.fillRect(0, 0, width, height);
- icon.paintIcon(this, g, 0, 0);
- }
- private String makeDynamicSVG()
- {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:16\" viewBox=\"781 -391 1177 826\">");
- pw.println("<rect x=\"0\" y=\"0\" width=\"2000\" height=\"1000\" style=\"stroke:blue;fill:white\"/>");
- pw.println("</svg>");
- pw.close();
- return sw.toString();
- }
- }
- /**
- *
- * @author kitfox
- */
- public class TestClient2 extends javax.swing.JFrame
- {
- public static final long serialVersionUID = 0;
- TestPanel panel = new TestPanel();
- public TestClient2()
- {
- initComponents();
- panel_display.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.
- */
- // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
- private void initComponents()
- {
- panel_display = new javax.swing.JPanel();
- button1 = new javax.swing.JButton();
- button2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- panel_display.setLayout(new java.awt.BorderLayout());
- getContentPane().add(panel_display, java.awt.BorderLayout.CENTER);
- button1.setText("Visible");
- button1.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- SVGElement root = TestClient2.this.panel.root;
- try {
- root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
- root.updateTime(0f);
- repaint();
- } catch (SVGElementException e) {
- e.printStackTrace();
- } catch (SVGException e) {
- e.printStackTrace();
- }
- }
- });
- button2.setText("Invisible");
- button2.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- SVGElement root = TestClient2.this.panel.root;
- try {
- root.setAttribute("viewBox", AnimationElement.AT_XML, "800 0 2368 1652");
- root.updateTime(0f);
- repaint();
- } catch (SVGElementException e) {
- e.printStackTrace();
- } catch (SVGException e) {
- e.printStackTrace();
- }
- }
- });
- panel_display.add(button1, java.awt.BorderLayout.EAST);
- panel_display.add(button2, java.awt.BorderLayout.WEST);
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[])
- {
- java.awt.EventQueue.invokeLater(new Runnable()
- {
- public void run()
- {
- new TestClient2().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton button1;
- private javax.swing.JButton button2;
- private javax.swing.JPanel panel_display;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement