summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/kitfox/svg/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/kitfox/svg/app')
-rw-r--r--src/main/java/com/kitfox/svg/app/MainFrame.form65
-rw-r--r--src/main/java/com/kitfox/svg/app/MainFrame.java134
-rw-r--r--src/main/java/com/kitfox/svg/app/PlayerDialog.form133
-rw-r--r--src/main/java/com/kitfox/svg/app/PlayerDialog.java289
-rw-r--r--src/main/java/com/kitfox/svg/app/PlayerThread.java129
-rw-r--r--src/main/java/com/kitfox/svg/app/PlayerThreadListener.java37
-rw-r--r--src/main/java/com/kitfox/svg/app/SVGPlayer.form118
-rw-r--r--src/main/java/com/kitfox/svg/app/SVGPlayer.java426
-rw-r--r--src/main/java/com/kitfox/svg/app/SVGViewer.form118
-rw-r--r--src/main/java/com/kitfox/svg/app/SVGViewer.java421
-rw-r--r--src/main/java/com/kitfox/svg/app/VersionDialog.form64
-rw-r--r--src/main/java/com/kitfox/svg/app/VersionDialog.java151
-rw-r--r--src/main/java/com/kitfox/svg/app/ant/SVGToImageAntTask.java251
-rw-r--r--src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.form29
-rw-r--r--src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.java91
-rw-r--r--src/main/java/com/kitfox/svg/app/beans/SVGIcon.java385
-rw-r--r--src/main/java/com/kitfox/svg/app/beans/SVGPanel.form13
-rw-r--r--src/main/java/com/kitfox/svg/app/beans/SVGPanel.java243
18 files changed, 3097 insertions, 0 deletions
diff --git a/src/main/java/com/kitfox/svg/app/MainFrame.form b/src/main/java/com/kitfox/svg/app/MainFrame.form
new file mode 100644
index 0000000..e285b77
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/MainFrame.form
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <Properties>
+ <Property name="title" type="java.lang.String" value="SVG Salamander - Application Launcher"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitForm"/>
+ </Events>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="jPanel1">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
+ <Property name="axis" type="int" value="1"/>
+ </Layout>
+ <SubComponents>
+ <Component class="javax.swing.JButton" name="bn_svgViewer">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="SVG Viewer (No animation)"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_svgViewerActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="bn_svgViewer1">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="SVG Player (Animation)"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_svgViewer1ActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="jPanel2">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="South"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JButton" name="bn_quit">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Quit"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_quitActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/MainFrame.java b/src/main/java/com/kitfox/svg/app/MainFrame.java
new file mode 100644
index 0000000..596ec05
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/MainFrame.java
@@ -0,0 +1,134 @@
+/*
+ * MainFrame.java
+ *
+ * Created on September 6, 2004, 1:19 AM
+ */
+
+package com.kitfox.svg.app;
+
+/**
+ *
+ * @author kitfox
+ */
+public class MainFrame extends javax.swing.JFrame
+{
+ public static final long serialVersionUID = 1;
+
+ /** Creates new form MainFrame */
+ public MainFrame()
+ {
+ initComponents();
+ }
+
+ /** 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()//GEN-BEGIN:initComponents
+ {
+ jPanel1 = new javax.swing.JPanel();
+ bn_svgViewer = new javax.swing.JButton();
+ bn_svgViewer1 = new javax.swing.JButton();
+ jPanel2 = new javax.swing.JPanel();
+ bn_quit = new javax.swing.JButton();
+
+ setTitle("SVG Salamander - Application Launcher");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing(java.awt.event.WindowEvent evt)
+ {
+ exitForm(evt);
+ }
+ });
+
+ jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
+
+ bn_svgViewer.setText("SVG Viewer (No animation)");
+ bn_svgViewer.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_svgViewerActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(bn_svgViewer);
+
+ bn_svgViewer1.setText("SVG Player (Animation)");
+ bn_svgViewer1.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_svgViewer1ActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(bn_svgViewer1);
+
+ getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
+
+ bn_quit.setText("Quit");
+ bn_quit.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_quitActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(bn_quit);
+
+ getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
+
+ pack();
+ }//GEN-END:initComponents
+
+ private void bn_svgViewer1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_svgViewer1ActionPerformed
+ {//GEN-HEADEREND:event_bn_svgViewer1ActionPerformed
+ SVGPlayer.main(null);
+
+ close();
+ }//GEN-LAST:event_bn_svgViewer1ActionPerformed
+
+ private void bn_svgViewerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_svgViewerActionPerformed
+ {//GEN-HEADEREND:event_bn_svgViewerActionPerformed
+ SVGViewer.main(null);
+
+ close();
+ }//GEN-LAST:event_bn_svgViewerActionPerformed
+
+ private void bn_quitActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_quitActionPerformed
+ {//GEN-HEADEREND:event_bn_quitActionPerformed
+ exitForm(null);
+ }//GEN-LAST:event_bn_quitActionPerformed
+
+ /** Exit the Application */
+ private void exitForm(java.awt.event.WindowEvent evt)//GEN-FIRST:event_exitForm
+ {
+ System.exit(0);
+ }//GEN-LAST:event_exitForm
+
+ private void close()
+ {
+ this.setVisible(false);
+ this.dispose();
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {
+ new MainFrame().setVisible(true);
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton bn_quit;
+ private javax.swing.JButton bn_svgViewer;
+ private javax.swing.JButton bn_svgViewer1;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/PlayerDialog.form b/src/main/java/com/kitfox/svg/app/PlayerDialog.form
new file mode 100644
index 0000000..628bbf8
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/PlayerDialog.form
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
+ <Properties>
+ <Property name="defaultCloseOperation" type="int" value="2"/>
+ <Property name="title" type="java.lang.String" value="Player"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosed" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosed"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="jPanel1">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="North"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JButton" name="bn_playBack">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="&lt;"/>
+ <Property name="toolTipText" type="java.lang.String" value="Play backwards"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_playBackActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="bn_stop">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="||"/>
+ <Property name="toolTipText" type="java.lang.String" value="Stop playback"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_stopActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="bn_playFwd">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="&gt;"/>
+ <Property name="toolTipText" type="java.lang.String" value="Play Forwards"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_playFwdActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="jPanel2">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
+ <Property name="axis" type="int" value="1"/>
+ </Layout>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="jPanel3">
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="jLabel1">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Cur Time"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JTextField" name="text_curTime">
+ <Properties>
+ <Property name="horizontalAlignment" type="int" value="2"/>
+ <Property name="text" type="java.lang.String" value="0"/>
+ <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+ <Dimension value="[100, 21]"/>
+ </Property>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="text_curTimeActionPerformed"/>
+ <EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="text_curTimeFocusLost"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="bn_time0">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Time 0"/>
+ <Property name="toolTipText" type="java.lang.String" value="Reset time to first frame"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_time0ActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="jPanel4">
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="jLabel2">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Frames Per Second"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JTextField" name="text_timeStep">
+ <Properties>
+ <Property name="horizontalAlignment" type="int" value="4"/>
+ <Property name="text" type="java.lang.String" value="60"/>
+ <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+ <Dimension value="[100, 21]"/>
+ </Property>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="text_timeStepActionPerformed"/>
+ <EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="text_timeStepFocusLost"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/PlayerDialog.java b/src/main/java/com/kitfox/svg/app/PlayerDialog.java
new file mode 100644
index 0000000..6d663f0
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/PlayerDialog.java
@@ -0,0 +1,289 @@
+/*
+ * PlayerDialog.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on September 28, 2004, 9:56 PM
+ */
+
+package com.kitfox.svg.app;
+
+/**
+ *
+ * @author kitfox
+ */
+public class PlayerDialog extends javax.swing.JDialog implements PlayerThreadListener
+{
+ public static final long serialVersionUID = 1;
+
+ PlayerThread thread;
+
+ final SVGPlayer parent;
+
+ /** Creates new form PlayerDialog */
+ public PlayerDialog(SVGPlayer parent)
+ {
+ super(parent, false);
+ initComponents();
+
+ this.parent = parent;
+
+ thread = new PlayerThread();
+ thread.addListener(this);
+
+ text_timeStepActionPerformed(null);
+ }
+
+ public void updateTime(double curTime, double timeStep, int playState)
+ {
+ if (playState == PlayerThread.PS_STOP) return;
+
+ text_curTime.setText("" + (float)curTime);
+ parent.updateTime(curTime);
+// text_timeStep.setText("" + (int)(1.0 / timeStep));
+ }
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ jPanel1 = new javax.swing.JPanel();
+ bn_playBack = new javax.swing.JButton();
+ bn_stop = new javax.swing.JButton();
+ bn_playFwd = new javax.swing.JButton();
+ jPanel2 = new javax.swing.JPanel();
+ jPanel3 = new javax.swing.JPanel();
+ jLabel1 = new javax.swing.JLabel();
+ text_curTime = new javax.swing.JTextField();
+ bn_time0 = new javax.swing.JButton();
+ jPanel4 = new javax.swing.JPanel();
+ jLabel2 = new javax.swing.JLabel();
+ text_timeStep = new javax.swing.JTextField();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Player");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosed(java.awt.event.WindowEvent evt)
+ {
+ formWindowClosed(evt);
+ }
+ });
+
+ bn_playBack.setText("<");
+ bn_playBack.setToolTipText("Play backwards");
+ bn_playBack.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_playBackActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(bn_playBack);
+
+ bn_stop.setText("||");
+ bn_stop.setToolTipText("Stop playback");
+ bn_stop.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_stopActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(bn_stop);
+
+ bn_playFwd.setText(">");
+ bn_playFwd.setToolTipText("Play Forwards");
+ bn_playFwd.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_playFwdActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(bn_playFwd);
+
+ getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
+
+ jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
+
+ jLabel1.setText("Cur Time");
+ jPanel3.add(jLabel1);
+
+ text_curTime.setHorizontalAlignment(javax.swing.JTextField.LEFT);
+ text_curTime.setText("0");
+ text_curTime.setPreferredSize(new java.awt.Dimension(100, 21));
+ text_curTime.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ text_curTimeActionPerformed(evt);
+ }
+ });
+ text_curTime.addFocusListener(new java.awt.event.FocusAdapter()
+ {
+ public void focusLost(java.awt.event.FocusEvent evt)
+ {
+ text_curTimeFocusLost(evt);
+ }
+ });
+
+ jPanel3.add(text_curTime);
+
+ bn_time0.setText("Time 0");
+ bn_time0.setToolTipText("Reset time to first frame");
+ bn_time0.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_time0ActionPerformed(evt);
+ }
+ });
+
+ jPanel3.add(bn_time0);
+
+ jPanel2.add(jPanel3);
+
+ jLabel2.setText("Frames Per Second");
+ jPanel4.add(jLabel2);
+
+ text_timeStep.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
+ text_timeStep.setText("60");
+ text_timeStep.setPreferredSize(new java.awt.Dimension(100, 21));
+ text_timeStep.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ text_timeStepActionPerformed(evt);
+ }
+ });
+ text_timeStep.addFocusListener(new java.awt.event.FocusAdapter()
+ {
+ public void focusLost(java.awt.event.FocusEvent evt)
+ {
+ text_timeStepFocusLost(evt);
+ }
+ });
+
+ jPanel4.add(text_timeStep);
+
+ jPanel2.add(jPanel4);
+
+ getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void bn_time0ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_time0ActionPerformed
+ {//GEN-HEADEREND:event_bn_time0ActionPerformed
+ thread.setCurTime(0);
+ }//GEN-LAST:event_bn_time0ActionPerformed
+
+ private void bn_playFwdActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playFwdActionPerformed
+ {//GEN-HEADEREND:event_bn_playFwdActionPerformed
+ thread.setPlayState(PlayerThread.PS_PLAY_FWD);
+ }//GEN-LAST:event_bn_playFwdActionPerformed
+
+ private void bn_stopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_stopActionPerformed
+ {//GEN-HEADEREND:event_bn_stopActionPerformed
+ thread.setPlayState(PlayerThread.PS_STOP);
+ }//GEN-LAST:event_bn_stopActionPerformed
+
+ private void bn_playBackActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playBackActionPerformed
+ {//GEN-HEADEREND:event_bn_playBackActionPerformed
+ thread.setPlayState(PlayerThread.PS_PLAY_BACK);
+ }//GEN-LAST:event_bn_playBackActionPerformed
+
+ private void formWindowClosed(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosed
+ {//GEN-HEADEREND:event_formWindowClosed
+// thread.exit();
+ }//GEN-LAST:event_formWindowClosed
+
+ private void text_timeStepFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_timeStepFocusLost
+ {//GEN-HEADEREND:event_text_timeStepFocusLost
+ text_timeStepActionPerformed(null);
+ }//GEN-LAST:event_text_timeStepFocusLost
+
+ private void text_timeStepActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_timeStepActionPerformed
+ {//GEN-HEADEREND:event_text_timeStepActionPerformed
+ try
+ {
+ int val = Integer.parseInt(text_timeStep.getText());
+ thread.setTimeStep(1.0 / val);
+ }
+ catch (Exception e)
+ {
+ }
+
+ double d = thread.getTimeStep();
+ String newStrn = "" + (int)(1f / d);
+ if (newStrn.equals(text_timeStep.getText())) return;
+ text_timeStep.setText(newStrn);
+
+// text_timeStepActionPerformed(null);
+ }//GEN-LAST:event_text_timeStepActionPerformed
+
+ private void text_curTimeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_curTimeActionPerformed
+ {//GEN-HEADEREND:event_text_curTimeActionPerformed
+ try
+ {
+ double val = Double.parseDouble(text_curTime.getText());
+ thread.setCurTime(val);
+ }
+ catch (Exception e)
+ {
+ }
+
+ double d = thread.getCurTime();
+ text_curTime.setText("" + (float)d);
+
+ text_timeStepActionPerformed(null);
+ }//GEN-LAST:event_text_curTimeActionPerformed
+
+ private void text_curTimeFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_curTimeFocusLost
+ {//GEN-HEADEREND:event_text_curTimeFocusLost
+ text_curTimeActionPerformed(null);
+ }//GEN-LAST:event_text_curTimeFocusLost
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton bn_playBack;
+ private javax.swing.JButton bn_playFwd;
+ private javax.swing.JButton bn_stop;
+ private javax.swing.JButton bn_time0;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JPanel jPanel3;
+ private javax.swing.JPanel jPanel4;
+ private javax.swing.JTextField text_curTime;
+ private javax.swing.JTextField text_timeStep;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/PlayerThread.java b/src/main/java/com/kitfox/svg/app/PlayerThread.java
new file mode 100644
index 0000000..90a3a28
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/PlayerThread.java
@@ -0,0 +1,129 @@
+/*
+ * PlayerThread.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on September 28, 2004, 10:07 PM
+ */
+
+
+package com.kitfox.svg.app;
+
+import java.util.*;
+
+/**
+ *
+ * @author kitfox
+ */
+public class PlayerThread implements Runnable
+{
+ HashSet listeners = new HashSet();
+
+ double curTime = 0;
+ double timeStep = .2;
+
+ public static final int PS_STOP = 0;
+ public static final int PS_PLAY_FWD = 1;
+ public static final int PS_PLAY_BACK = 2;
+
+ int playState = PS_STOP;
+
+ Thread thread;
+
+ /** Creates a new instance of PlayerThread */
+ public PlayerThread()
+ {
+ thread = new Thread(this);
+ thread.start();
+ }
+
+ public void run()
+ {
+ while (thread != null)
+ {
+ synchronized (this)
+ {
+ switch (playState)
+ {
+ case PS_PLAY_FWD:
+ curTime += timeStep;
+ break;
+ case PS_PLAY_BACK:
+ curTime -= timeStep;
+ if (curTime < 0) curTime = 0;
+ break;
+ default:
+ case PS_STOP:
+ break;
+ }
+
+ fireTimeUpdateEvent();
+ }
+
+ try
+ {
+ Thread.sleep((long)(timeStep * 1000));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public void exit() { thread = null; }
+ public synchronized void addListener(PlayerThreadListener listener)
+ {
+ listeners.add(listener);
+ }
+
+ public synchronized double getCurTime() { return curTime; }
+
+ public synchronized void setCurTime(double time)
+ {
+ curTime = time;
+ }
+
+ public synchronized double getTimeStep() { return timeStep; }
+
+ public synchronized void setTimeStep(double time)
+ {
+ timeStep = time;
+ if (timeStep < .01) timeStep = .01;
+ }
+
+ public synchronized int getPlayState() { return playState; }
+
+ public synchronized void setPlayState(int playState)
+ {
+ this.playState = playState;
+ }
+
+ private void fireTimeUpdateEvent()
+ {
+ for (Iterator it = listeners.iterator(); it.hasNext();)
+ {
+ PlayerThreadListener listener = (PlayerThreadListener)it.next();
+ listener.updateTime(curTime, timeStep, playState);
+ }
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/app/PlayerThreadListener.java b/src/main/java/com/kitfox/svg/app/PlayerThreadListener.java
new file mode 100644
index 0000000..b6438a0
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/PlayerThreadListener.java
@@ -0,0 +1,37 @@
+/*
+ * PlayerThreadListener.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on September 28, 2004, 10:15 PM
+ */
+
+package com.kitfox.svg.app;
+
+/**
+ *
+ * @author kitfox
+ */
+public interface PlayerThreadListener
+{
+ public void updateTime(double curTime, double timeStep, int playState);
+}
diff --git a/src/main/java/com/kitfox/svg/app/SVGPlayer.form b/src/main/java/com/kitfox/svg/app/SVGPlayer.form
new file mode 100644
index 0000000..f98c2be
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/SVGPlayer.form
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Menu class="javax.swing.JMenuBar" name="jMenuBar1">
+ <SubComponents>
+ <Menu class="javax.swing.JMenu" name="menu_file">
+ <Properties>
+ <Property name="mnemonic" type="int" value="102"/>
+ <Property name="text" type="java.lang.String" value="File"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_loadFile">
+ <Properties>
+ <Property name="mnemonic" type="int" value="108"/>
+ <Property name="text" type="java.lang.String" value="Load File..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_loadFileActionPerformed"/>
+ </Events>
+ </MenuItem>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_loadUrl">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Load URL..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_loadUrlActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="menu_window">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Window"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_player">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Player"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_playerActionPerformed"/>
+ </Events>
+ </MenuItem>
+ <MenuItem class="javax.swing.JSeparator" name="jSeparator2">
+ </MenuItem>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_800x600">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="800 x 600"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_800x600ActionPerformed"/>
+ </Events>
+ </MenuItem>
+ <MenuItem class="javax.swing.JCheckBoxMenuItem" name="CheckBoxMenuItem_anonInputStream">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Anonymous Input Stream"/>
+ </Properties>
+ </MenuItem>
+ <MenuItem class="javax.swing.JCheckBoxMenuItem" name="cmCheck_verbose">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Verbose"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmCheck_verboseActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="menu_help">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Help"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_about">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="About..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_aboutActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ </SubComponents>
+ </Menu>
+ </NonVisualComponents>
+ <Properties>
+ <Property name="title" type="java.lang.String" value="SVG Player - Salamander Project"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitForm"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JScrollPane" name="scrollPane_svgArea">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/SVGPlayer.java b/src/main/java/com/kitfox/svg/app/SVGPlayer.java
new file mode 100644
index 0000000..100a3e8
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/SVGPlayer.java
@@ -0,0 +1,426 @@
+/*
+ * SVGViewer.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on April 3, 2004, 5:28 PM
+ */
+
+package com.kitfox.svg.app;
+
+import java.net.*;
+import java.awt.*;
+import java.io.*;
+import java.util.regex.*;
+
+import javax.swing.*;
+
+import com.kitfox.svg.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.geom.Point2D;
+import java.security.AccessControlException;
+import java.util.Vector;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class SVGPlayer extends javax.swing.JFrame
+{
+ public static final long serialVersionUID = 1;
+
+ SVGDisplayPanel svgDisplayPanel = new SVGDisplayPanel();
+
+ final PlayerDialog playerDialog;
+
+ SVGUniverse universe;
+
+ /** FileChooser for running in trusted environments */
+ final JFileChooser fileChooser;
+ {
+// fileChooser = new JFileChooser(new File("."));
+ JFileChooser fc = null;
+ try
+ {
+ fc = new JFileChooser();
+ fc.setFileFilter(
+ new javax.swing.filechooser.FileFilter() {
+ final Matcher matchLevelFile = Pattern.compile(".*\\.svg").matcher("");
+
+ public boolean accept(File file)
+ {
+ if (file.isDirectory()) return true;
+
+ matchLevelFile.reset(file.getName());
+ return matchLevelFile.matches();
+ }
+
+ public String getDescription() { return "SVG file (*.svg)"; }
+ }
+ );
+ }
+ catch (AccessControlException ex)
+ {
+ //Do not create file chooser if webstart refuses permissions
+ }
+ fileChooser = fc;
+ }
+
+ /** Backup file service for opening files in WebStart situations */
+ /*
+ final FileOpenService fileOpenService;
+ {
+ try
+ {
+ fileOpenService = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
+ }
+ catch (UnavailableServiceException e)
+ {
+ fileOpenService = null;
+ }
+ }
+ */
+
+ /** Creates new form SVGViewer */
+ public SVGPlayer() {
+ initComponents();
+
+ setSize(800, 600);
+
+ svgDisplayPanel.setBgColor(Color.white);
+ svgDisplayPanel.addMouseListener(new MouseAdapter()
+ {
+ public void mouseClicked(MouseEvent evt)
+ {
+ SVGDiagram diagram = svgDisplayPanel.getDiagram();
+ if (diagram == null) return;
+
+ System.out.println("Picking at cursor (" + evt.getX() + ", " + evt.getY() + ")");
+ try
+ {
+ Vector paths = diagram.pick(new Point2D.Float(evt.getX(), evt.getY()), null);
+ for (int i = 0; i < paths.size(); i++)
+ {
+ Vector path = (Vector)paths.get(i);
+ System.out.println(pathToString(path));
+ }
+ }
+ catch (SVGException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+ );
+
+ svgDisplayPanel.setPreferredSize(getSize());
+ scrollPane_svgArea.setViewportView(svgDisplayPanel);
+
+ playerDialog = new PlayerDialog(this);
+ }
+
+ private String pathToString(Vector path)
+ {
+ if (path.size() == 0) return "";
+
+ StringBuffer sb = new StringBuffer();
+ sb.append(path.get(0));
+ for (int i = 1; i < path.size(); i++)
+ {
+ sb.append("/");
+ sb.append(((SVGElement)path.get(i)).getId());
+ }
+ return sb.toString();
+ }
+
+ public void updateTime(double curTime)
+ {
+ try
+ {
+ if (universe != null)
+ {
+ universe.setCurTime(curTime);
+ universe.updateTime();
+ // svgDisplayPanel.updateTime(curTime);
+ repaint();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void loadURL(URL url)
+ {
+ boolean verbose = cmCheck_verbose.isSelected();
+
+ universe = new SVGUniverse();
+ universe.setVerbose(verbose);
+ SVGDiagram diagram = null;
+
+ if (!CheckBoxMenuItem_anonInputStream.isSelected())
+ {
+ //Load from a disk with a valid URL
+ URI uri = universe.loadSVG(url);
+
+ if (verbose) System.err.println(uri.toString());
+
+ diagram = universe.getDiagram(uri);
+ }
+ else
+ {
+ //Load from a stream with no particular valid URL
+ try
+ {
+ InputStream is = url.openStream();
+ URI uri = universe.loadSVG(is, "defaultName");
+
+ if (verbose) System.err.println(uri.toString());
+
+ diagram = universe.getDiagram(uri);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ svgDisplayPanel.setDiagram(diagram);
+ repaint();
+ }
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ scrollPane_svgArea = new javax.swing.JScrollPane();
+ jMenuBar1 = new javax.swing.JMenuBar();
+ menu_file = new javax.swing.JMenu();
+ cm_loadFile = new javax.swing.JMenuItem();
+ cm_loadUrl = new javax.swing.JMenuItem();
+ menu_window = new javax.swing.JMenu();
+ cm_player = new javax.swing.JMenuItem();
+ jSeparator2 = new javax.swing.JSeparator();
+ cm_800x600 = new javax.swing.JMenuItem();
+ CheckBoxMenuItem_anonInputStream = new javax.swing.JCheckBoxMenuItem();
+ cmCheck_verbose = new javax.swing.JCheckBoxMenuItem();
+ menu_help = new javax.swing.JMenu();
+ cm_about = new javax.swing.JMenuItem();
+
+ setTitle("SVG Player - Salamander Project");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing(java.awt.event.WindowEvent evt)
+ {
+ exitForm(evt);
+ }
+ });
+
+ getContentPane().add(scrollPane_svgArea, java.awt.BorderLayout.CENTER);
+
+ menu_file.setMnemonic('f');
+ menu_file.setText("File");
+ cm_loadFile.setMnemonic('l');
+ cm_loadFile.setText("Load File...");
+ cm_loadFile.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_loadFileActionPerformed(evt);
+ }
+ });
+
+ menu_file.add(cm_loadFile);
+
+ cm_loadUrl.setText("Load URL...");
+ cm_loadUrl.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_loadUrlActionPerformed(evt);
+ }
+ });
+
+ menu_file.add(cm_loadUrl);
+
+ jMenuBar1.add(menu_file);
+
+ menu_window.setText("Window");
+ cm_player.setText("Player");
+ cm_player.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_playerActionPerformed(evt);
+ }
+ });
+
+ menu_window.add(cm_player);
+
+ menu_window.add(jSeparator2);
+
+ cm_800x600.setText("800 x 600");
+ cm_800x600.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_800x600ActionPerformed(evt);
+ }
+ });
+
+ menu_window.add(cm_800x600);
+
+ CheckBoxMenuItem_anonInputStream.setText("Anonymous Input Stream");
+ menu_window.add(CheckBoxMenuItem_anonInputStream);
+
+ cmCheck_verbose.setText("Verbose");
+ cmCheck_verbose.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cmCheck_verboseActionPerformed(evt);
+ }
+ });
+
+ menu_window.add(cmCheck_verbose);
+
+ jMenuBar1.add(menu_window);
+
+ menu_help.setText("Help");
+ cm_about.setText("About...");
+ cm_about.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_aboutActionPerformed(evt);
+ }
+ });
+
+ menu_help.add(cm_about);
+
+ jMenuBar1.add(menu_help);
+
+ setJMenuBar(jMenuBar1);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void cm_loadUrlActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_loadUrlActionPerformed
+ {//GEN-HEADEREND:event_cm_loadUrlActionPerformed
+ String urlStrn = JOptionPane.showInputDialog(this, "Enter URL of SVG file");
+ if (urlStrn == null) return;
+
+ try
+ {
+ URL url = new URL(urlStrn);
+ loadURL(url);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }//GEN-LAST:event_cm_loadUrlActionPerformed
+
+ private void cmCheck_verboseActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cmCheck_verboseActionPerformed
+ {//GEN-HEADEREND:event_cmCheck_verboseActionPerformed
+// TODO add your handling code here:
+ }//GEN-LAST:event_cmCheck_verboseActionPerformed
+
+ private void cm_playerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_playerActionPerformed
+ {//GEN-HEADEREND:event_cm_playerActionPerformed
+ playerDialog.setVisible(true);
+ }//GEN-LAST:event_cm_playerActionPerformed
+
+ private void cm_aboutActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_aboutActionPerformed
+ {//GEN-HEADEREND:event_cm_aboutActionPerformed
+ VersionDialog dia = new VersionDialog(this, true, cmCheck_verbose.isSelected());
+ dia.setVisible(true);
+// JOptionPane.showMessageDialog(this, "Salamander SVG - Created by Mark McKay\nhttp://www.kitfox.com");
+ }//GEN-LAST:event_cm_aboutActionPerformed
+
+ private void cm_800x600ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cm_800x600ActionPerformed
+ setSize(800, 600);
+ }//GEN-LAST:event_cm_800x600ActionPerformed
+
+ private void cm_loadFileActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_loadFileActionPerformed
+ {//GEN-HEADEREND:event_cm_loadFileActionPerformed
+ boolean verbose = cmCheck_verbose.isSelected();
+
+ try
+ {
+ int retVal = fileChooser.showOpenDialog(this);
+ if (retVal == JFileChooser.APPROVE_OPTION)
+ {
+ File chosenFile = fileChooser.getSelectedFile();
+
+ URL url = chosenFile.toURI().toURL();
+
+ loadURL(url);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }//GEN-LAST:event_cm_loadFileActionPerformed
+
+ /** Exit the Application */
+ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
+ System.exit(0);
+ }//GEN-LAST:event_exitForm
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ new SVGPlayer().setVisible(true);
+ }
+
+ public void updateTime(double curTime, double timeStep, int playState)
+ {
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JCheckBoxMenuItem CheckBoxMenuItem_anonInputStream;
+ private javax.swing.JCheckBoxMenuItem cmCheck_verbose;
+ private javax.swing.JMenuItem cm_800x600;
+ private javax.swing.JMenuItem cm_about;
+ private javax.swing.JMenuItem cm_loadFile;
+ private javax.swing.JMenuItem cm_loadUrl;
+ private javax.swing.JMenuItem cm_player;
+ private javax.swing.JMenuBar jMenuBar1;
+ private javax.swing.JSeparator jSeparator2;
+ private javax.swing.JMenu menu_file;
+ private javax.swing.JMenu menu_help;
+ private javax.swing.JMenu menu_window;
+ private javax.swing.JScrollPane scrollPane_svgArea;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/SVGViewer.form b/src/main/java/com/kitfox/svg/app/SVGViewer.form
new file mode 100644
index 0000000..d6a5f7d
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/SVGViewer.form
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Menu class="javax.swing.JMenuBar" name="jMenuBar1">
+ <SubComponents>
+ <Menu class="javax.swing.JMenu" name="menu_file">
+ <Properties>
+ <Property name="mnemonic" type="int" value="102"/>
+ <Property name="text" type="java.lang.String" value="File"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_loadFile">
+ <Properties>
+ <Property name="mnemonic" type="int" value="108"/>
+ <Property name="text" type="java.lang.String" value="Load File..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_loadFileActionPerformed"/>
+ </Events>
+ </MenuItem>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_loadUrl">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Load URL..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_loadUrlActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="menu_window">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Window"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_800x600">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="800 x 600"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_800x600ActionPerformed"/>
+ </Events>
+ </MenuItem>
+ <MenuItem class="javax.swing.JCheckBoxMenuItem" name="CheckBoxMenuItem_anonInputStream">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Anonymous Input Stream"/>
+ </Properties>
+ </MenuItem>
+ <MenuItem class="javax.swing.JCheckBoxMenuItem" name="cmCheck_verbose">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Verbose"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmCheck_verboseActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="menu_help">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Help"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="cm_about">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="About..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cm_aboutActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ </SubComponents>
+ </Menu>
+ </NonVisualComponents>
+ <Properties>
+ <Property name="title" type="java.lang.String" value="SVG Viewer - Salamander Project"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitForm"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JScrollPane" name="scrollPane_svgArea">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="panel_svgArea">
+ <Events>
+ <EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="panel_svgAreaMousePressed"/>
+ <EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="panel_svgAreaMouseReleased"/>
+ </Events>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ </Container>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/SVGViewer.java b/src/main/java/com/kitfox/svg/app/SVGViewer.java
new file mode 100644
index 0000000..ea63b7f
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/SVGViewer.java
@@ -0,0 +1,421 @@
+/*
+ * SVGViewer.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on April 3, 2004, 5:28 PM
+ */
+
+package com.kitfox.svg.app;
+
+import java.net.*;
+import java.awt.*;
+import java.io.*;
+import java.util.regex.*;
+import javax.swing.*;
+
+//import javax.jnlp.*;
+
+import com.kitfox.svg.*;
+import java.security.AccessControlException;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class SVGViewer extends javax.swing.JFrame
+{
+ public static final long serialVersionUID = 1;
+
+ SVGDisplayPanel svgDisplayPanel = new SVGDisplayPanel();
+
+ /** FileChooser for running in trusted environments */
+ final JFileChooser fileChooser;
+ {
+// fileChooser = new JFileChooser(new File("."));
+ JFileChooser fc = null;
+ try
+ {
+ fc = new JFileChooser();
+ fc.setFileFilter(
+ new javax.swing.filechooser.FileFilter() {
+ final Matcher matchLevelFile = Pattern.compile(".*\\.svg").matcher("");
+
+ public boolean accept(File file)
+ {
+ if (file.isDirectory()) return true;
+
+ matchLevelFile.reset(file.getName());
+ return matchLevelFile.matches();
+ }
+
+ public String getDescription() { return "SVG file (*.svg)"; }
+ }
+ );
+ }
+ catch (AccessControlException ex)
+ {
+ //Do not create file chooser if webstart refuses permissions
+ }
+ fileChooser = fc;
+ }
+
+ /** Backup file service for opening files in WebStart situations */
+ /*
+ final FileOpenService fileOpenService;
+ {
+ try
+ {
+ fileOpenService = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
+ }
+ catch (UnavailableServiceException e)
+ {
+ fileOpenService = null;
+ }
+ }
+ */
+
+ /** Creates new form SVGViewer */
+ public SVGViewer() {
+ initComponents();
+
+ setSize(800, 600);
+
+ svgDisplayPanel.setBgColor(Color.white);
+
+ svgDisplayPanel.setPreferredSize(getSize());
+ panel_svgArea.add(svgDisplayPanel, BorderLayout.CENTER);
+// scrollPane_svgArea.setViewportView(svgDisplayPanel);
+ }
+
+ private void loadURL(URL url)
+ {
+ boolean verbose = cmCheck_verbose.isSelected();
+
+// SVGUniverse universe = new SVGUniverse();
+ SVGUniverse universe = SVGCache.getSVGUniverse();
+ SVGDiagram diagram = null;
+ URI uri;
+
+ if (!CheckBoxMenuItem_anonInputStream.isSelected())
+ {
+ //Load from a disk with a valid URL
+ uri = universe.loadSVG(url);
+
+ if (verbose) System.err.println("Loading document " + uri.toString());
+
+ diagram = universe.getDiagram(uri);
+ }
+ else
+ {
+ //Load from a stream with no particular valid URL
+ try
+ {
+ InputStream is = url.openStream();
+ uri = universe.loadSVG(is, "defaultName");
+
+ if (verbose) System.err.println("Loading document " + uri.toString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return;
+ }
+ }
+/*
+ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ObjectOutputStream os = new ObjectOutputStream(bs);
+os.writeObject(universe);
+os.close();
+
+ByteArrayInputStream bin = new ByteArrayInputStream(bs.toByteArray());
+ObjectInputStream is = new ObjectInputStream(bin);
+universe = (SVGUniverse)is.readObject();
+is.close();
+*/
+
+ diagram = universe.getDiagram(uri);
+
+ svgDisplayPanel.setDiagram(diagram);
+ repaint();
+ }
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ scrollPane_svgArea = new javax.swing.JScrollPane();
+ panel_svgArea = new javax.swing.JPanel();
+ jMenuBar1 = new javax.swing.JMenuBar();
+ menu_file = new javax.swing.JMenu();
+ cm_loadFile = new javax.swing.JMenuItem();
+ cm_loadUrl = new javax.swing.JMenuItem();
+ menu_window = new javax.swing.JMenu();
+ cm_800x600 = new javax.swing.JMenuItem();
+ CheckBoxMenuItem_anonInputStream = new javax.swing.JCheckBoxMenuItem();
+ cmCheck_verbose = new javax.swing.JCheckBoxMenuItem();
+ menu_help = new javax.swing.JMenu();
+ cm_about = new javax.swing.JMenuItem();
+
+ setTitle("SVG Viewer - Salamander Project");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing(java.awt.event.WindowEvent evt)
+ {
+ exitForm(evt);
+ }
+ });
+
+ panel_svgArea.setLayout(new java.awt.BorderLayout());
+
+ panel_svgArea.addMouseListener(new java.awt.event.MouseAdapter()
+ {
+ public void mousePressed(java.awt.event.MouseEvent evt)
+ {
+ panel_svgAreaMousePressed(evt);
+ }
+ public void mouseReleased(java.awt.event.MouseEvent evt)
+ {
+ panel_svgAreaMouseReleased(evt);
+ }
+ });
+
+ scrollPane_svgArea.setViewportView(panel_svgArea);
+
+ getContentPane().add(scrollPane_svgArea, java.awt.BorderLayout.CENTER);
+
+ menu_file.setMnemonic('f');
+ menu_file.setText("File");
+ cm_loadFile.setMnemonic('l');
+ cm_loadFile.setText("Load File...");
+ cm_loadFile.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_loadFileActionPerformed(evt);
+ }
+ });
+
+ menu_file.add(cm_loadFile);
+
+ cm_loadUrl.setText("Load URL...");
+ cm_loadUrl.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_loadUrlActionPerformed(evt);
+ }
+ });
+
+ menu_file.add(cm_loadUrl);
+
+ jMenuBar1.add(menu_file);
+
+ menu_window.setText("Window");
+ cm_800x600.setText("800 x 600");
+ cm_800x600.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_800x600ActionPerformed(evt);
+ }
+ });
+
+ menu_window.add(cm_800x600);
+
+ CheckBoxMenuItem_anonInputStream.setText("Anonymous Input Stream");
+ menu_window.add(CheckBoxMenuItem_anonInputStream);
+
+ cmCheck_verbose.setText("Verbose");
+ cmCheck_verbose.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cmCheck_verboseActionPerformed(evt);
+ }
+ });
+
+ menu_window.add(cmCheck_verbose);
+
+ jMenuBar1.add(menu_window);
+
+ menu_help.setText("Help");
+ cm_about.setText("About...");
+ cm_about.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ cm_aboutActionPerformed(evt);
+ }
+ });
+
+ menu_help.add(cm_about);
+
+ jMenuBar1.add(menu_help);
+
+ setJMenuBar(jMenuBar1);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void cm_loadUrlActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_loadUrlActionPerformed
+ {//GEN-HEADEREND:event_cm_loadUrlActionPerformed
+ String urlStrn = JOptionPane.showInputDialog(this, "Enter URL of SVG file");
+ if (urlStrn == null) return;
+
+ try
+ {
+ URL url = new URL(urlStrn);
+ loadURL(url);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }//GEN-LAST:event_cm_loadUrlActionPerformed
+
+ private void panel_svgAreaMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_panel_svgAreaMouseReleased
+ {//GEN-HEADEREND:event_panel_svgAreaMouseReleased
+ SVGDiagram diagram = svgDisplayPanel.getDiagram();
+ Vector pickedElements;
+ try
+ {
+ pickedElements = diagram.pick(new Point(evt.getX(), evt.getY()), null);
+ }
+ catch (SVGException ex)
+ {
+ ex.printStackTrace();
+ return;
+ }
+
+ System.out.println("Pick results:");
+ for (Iterator it = pickedElements.iterator(); it.hasNext();)
+ {
+ Vector path = (Vector)it.next();
+
+ System.out.print(" Path: ");
+
+ for (Iterator it2 = path.iterator(); it2.hasNext();)
+ {
+ SVGElement ele = (SVGElement)it2.next();
+
+ System.out.print("" + ele.getId() + "(" + ele.getClass().getName() + ") ");
+ }
+ System.out.println();
+ }
+ }//GEN-LAST:event_panel_svgAreaMouseReleased
+
+ private void panel_svgAreaMousePressed(java.awt.event.MouseEvent evt)//GEN-FIRST:event_panel_svgAreaMousePressed
+ {//GEN-HEADEREND:event_panel_svgAreaMousePressed
+
+ }//GEN-LAST:event_panel_svgAreaMousePressed
+
+ private void cmCheck_verboseActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cmCheck_verboseActionPerformed
+ {//GEN-HEADEREND:event_cmCheck_verboseActionPerformed
+ SVGCache.getSVGUniverse().setVerbose(cmCheck_verbose.isSelected());
+ }//GEN-LAST:event_cmCheck_verboseActionPerformed
+
+ private void cm_aboutActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_aboutActionPerformed
+ {//GEN-HEADEREND:event_cm_aboutActionPerformed
+ //JOptionPane.showMessageDialog(this, "Salamander SVG - Created by Mark McKay\nhttp://www.kitfox.com");
+ VersionDialog dlg = new VersionDialog(this, true, cmCheck_verbose.isSelected());
+ dlg.setVisible(true);
+ }//GEN-LAST:event_cm_aboutActionPerformed
+
+ private void cm_800x600ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cm_800x600ActionPerformed
+ setSize(800, 600);
+ }//GEN-LAST:event_cm_800x600ActionPerformed
+
+ private void cm_loadFileActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cm_loadFileActionPerformed
+ {//GEN-HEADEREND:event_cm_loadFileActionPerformed
+ try
+ {
+ int retVal = fileChooser.showOpenDialog(this);
+ if (retVal == JFileChooser.APPROVE_OPTION)
+ {
+ File chosenFile = fileChooser.getSelectedFile();
+
+ URL url = chosenFile.toURI().toURL();
+
+ loadURL(url);
+ }
+ }
+ /*
+ catch (IOException ioe)
+ {
+ try
+ {
+ //We may be in a WebStart app. Try again with a FileOpenService
+ FileContents fc = fileOpenService.openFileDialog(null, new String[]{"svg"});
+ InputStream is = fc.getInputStream();
+ String name = fc.getName();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ */
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }//GEN-LAST:event_cm_loadFileActionPerformed
+
+ /** Exit the Application */
+ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
+// setVisible(false);
+// dispose();
+ System.exit(0);
+ }//GEN-LAST:event_exitForm
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ new SVGViewer().setVisible(true);
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JCheckBoxMenuItem CheckBoxMenuItem_anonInputStream;
+ private javax.swing.JCheckBoxMenuItem cmCheck_verbose;
+ private javax.swing.JMenuItem cm_800x600;
+ private javax.swing.JMenuItem cm_about;
+ private javax.swing.JMenuItem cm_loadFile;
+ private javax.swing.JMenuItem cm_loadUrl;
+ private javax.swing.JMenuBar jMenuBar1;
+ private javax.swing.JMenu menu_file;
+ private javax.swing.JMenu menu_help;
+ private javax.swing.JMenu menu_window;
+ private javax.swing.JPanel panel_svgArea;
+ private javax.swing.JScrollPane scrollPane_svgArea;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/VersionDialog.form b/src/main/java/com/kitfox/svg/app/VersionDialog.form
new file mode 100644
index 0000000..a20b953
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/VersionDialog.form
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
+ <Properties>
+ <Property name="defaultCloseOperation" type="int" value="2"/>
+ <Property name="title" type="java.lang.String" value="About SVG Salamander"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="jPanel1">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTextPane" name="textpane_text">
+ <Properties>
+ <Property name="editable" type="boolean" value="false"/>
+ <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+ <Dimension value="[400, 300]"/>
+ </Property>
+ </Properties>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="jPanel2">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="South"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JButton" name="bn_close">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Close"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bn_closeActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/VersionDialog.java b/src/main/java/com/kitfox/svg/app/VersionDialog.java
new file mode 100644
index 0000000..4c416d1
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/VersionDialog.java
@@ -0,0 +1,151 @@
+/*
+ * VersionDialog.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 13, 2005, 7:23 AM
+ */
+
+package com.kitfox.svg.app;
+
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import javax.swing.event.*;
+import javax.swing.*;
+import javax.swing.text.html.*;
+
+
+/**
+ *
+ * @author kitfox
+ */
+public class VersionDialog extends javax.swing.JDialog
+{
+ public static final long serialVersionUID = 1;
+
+ final boolean verbose;
+
+ /** Creates new form VersionDialog */
+ public VersionDialog(java.awt.Frame parent, boolean modal, boolean verbose)
+ {
+ super(parent, modal);
+ initComponents();
+
+ this.verbose = verbose;
+
+ textpane_text.setContentType("text/html");
+
+ StringBuffer sb = new StringBuffer();
+ try
+ {
+ URL url = getClass().getResource("/res/help/about/about.html");
+ if (verbose)
+ {
+ System.err.println("" + getClass() + " trying to load about html " + url);
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+ while (true)
+ {
+ String line = reader.readLine();
+ if (line == null) break;
+ sb.append(line);
+ }
+
+ textpane_text.setText(sb.toString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ jPanel1 = new javax.swing.JPanel();
+ textpane_text = new javax.swing.JTextPane();
+ jPanel2 = new javax.swing.JPanel();
+ bn_close = new javax.swing.JButton();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("About SVG Salamander");
+ jPanel1.setLayout(new java.awt.BorderLayout());
+
+ textpane_text.setEditable(false);
+ textpane_text.setPreferredSize(new java.awt.Dimension(400, 300));
+ jPanel1.add(textpane_text, java.awt.BorderLayout.CENTER);
+
+ getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
+
+ bn_close.setText("Close");
+ bn_close.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ bn_closeActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(bn_close);
+
+ getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
+
+ pack();
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+ private void bn_closeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_closeActionPerformed
+ {//GEN-HEADEREND:event_bn_closeActionPerformed
+ setVisible(false);
+ dispose();
+ }//GEN-LAST:event_bn_closeActionPerformed
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ new VersionDialog(new javax.swing.JFrame(), true, true).setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton bn_close;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JTextPane textpane_text;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/ant/SVGToImageAntTask.java b/src/main/java/com/kitfox/svg/app/ant/SVGToImageAntTask.java
new file mode 100644
index 0000000..f4cd85a
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/ant/SVGToImageAntTask.java
@@ -0,0 +1,251 @@
+/*
+ * IndexLoadObjectsAntTask.java
+ *
+ * Created on January 22, 2005, 10:30 AM
+ */
+
+package com.kitfox.svg.app.ant;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.util.*;
+import java.util.regex.*;
+import java.io.*;
+import javax.imageio.*;
+
+//import com.kitfox.util.*;
+//import com.kitfox.util.indexedObject.*;
+
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.types.*;
+
+import com.kitfox.svg.app.beans.*;
+import com.kitfox.svg.*;
+import com.kitfox.svg.xml.ColorTable;
+
+/**
+ * <p>Translates a group of SVG files into images.</p>
+ *
+ * <p>Parameters:</p>
+ * <p><ul>
+ * <li/>destDir - If present, specifices a directory to write SVG files to. Otherwise
+ * writes images to directory SVG file was found in
+ * verbose - If true, prints processing information to the console
+ * <li/>format - File format for output images. The java core javax.imageio.ImageIO
+ * class is used for creating images, so format strings will depend on what
+ * files your system is configured to handle. By default, "gif", "jpg" and "png"
+ * files are guaranteed to be present. If omitted, "png" is used by default.
+ * <li/>backgroundColor - Optional background color. Color can be specified as a standard
+ * HTML color. That is, as the name of a standard color such as "blue" or
+ * "limegreen", using the # notaion as in #ff00ff for magenta, or in rgb format
+ * listing the components as in rgb(255, 192, 192) for pink. If omitted,
+ * background is transparent.
+ * <li/>antiAlias - If set, shapes are drawn using antialiasing. Defaults to true.
+ * <li/>interpolation - String describing image interpolation alrogithm. Can
+ * be one of "nearest neighbor", "bilinear" or "bicubic". Defaults to "bicubic".
+ * <li/>width - If greater than 0, determines the width of the written image. Otherwise,
+ * the width is obtained from the SVG document. Defaults to -1;
+ * <li/>height - If greater than 0, determines the height of the written image. Otherwise,
+ * the height is obtained from the SVG document. Defaults to -1.
+ * <li/>sizeToFit - If true and the width and height of the output image differ
+ * from that of the SVG image, the valid area of the SVG image will be resized
+ * to fit the specified size.
+ * <li/>verbose - IF true, prints out diagnostic infromation about processing.
+ * Defaults to false.
+ * </ul></p>
+ *
+ * Example:
+ * &lt;SVGToImage destDir="${index.java}" format="jpg" verbose="true"&gt;
+ * &lt;fileset dir="${dir1}"&gt;
+ * &lt;include name="*.svg"/&gt;
+ * &lt;/fileset&gt;
+ * &lt;fileset dir="${dir2}"&gt;
+ * &lt;include name="*.svg"/&gt;
+ * &lt;/fileset&gt;
+ * &lt;/SVGToImage&gt;
+ *
+ *
+ *
+ * @author kitfox
+ */
+public class SVGToImageAntTask extends Task
+{
+ private Vector filesets = new Vector();
+ boolean verbose = false;
+ File destDir;
+ private String format = "png";
+ Color backgroundColor = null;
+ int width = -1;
+ int height = -1;
+ boolean antiAlias = true;
+ String interpolation = "bicubic";
+ boolean clipToViewBox = false;
+ boolean sizeToFit = true;
+
+ /** Creates a new instance of IndexLoadObjectsAntTask */
+ public SVGToImageAntTask()
+ {
+ }
+
+
+ public String getFormat()
+ {
+ return format;
+ }
+
+ public void setFormat(String format)
+ {
+ this.format = format;
+ }
+
+ public void setBackgroundColor(String bgColor)
+ {
+ this.backgroundColor = ColorTable.parseColor(bgColor);
+ }
+
+ public void setHeight(int height)
+ {
+ this.height = height;
+ }
+
+ public void setWidth(int width)
+ {
+ this.width = width;
+ }
+
+ public void setAntiAlias(boolean antiAlias)
+ {
+ this.antiAlias = antiAlias;
+ }
+
+ public void setInterpolation(String interpolation)
+ {
+ this.interpolation = interpolation;
+ }
+
+ public void setSizeToFit(boolean sizeToFit)
+ {
+ this.sizeToFit = sizeToFit;
+ }
+
+ public void setClipToViewBox(boolean clipToViewBox)
+ {
+ this.clipToViewBox = clipToViewBox;
+ }
+
+ public void setVerbose(boolean verbose)
+ {
+ this.verbose = verbose;
+ }
+
+ public void setDestDir(File destDir)
+ {
+ this.destDir = destDir;
+ }
+
+ /**
+ * Adds a set of files.
+ */
+ public void addFileset(FileSet set)
+ {
+ filesets.add(set);
+ }
+
+
+
+ public void execute()
+ {
+ if (verbose) log("Building SVG images");
+
+ for (Iterator it = filesets.iterator(); it.hasNext();)
+ {
+ FileSet fs = (FileSet)it.next();
+ FileScanner scanner = fs.getDirectoryScanner(getProject());
+ String[] files = scanner.getIncludedFiles();
+
+ try
+ {
+ File basedir = scanner.getBasedir();
+
+ if (verbose) log("Scaning " + basedir);
+
+ for (int i = 0; i < files.length; i++)
+ {
+//System.out.println("File " + files[i]);
+//System.out.println("BaseDir " + basedir);
+ translate(basedir, files[i]);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new BuildException(e);
+ }
+ }
+ }
+
+ private void translate(File baseDir, String shortName) throws BuildException
+ {
+ File source = new File(baseDir, shortName);
+
+ if (verbose) log("Reading file: " + source);
+
+ Matcher matchName = Pattern.compile("(.*)\\.svg", Pattern.CASE_INSENSITIVE).matcher(shortName);
+ if (matchName.matches())
+ {
+ shortName = matchName.group(1);
+ }
+ shortName += "." + format;
+
+ SVGIcon icon = new SVGIcon();
+ icon.setSvgURI(source.toURI());
+ icon.setAntiAlias(antiAlias);
+ if (interpolation.equals("nearest neighbor"))
+ {
+ icon.setInterpolation(SVGIcon.INTERP_NEAREST_NEIGHBOR);
+ }
+ else if (interpolation.equals("bilinear"))
+ {
+ icon.setInterpolation(SVGIcon.INTERP_BILINEAR);
+ }
+ else if (interpolation.equals("bicubic"))
+ {
+ icon.setInterpolation(SVGIcon.INTERP_BICUBIC);
+ }
+
+ int iconWidth = width > 0 ? width : icon.getIconWidth();
+ int iconHeight = height > 0 ? height : icon.getIconHeight();
+ icon.setClipToViewbox(clipToViewBox);
+ icon.setPreferredSize(new Dimension(iconWidth, iconHeight));
+ icon.setScaleToFit(sizeToFit);
+ BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = image.createGraphics();
+
+ if (backgroundColor != null)
+ {
+ g.setColor(backgroundColor);
+ g.fillRect(0, 0, iconWidth, iconHeight);
+ }
+
+ g.setClip(0, 0, iconWidth, iconHeight);
+// g.fillRect(10, 10, 100, 100);
+ icon.paintIcon(null, g, 0, 0);
+ g.dispose();
+
+ File outFile = destDir == null ? new File(baseDir, shortName) : new File(destDir, shortName);
+ if (verbose) log("Writing file: " + outFile);
+
+ try
+ {
+ ImageIO.write(image, format, outFile);
+ }
+ catch (IOException e)
+ {
+ log("Error writing image: " + e.getMessage());
+ throw new BuildException(e);
+ }
+
+
+ SVGCache.getSVGUniverse().clear();
+ }
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.form b/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.form
new file mode 100644
index 0000000..81fa33a
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.form
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+ <Events>
+ <EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="formComponentResized"/>
+ <EventHandler event="componentShown" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="formComponentShown"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
+ <Property name="useNullLayout" type="boolean" value="true"/>
+ </Layout>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="jPanel1">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
+ <AbsoluteConstraints x="80" y="90" width="280" height="160"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.java b/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.java
new file mode 100644
index 0000000..be947db
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/beans/ProportionalLayoutPanel.java
@@ -0,0 +1,91 @@
+/*
+ * ProportionalLayoutPanel.java
+ *
+ * Created on May 7, 2005, 4:15 AM
+ */
+
+package com.kitfox.svg.app.beans;
+
+import java.awt.*;
+import java.util.*;
+import javax.swing.*;
+
+/**
+ * Panel based on the null layout. Allows editing with absolute layout. When
+ * instanced, records layout dimensions of all subcomponents. Then, if the
+ * panel is ever resized, scales all children to fit new size.
+ *
+ * @author kitfox
+ */
+public class ProportionalLayoutPanel extends javax.swing.JPanel
+{
+ public static final long serialVersionUID = 1;
+
+ //Margins to leave on sides of panel, expressed in fractions [0 1]
+ float topMargin;
+ float bottomMargin;
+ float leftMargin;
+ float rightMargin;
+
+ /** Creates new form ProportionalLayoutPanel */
+ public ProportionalLayoutPanel()
+ {
+ initComponents();
+ }
+
+ public void addNotify()
+ {
+ super.addNotify();
+
+ Rectangle rect = this.getBounds();
+ JOptionPane.showMessageDialog(this, "" + rect);
+ }
+
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ jPanel1 = new javax.swing.JPanel();
+
+ setLayout(null);
+
+ addComponentListener(new java.awt.event.ComponentAdapter()
+ {
+ public void componentResized(java.awt.event.ComponentEvent evt)
+ {
+ formComponentResized(evt);
+ }
+ public void componentShown(java.awt.event.ComponentEvent evt)
+ {
+ formComponentShown(evt);
+ }
+ });
+
+ add(jPanel1);
+ jPanel1.setBounds(80, 90, 280, 160);
+
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+ private void formComponentShown(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentShown
+ {//GEN-HEADEREND:event_formComponentShown
+ JOptionPane.showMessageDialog(this, "" + getWidth() + ", " + getHeight());
+
+ }//GEN-LAST:event_formComponentShown
+
+ private void formComponentResized(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentResized
+ {//GEN-HEADEREND:event_formComponentResized
+// TODO add your handling code here:
+ }//GEN-LAST:event_formComponentResized
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JPanel jPanel1;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java b/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java
new file mode 100644
index 0000000..acb5bb5
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java
@@ -0,0 +1,385 @@
+/*
+ * SVGIcon.java
+ *
+ * Created on April 21, 2005, 10:45 AM
+ */
+
+package com.kitfox.svg.app.beans;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.net.*;
+import java.beans.*;
+
+import com.kitfox.svg.*;
+
+/**
+ *
+ * @author kitfox
+ */
+public class SVGIcon implements Icon
+{
+ public static final long serialVersionUID = 1;
+
+ private PropertyChangeSupport changes = new PropertyChangeSupport(this);
+
+ SVGUniverse svgUniverse = SVGCache.getSVGUniverse();
+ public static final int INTERP_NEAREST_NEIGHBOR = 0;
+ public static final int INTERP_BILINEAR = 1;
+ public static final int INTERP_BICUBIC = 2;
+
+ private boolean antiAlias;
+ private int interpolation = INTERP_NEAREST_NEIGHBOR;
+ private boolean clipToViewbox;
+
+// private String svgPath;
+ URI svgURI;
+
+ private boolean scaleToFit;
+ AffineTransform scaleXform = new AffineTransform();
+
+// Dimension preferredSize = new Dimension(100, 100);
+ Dimension preferredSize;
+
+ /** Creates a new instance of SVGIcon */
+ public SVGIcon()
+ {
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener p)
+ {
+ changes.addPropertyChangeListener(p);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener p)
+ {
+ changes.removePropertyChangeListener(p);
+ }
+
+ /**
+ * @return height of this icon
+ */
+ public int getIconHeight()
+ {
+ if (scaleToFit && preferredSize != null)
+ {
+ return preferredSize.height;
+ }
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return 0;
+ return (int)diagram.getHeight();
+ }
+
+ /**
+ * @return width of this icon
+ */
+ public int getIconWidth()
+ {
+ if (scaleToFit && preferredSize != null)
+ {
+ return preferredSize.width;
+ }
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return 0;
+ return (int)diagram.getWidth();
+ }
+
+ /**
+ * Draws the icon to the specified component.
+ * @param comp - Component to draw icon to. This is ignored by SVGIcon, and can be set to null; only gg is used for drawing the icon
+ * @param gg - Graphics context to render SVG content to
+ * @param x - X coordinate to draw icon
+ * @param y - Y coordinate to draw icon
+ */
+ public void paintIcon(Component comp, Graphics gg, int x, int y)
+ {
+ Graphics2D g = (Graphics2D)gg;
+
+ Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
+
+ Object oldInterpolationHint = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
+ switch (interpolation)
+ {
+ case INTERP_NEAREST_NEIGHBOR:
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+ break;
+ case INTERP_BILINEAR:
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ break;
+ case INTERP_BICUBIC:
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ break;
+ }
+
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return;
+
+ g.translate(x, y);
+ diagram.setIgnoringClipHeuristic(!clipToViewbox);
+ if (clipToViewbox)
+ {
+ g.setClip(new Rectangle2D.Float(0, 0, diagram.getWidth(), diagram.getHeight()));
+ }
+
+
+
+ if (!scaleToFit)
+ {
+ try
+ {
+ diagram.render(g);
+ g.translate(-x, -y);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ return;
+ }
+
+ final int width = getIconWidth();
+ final int height = getIconHeight();
+// int width = getWidth();
+// int height = getHeight();
+
+ if (width == 0 || height == 0)
+ {
+ return;
+ }
+
+// if (width == 0 || height == 0)
+// {
+// //Chances are we're rendering offscreen
+// Dimension dim = getSize();
+// width = dim.width;
+// height = dim.height;
+// return;
+// }
+
+// g.setClip(0, 0, width, height);
+
+
+ final Rectangle2D.Double rect = new Rectangle2D.Double();
+ diagram.getViewRect(rect);
+
+ scaleXform.setToScale(width / rect.width, height / rect.height);
+
+ AffineTransform oldXform = g.getTransform();
+ g.transform(scaleXform);
+
+ try
+ {
+ diagram.render(g);
+ }
+ catch (SVGException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ g.setTransform(oldXform);
+
+
+ g.translate(-x, -y);
+
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
+ if (oldInterpolationHint != null) g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint);
+ }
+
+ /**
+ * @return the universe this icon draws it's SVGDiagrams from
+ */
+ public SVGUniverse getSvgUniverse()
+ {
+ return svgUniverse;
+ }
+
+ public void setSvgUniverse(SVGUniverse svgUniverse)
+ {
+ SVGUniverse old = this.svgUniverse;
+ this.svgUniverse = svgUniverse;
+ changes.firePropertyChange("svgUniverse", old, svgUniverse);
+ }
+
+ /**
+ * @return the uni of the document being displayed by this icon
+ */
+ public URI getSvgURI()
+ {
+ return svgURI;
+ }
+
+ /**
+ * Loads an SVG document from a URI.
+ * @param svgURI - URI to load document from
+ */
+ public void setSvgURI(URI svgURI)
+ {
+ URI old = this.svgURI;
+ this.svgURI = svgURI;
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram != null)
+ {
+ Dimension size = getPreferredSize();
+ if (size == null)
+ {
+ size = new Dimension((int)diagram.getRoot().getDeviceWidth(), (int)diagram.getRoot().getDeviceHeight());
+ }
+ diagram.setDeviceViewport(new Rectangle(0, 0, size.width, size.height));
+ }
+
+ changes.firePropertyChange("svgURI", old, svgURI);
+ }
+
+ /**
+ * Loads an SVG document from the classpath. This function is equivilant to
+ * setSvgURI(new URI(getClass().getResource(resourcePath).toString());
+ * @param resourcePath - resource to load
+ */
+ public void setSvgResourcePath(String resourcePath)
+ {
+ URI old = this.svgURI;
+
+ try
+ {
+ svgURI = new URI(getClass().getResource(resourcePath).toString());
+ changes.firePropertyChange("svgURI", old, svgURI);
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram != null)
+ {
+ diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height));
+ }
+
+ }
+ catch (Exception e)
+ {
+ svgURI = old;
+ }
+ }
+
+ /**
+ * If this SVG document has a viewbox, if scaleToFit is set, will scale the viewbox to match the
+ * preferred size of this icon
+ */
+ public boolean isScaleToFit()
+ {
+ return scaleToFit;
+ }
+
+ public void setScaleToFit(boolean scaleToFit)
+ {
+ boolean old = this.scaleToFit;
+ this.scaleToFit = scaleToFit;
+ changes.firePropertyChange("scaleToFit", old, scaleToFit);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ if (preferredSize == null)
+ {
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram != null)
+ {
+ //preferredSize = new Dimension((int)diagram.getWidth(), (int)diagram.getHeight());
+ setPreferredSize(new Dimension((int)diagram.getWidth(), (int)diagram.getHeight()));
+ }
+ }
+
+ return new Dimension(preferredSize);
+ }
+
+ public void setPreferredSize(Dimension preferredSize)
+ {
+ Dimension old = this.preferredSize;
+ this.preferredSize = preferredSize;
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram != null)
+ {
+ diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height));
+ }
+
+ changes.firePropertyChange("preferredSize", old, preferredSize);
+ }
+
+
+ /**
+ * @return true if antiAliasing is turned on.
+ * @deprecated
+ */
+ public boolean getUseAntiAlias()
+ {
+ return getAntiAlias();
+ }
+
+ /**
+ * @param antiAlias true to use antiAliasing.
+ * @deprecated
+ */
+ public void setUseAntiAlias(boolean antiAlias)
+ {
+ setAntiAlias(antiAlias);
+ }
+
+ /**
+ * @return true if antiAliasing is turned on.
+ */
+ public boolean getAntiAlias()
+ {
+ return antiAlias;
+ }
+
+ /**
+ * @param antiAlias true to use antiAliasing.
+ */
+ public void setAntiAlias(boolean antiAlias)
+ {
+ boolean old = this.antiAlias;
+ this.antiAlias = antiAlias;
+ changes.firePropertyChange("antiAlias", old, antiAlias);
+ }
+
+ /**
+ * @return interpolation used in rescaling images
+ */
+ public int getInterpolation()
+ {
+ return interpolation;
+ }
+
+ /**
+ * @param interpolation Interpolation value used in rescaling images.
+ * Should be one of
+ * INTERP_NEAREST_NEIGHBOR - Fastest, one pixel resampling, poor quality
+ * INTERP_BILINEAR - four pixel resampling
+ * INTERP_BICUBIC - Slowest, nine pixel resampling, best quality
+ */
+ public void setInterpolation(int interpolation)
+ {
+ int old = this.interpolation;
+ this.interpolation = interpolation;
+ changes.firePropertyChange("interpolation", old, interpolation);
+ }
+
+ /**
+ * clipToViewbox will set a clip box equivilant to the SVG's viewbox before
+ * rendering.
+ */
+ public boolean isClipToViewbox()
+ {
+ return clipToViewbox;
+ }
+
+ public void setClipToViewbox(boolean clipToViewbox)
+ {
+ this.clipToViewbox = clipToViewbox;
+ }
+
+}
diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form
new file mode 100644
index 0000000..b404a39
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+</Form>
diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java
new file mode 100644
index 0000000..396bd9b
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java
@@ -0,0 +1,243 @@
+/*
+ * SVGIcon.java
+ *
+ * Created on April 21, 2005, 10:43 AM
+ */
+
+package com.kitfox.svg.app.beans;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.net.*;
+import java.beans.*;
+
+import com.kitfox.svg.*;
+
+/**
+ *
+ * @author kitfox
+ */
+public class SVGPanel extends JPanel
+{
+ public static final long serialVersionUID = 1;
+
+
+ SVGUniverse svgUniverse = SVGCache.getSVGUniverse();
+
+ private boolean antiAlias;
+
+// private String svgPath;
+ URI svgURI;
+
+ private boolean scaleToFit;
+ AffineTransform scaleXform = new AffineTransform();
+
+ /** Creates new form SVGIcon */
+ public SVGPanel()
+ {
+ initComponents();
+ }
+
+ public int getSVGHeight()
+ {
+ if (scaleToFit) return getPreferredSize().height;
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return 0;
+ return (int)diagram.getHeight();
+ }
+
+ public int getSVGWidth()
+ {
+ if (scaleToFit) return getPreferredSize().width;
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return 0;
+ return (int)diagram.getWidth();
+ }
+
+// Draw the icon at the specified location.
+ public void paintComponent(Graphics gg)
+ {
+ super.paintComponent(gg);
+
+ Graphics2D g = (Graphics2D)gg;
+
+ Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
+
+
+ SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+ if (diagram == null) return;
+
+ if (!scaleToFit)
+ {
+ try
+ {
+ diagram.render(g);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
+ }
+ catch (SVGException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return;
+ }
+
+ Dimension dim = getSize();
+ final int width = dim.width;
+ final int height = dim.height;
+// int width = getWidth();
+// int height = getHeight();
+
+// if (width == 0 || height == 0)
+// {
+// //Chances are we're rendering offscreen
+// Dimension dim = getSize();
+// width = dim.width;
+// height = dim.height;
+// return;
+// }
+
+// g.setClip(0, 0, dim.width, dim.height);
+
+
+ final Rectangle2D.Double rect = new Rectangle2D.Double();
+ diagram.getViewRect(rect);
+
+ scaleXform.setToScale(width / rect.width, height / rect.height);
+
+ AffineTransform oldXform = g.getTransform();
+ g.transform(scaleXform);
+
+ try
+ {
+ diagram.render(g);
+ }
+ catch (SVGException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ g.setTransform(oldXform);
+
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
+ }
+
+ public SVGUniverse getSvgUniverse()
+ {
+ return svgUniverse;
+ }
+
+ public void setSvgUniverse(SVGUniverse svgUniverse)
+ {
+ SVGUniverse old = this.svgUniverse;
+ this.svgUniverse = svgUniverse;
+ firePropertyChange("svgUniverse", old, svgUniverse);
+ }
+
+ public URI getSvgURI()
+ {
+ return svgURI;
+ }
+
+ public void setSvgURI(URI svgURI)
+ {
+ URI old = this.svgURI;
+ this.svgURI = svgURI;
+ firePropertyChange("svgURI", old, svgURI);
+ }
+
+ /**
+ * Most resources your component will want to access will be resources on your classpath.
+ * This method will interpret the passed string as a path in the classpath and use
+ * Class.getResource() to determine the URI of the SVG.
+ */
+ public void setSvgResourcePath(String resourcePath) throws SVGException
+ {
+ URI old = this.svgURI;
+
+ try
+ {
+ svgURI = new URI(getClass().getResource(resourcePath).toString());
+//System.err.println("SVGPanel: new URI " + svgURI + " from path " + resourcePath);
+
+ firePropertyChange("svgURI", old, svgURI);
+
+ repaint();
+ }
+ catch (Exception e)
+ {
+ throw new SVGException("Could not resolve path " + resourcePath, e);
+// svgURI = old;
+ }
+ }
+
+ public boolean isScaleToFit()
+ {
+ return scaleToFit;
+ }
+
+ public void setScaleToFit(boolean scaleToFit)
+ {
+ boolean old = this.scaleToFit;
+ this.scaleToFit = scaleToFit;
+ firePropertyChange("scaleToFit", old, scaleToFit);
+ }
+
+ /**
+ * @return true if antiAliasing is turned on.
+ * @deprecated
+ */
+ public boolean getUseAntiAlias()
+ {
+ return getAntiAlias();
+ }
+
+ /**
+ * @param antiAlias true to use antiAliasing.
+ * @deprecated
+ */
+ public void setUseAntiAlias(boolean antiAlias)
+ {
+ setAntiAlias(antiAlias);
+ }
+
+ /**
+ * @return true if antiAliasing is turned on.
+ */
+ public boolean getAntiAlias()
+ {
+ return antiAlias;
+ }
+
+ /**
+ * @param antiAlias true to use antiAliasing.
+ */
+ public void setAntiAlias(boolean antiAlias)
+ {
+ boolean old = this.antiAlias;
+ this.antiAlias = antiAlias;
+ firePropertyChange("antiAlias", old, antiAlias);
+ }
+
+ /** 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 ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+
+ setLayout(new java.awt.BorderLayout());
+
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+
+}