You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2015/02/04 23:10:08 UTC

svn commit: r1657421 - in /pivot/branches/2.0.x/tests: .classpath src/org/apache/pivot/tests/issues/pivot964/ src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java

Author: smartini
Date: Wed Feb  4 22:10:07 2015
New Revision: 1657421

URL: http://svn.apache.org/r1657421
Log:
PIVOT-964, add test cases

Added:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java
Modified:
    pivot/branches/2.0.x/tests/.classpath

Modified: pivot/branches/2.0.x/tests/.classpath
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/.classpath?rev=1657421&r1=1657420&r2=1657421&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/.classpath (original)
+++ pivot/branches/2.0.x/tests/.classpath Wed Feb  4 22:10:07 2015
@@ -8,5 +8,6 @@
 	<classpathentry combineaccessrules="false" kind="src" path="/wtk"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/wtk-terra"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+	<classpathentry kind="lib" path="/wtk/lib/svgSalamander-tiny.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java?rev=1657421&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Pivot.java Wed Feb  4 22:10:07 2015
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests.issues.pivot964;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.ImageView;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.media.Drawing;
+import org.apache.pivot.wtk.media.SVGDiagramSerializer;
+
+import com.kitfox.svg.SVGDiagram;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGElementException;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.animation.AnimationElement;
+
+/**
+ * Test application with Pivot components
+ */
+public class Pivot964Pivot extends Application.Adapter {
+
+    // Display stuff
+    protected SVGDiagram diagram;
+    protected SVGElement root;
+    protected Window window;
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(Pivot964Pivot.class, args);
+    }
+
+    @Override
+    public void startup(Display display, Map<String, String> properties) {
+        display.getHostWindow().setSize(1000, 600);  // force dimensions for host frame
+
+        window = new Window();
+
+        prepareSVG();
+
+        final ImageView image = new ImageView(new Drawing(diagram));
+
+        BoxPane bp = new BoxPane();
+
+        PushButton pb1 = new PushButton("Visible");
+        PushButton pb2 = new PushButton("Invisible (bug)");
+
+        bp.add(image);
+        bp.add(pb1);
+        bp.add(pb2);
+
+        pb1.getButtonPressListeners().add(new ButtonPressListener() {
+
+            @Override
+            public void buttonPressed(Button arg0) {
+                try {
+                    root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
+                    root.updateTime(0f);
+                    image.repaint();
+                } catch (SVGElementException e) {
+                    e.printStackTrace();
+                } catch (SVGException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        });
+
+        pb2.getButtonPressListeners().add(new ButtonPressListener() {
+
+            @Override
+            public void buttonPressed(Button arg0) {
+                try {
+                    root.setAttribute("viewBox", AnimationElement.AT_XML, "800 0 2368 1652");
+                    root.updateTime(0f);
+                    image.repaint();
+                } catch (SVGElementException e) {
+                    e.printStackTrace();
+                } catch (SVGException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        });
+
+        window.setContent(bp);
+        window.setMaximized(true);
+        window.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean optional) {
+        if (window != null) {
+            window.close();
+        }
+
+        return false;
+    }
+
+    protected void prepareSVG() {
+        SVGDiagramSerializer s = new SVGDiagramSerializer();
+
+        try {
+            diagram = s.readObject(new ByteArrayInputStream(makeDynamicSVG().getBytes()));
+            root = diagram.getRoot();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private String makeDynamicSVG() {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+
+        pw.println(
+            "<svg width=\"800\" height=\"600\" style=\"fill:none;stroke-width:2\" viewBox=\"0 0 2368 1652\">");
+        pw.println(
+            "<rect x=\"0\" y=\"0\" width=\"2000\" height=\"1000\" style=\"stroke:blue;fill:blue\"/>");
+        pw.println("</svg>");
+
+        pw.close();
+        return sw.toString();
+    }
+
+}

Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java?rev=1657421&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot964/Pivot964Swing.java Wed Feb  4 22:10:07 2015
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests.issues.pivot964;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.URI;
+
+import javax.swing.JPanel;
+
+import com.kitfox.svg.SVGCache;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGElementException;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.animation.AnimationElement;
+import com.kitfox.svg.app.beans.SVGIcon;
+
+/**
+ * Test using a Swing JFrame
+ * In this case all is good.
+ */
+public class Pivot964Swing extends javax.swing.JFrame {
+    public static final long serialVersionUID = 0;
+
+    TestPanel panel = new TestPanel();
+
+    /** Creates new form SVGIconDemo */
+    public Pivot964Swing() {
+        initComponents();
+        panel_display.add(panel, BorderLayout.CENTER);
+        pack();
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
+    private void initComponents() {
+        panel_display = new javax.swing.JPanel();
+        button1 = new javax.swing.JButton();
+        button2 = new javax.swing.JButton();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        panel_display.setLayout(new java.awt.BorderLayout());
+
+        getContentPane().add(panel_display, java.awt.BorderLayout.CENTER);
+
+        button1.setText("Visible");
+        button1.addActionListener(new java.awt.event.ActionListener() {
+            @Override
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                SVGElement root = Pivot964Swing.this.panel.root;
+                try {
+                    root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
+                    root.updateTime(0f);
+                    repaint();
+                } catch (SVGElementException e) {
+                    e.printStackTrace();
+                } catch (SVGException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+
+        button2.setText("Invisible");
+        button2.addActionListener(new java.awt.event.ActionListener() {
+            @Override
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                SVGElement root = Pivot964Swing.this.panel.root;
+                try {
+                    root.setAttribute("viewBox", AnimationElement.AT_XML, "800 0 2368 1652");
+                    root.updateTime(0f);
+                    repaint();
+                } catch (SVGElementException e) {
+                    e.printStackTrace();
+                } catch (SVGException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+
+        panel_display.add(button1, java.awt.BorderLayout.EAST);
+        panel_display.add(button2, java.awt.BorderLayout.WEST);
+
+        pack();
+    }// </editor-fold>
+
+    public static void main(String args[]) {
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                new Pivot964Swing().setVisible(true);
+            }
+        });
+    }
+
+    // Variables declaration - do not modify
+    private javax.swing.JButton button1;
+    private javax.swing.JButton button2;
+    private javax.swing.JPanel panel_display;
+    // End of variables declaration
+
+}
+
+class TestPanel extends JPanel {
+    public static final long serialVersionUID = 0;
+
+    final SVGIcon icon;
+    URI uri;
+    SVGElement root;
+
+    public TestPanel() {
+        StringReader reader = new StringReader(makeDynamicSVG());
+        uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
+        icon = new SVGIcon();
+        icon.setAntiAlias(true);
+        icon.setSvgURI(uri);
+        root = icon.getSvgUniverse().getDiagram(uri).getRoot();
+
+        setPreferredSize(new Dimension(400, 400));
+    }
+
+    @Override
+    public void paintComponent(Graphics g) {
+        final int width = getWidth();
+        final int height = getHeight();
+
+        g.setColor(getBackground());
+        g.fillRect(0, 0, width, height);
+
+        icon.paintIcon(this, g, 0, 0);
+    }
+
+    private String makeDynamicSVG() {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+
+        pw.println(
+            "<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:16\" viewBox=\"781 -391 1177 826\">");
+        pw.println(
+            "<rect x=\"0\" y=\"0\" width=\"2000\" height=\"1000\" style=\"stroke:blue;fill:white\"/>");
+        pw.println("</svg>");
+
+        pw.close();
+        return sw.toString();
+    }
+
+}