/*
 * Main.java
 *
 * Created on 20. únor 2009, 15:44
 */

package batikdemo;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.Document;

/**
 *
 * @author  karry
 */
public class Main extends javax.swing.JFrame {

        
    /** Creates new form Main */
    public Main() {
        initComponents();
        try {
            InputStream svgInputStream = getClass().getResourceAsStream("/batikdemo/controller.svg");

            String parserClassName = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parserClassName);

            // I get exception on this line
            Document doc = f.createDocument(parserClassName, svgInputStream);

            svgInputStream.close();
            jSVGCanvas1.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); // nutne pro updatovani pri upravach dokumentu (volani getUpdateManager...)
            jSVGCanvas1.setDocument(doc);

            if (doc.getDocumentElement().getAttribute("viewBox").isEmpty()) {
                Logger.getLogger(this.getClass().getName()).warning("Input SVG file has't set viewBox. Disable autoresize!");
            }
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSVGCanvas1 = new org.apache.batik.swing.JSVGCanvas();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jSVGCanvas1Layout = new javax.swing.GroupLayout(jSVGCanvas1);
        jSVGCanvas1.setLayout(jSVGCanvas1Layout);
        jSVGCanvas1Layout.setHorizontalGroup(
            jSVGCanvas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jSVGCanvas1Layout.setVerticalGroup(
            jSVGCanvas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSVGCanvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSVGCanvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-410)/2, (screenSize.height-330)/2, 410, 330);
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.apache.batik.swing.JSVGCanvas jSVGCanvas1;
    // End of variables declaration//GEN-END:variables

}
