svgsalamander-0~svn95.orig/ 0000755 0001750 0001750 00000000000 11562044311 014603 5 ustar moon moon svgsalamander-0~svn95.orig/svg-editor/ 0000755 0001750 0001750 00000000000 11562044207 016672 5 ustar moon moon svgsalamander-0~svn95.orig/www/ 0000755 0001750 0001750 00000000000 11562044230 015427 5 ustar moon moon svgsalamander-0~svn95.orig/www/salamanderStyle.css 0000644 0001750 0001750 00000001311 10627134103 021265 0 ustar moon moon /*
Document : __NAME__
Created on : __DATE__, __TIME__
Author : __USER__
Description:
Purpose of the stylesheet follows.
*/
/*
TODO customize this sample style
Syntax recommendation http://www.w3.org/TR/REC-CSS2/
*/
root {
display: block;
}
p.alert {
background-color: #ccffcc;
background-position: center;
border-bottom-color: green;
border-bottom-style: solid;
border-left-color: green;
border-left-style: solid;
border-right-color: green;
border-right-style: solid;
border-top-color: green;
border-top-style: solid;
font-style: inherit;
padding-bottom: 4px;
padding-left: 4px;
padding-right: 4px;
padding-top: 4px
}
svgsalamander-0~svn95.orig/www/license/ 0000755 0001750 0001750 00000000000 11562044207 017055 5 ustar moon moon svgsalamander-0~svn95.orig/www/license/license-bsd.txt 0000644 0001750 0001750 00000002722 11362434036 022012 0 ustar moon moon Copyright (c) 2010, Mark McKay
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the kitfox.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. svgsalamander-0~svn95.orig/www/license/license-lgpl.txt 0000644 0001750 0001750 00000017210 11362434036 022176 0 ustar moon moon GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
SVG Salamander is 100% pure Java, so using it in your application should not be any different than using any other JAR.
Take a look at the com.kitfox.svg.app.SVGPlayer and com.kitfox.svg.app.SVGViewer files for some straight forward ways to use Salamander.
The basic process is:
The SVGDiagram is the object you are going to be most concerned with. It provides a way to access the root of the SVG document you loaded and a means to render it to a Graphics2D.
All elements in an SVG document can be given an id that can be used to access the document in parts. For example, you can create a circle with the code <circle id="myCircle" cx="100" cy="100" r="50"/>. This circle can be referenced later with the key word 'myCircle'.
SVG Salamander provides the ability to access document parts with SVGDiagram.getElement(String elementName). You can then read and write the attributes of the element directly.
The Salamander JAR contains some controls to let you use SVG easily in Swing forms. They are:
These components are both beans and can be used in NetBeans or other beans aware Java editors. Once you have installed the Jar in your editor (see your IDE's documentation for how to do this), you can place them on your form.
Both of these beans have anti-aliasing turned off by default. To turn it on, be sure to call setAntiAlias(true).
A fast way to place an SVG element on your form:
SVG Salamander parallels the DOM model internally, and can be interactively updated at runtime. That is, you can change colors, positions and other aspects of a loaded SVGDiagram.
Tree NavigationUse SVGDiagram.getRoot() to get an instance of SVGRoot. The SVGRoot coresponds to the <SVG> element of an SVG document. You can then get a list of it's children by calling SVGRoot.getChildren(null). The tree can be further navigated at deeper depths by calling the getChildren() method.
Adding and Editing AttributesSVG Salamander stores attributes as strings and parses them into values at runtime to draw the SVG elements. This allows for the rich variety of types of values that the SVG specification defines. Attributes can also be either style attribtes or presentation attributes. Style attributes are defined in the 'style' attribute of an SVG element. Presentation attributes are the attributes defined as attributes outside of the 'style' attribute. If both style and presentation attributes are present, the style attribute overrides the presentation attribute. For example:
<ellipse id="myCircle" style="fill:red; stroke:black; stroke-width:5;" cx="30" cy="80" rx="10" ry="20"/>
In the above, the style attributes are fill, stroke and stroke-width while the presentation attributes are cx, cy, rx and ry.
SVG Salamander distinguishes between the two types of attributes by using the AnimationElement.AT_CSS and AnimationElement.AT_XML constants. AnimationElement.AT_CSS represents style attributes, and AnimationElement.AT_XML represents presentation attributes. If both style and presentation attributes exist for the same attribute name, the style attribute takes precedence.
To check if an attribute is defined
svgElement.hasAttribute("x", AnimationElement.AT_XML);
To add a new attribute attribute, call your element with the name of the attribute, a constant representing whether this attribute should be a style or presentation attribute, and a valid string representing the value of this attribute. If this attribute is already defined, this will throw a RuntimeException, so make sure to call hasAttribute() first if you're not sure if this attribute exists. The following adds a new style attribute to the given SVG element:
svgElement.addAttribute("fill-opacity", AnimationElement.AT_CSS, "0.5");
To setting an attribute, call the set function with the string representation of the value to set the attribute to. Make sure that the element already exists, or this will throw an exception:
svgElement.setAttribute("x", AnimationElement.AT_XML, "0.5");
Sometimes after setting an attribute, it will be necessary to take an animation step to update the element to reflect it's current state. For example, after setting the 'r' attribute of a circle, it will be necessary to call updateTime(timeInSeconds) on the circle or on one of the circle's ancestors to update the circle's shape. If your SVG diagram isn't using animation, you can pass any value in as the time. Not all attributes will require updateTime() to be called, but calling this will not hurt. Typically, atributes that alter shape will require an update while attributes that alter fills and colors do not. For convenience, you might want to update all the elements in a diagram, and then call svgDiagram.updateTime() to update the entire document at once.
circle.setAttribute("r", AnimationElement.AT_XML, "10");
circle.updateTime(0f);
At the moment, you can only set the text of tspan elements. You can do this by calling setText() on the tspan element. After doing this, you need to call rebuild() on the text element that contains the tspan element to update the caching data.
To get the value of an attribute, you can create an empty attribute and pass it to getStyle(). This will overwrite the value in the passed style attribute with the element's value of the attribute.
StyleAttribute attrib = new StyleAttribute();
svgElement.getStyle("fill", attrib);
double value = attrib.getDoubleValue();
Note that getting the value of a style attribute will first check to see if this attribute has a style set. If not, it checks to find the closest ancestor that may have this style set. If no ancestor has this attribute set, it then checks to see if a presentation attribute with the same name is set on this element. This is in keeping with the SVG convetion that style attributes override first ancestors and then presentation attributes. To get the value of only the style attribute of this element, call getStyleAbsolute() instead. getPresAbsolute() will check for the local presentation attribute.
Adding and removing childrenTo add a new element, create an instance of the element you wish to add, set it's attributes, and then add it to it's parent elemnt in the scene graph:
SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri);
Group group = (Group)diagram.getElement("parentGroup");
Circle circle = new Circle();
try
{
circle.addAttribute("cx", AnimationElement.AT_XML, "80");
circle.addAttribute("cy", AnimationElement.AT_XML, "80");
circle.addAttribute("r", AnimationElement.AT_XML, "10");
group.loaderAddChild(null, circle);
//Update animation state for group and it's decendants so that it reflects new animation values.
// We could also call diagram.update(0.0) or SVGCache.getSVGUniverse().update(). Note that calling
// circle.update(0.0) won't display anything since even though it will update the circle's state,
// it won't update the parent group's state.
group.updateTime(0.0);
}
catch (SVGException e)
{
e.printStackTrace();
}
To remove an element, call removeChild() on an element capable of having children:
SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri);
Group group = (Group)diagram.getElement("circleGroup");
Circle circle = (Circle)diagram.getElement("circleToRemove");
try
{
group.removeChild(circle);
}
catch (SVGException e)
{
e.printStackTrace();
}
To pick shapes within an SVGDiagram, use the pick() method.
SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri);
Point pickPoint = new Point(20, 80);
Vector pickedElements = diagram.pick(pickPoint, null);
The pick method will return a vector of vectors of SVGElements. Each vector contains the path from the root of the diagram to the picked RenderableElement.
The SVG Salamander Ant task allows you to easily convert SVG documents to images from an Ant script. To use it, include the SVGSalamander.jar in your class path and write an Ant target similar to:
<target name="testAntTask"> <typedef name="SVGToImage" classname="com.kitfox.svg.app.ant.SVGToImageAntTask" classpath="www/binaries/svgSalamander.jar"/> <SVGToImage format="png" antiAlias="false" verbose="true"> <fileset dir="examples"> <include name="hinorei.svg"/> </fileset> </SVGToImage> </target>Parameters:
Some example SVG files that can be loaded and played in this browser can be found in the /examples directory of the source.
Here's some example code that demonstrates the use of the SVGSalamander package:This is a minimal program which demonstrates a correct way to create SVG Icons and render them to the screen. This particular example generates the SVG document dynamically. You can also load SVG documents from file.
This example can be found in the SVG Salamnder source.
package com.kitfox.svg.example; import java.awt.*; import java.net.*; import java.io.*; import javax.swing.*; import com.kitfox.svg.*; import com.kitfox.svg.app.beans.*; class IconPanel extends JPanel { public static final long serialVersionUID = 0; final SVGIcon icon; public IconPanel() { StringReader reader = new StringReader(makeDynamicSVG()); URI uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage"); icon = new SVGIcon(); icon.setSvgURI(uri); setPreferredSize(new Dimension(400, 400)); } public void paintComponent(Graphics g) { final int width = getWidth(); final int height = getHeight(); g.setColor(getBackground()); g.fillRect(0, 0, width, height); icon.paintIcon(this, g, 0, 0); } private String makeDynamicSVG() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:4\">"); pw.println(" <circle cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/>"); pw.println(" <circle cx=\"140\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>"); pw.println(" <circle cx=\"260\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>"); pw.println(" <polyline points=\"100 300 150 340 250 240 300 300\" style=\"stroke:red\"/>"); pw.println("</svg>"); pw.close(); return sw.toString(); } } /** * * @author kitfox */ public class SVGIODemoFrame extends javax.swing.JFrame { public static final long serialVersionUID = 0; IconPanel panel = new IconPanel(); /** Creates new form SVGIconDemo */ public SVGIODemoFrame() { initComponents(); this.getContentPane().add(panel, BorderLayout.CENTER); pack(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() { setLayout(new java.awt.BorderLayout()); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SVGIODemoFrame().setVisible(true); } }); } }svgsalamander-0~svn95.orig/www/docs/exampleCode/SVGIconDemo.html 0000644 0001750 0001750 00000037121 11417443444 023565 0 ustar moon moon
This is a minimal program which demonstrates a correct way to create SVG Icons and render them to the screen. This particular example generates the SVG document dynamically. You can also load SVG documents from file.
This demonstrates simple user interaction with an SVGDiagram. You can create and remove diagram elements, as well as alter diagram attributes.
This example can be found in the SVG Salamnder source.
package com.kitfox.svg.example; import java.awt.*; import java.net.*; import java.io.*; import java.util.*; import javax.swing.*; import com.kitfox.svg.*; import com.kitfox.svg.animation.*; import com.kitfox.svg.app.beans.*; class DynamicIconPanel extends JPanel { public static final long serialVersionUID = 0; final SVGIcon icon; URI uri; LinkedList extraElements = new LinkedList(); public DynamicIconPanel() { StringReader reader = new StringReader(makeDynamicSVG()); uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage"); icon = new SVGIcon(); icon.setAntiAlias(true); icon.setSvgURI(uri); setPreferredSize(new Dimension(400, 400)); } public void paintComponent(Graphics g) { final int width = getWidth(); final int height = getHeight(); g.setColor(getBackground()); g.fillRect(0, 0, width, height); icon.paintIcon(this, g, 0, 0); } private String makeDynamicSVG() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:16\">"); pw.println(" <circle id=\"bigCircle\" cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/>"); pw.println(" <g id=\"extraElementGroup\" style=\"stroke-width:4;fill:green\"/>"); pw.println(" <text id=\"userTextParent\" x=\"0\" y=\"40\" style=\"font-size:40;stroke:none;fill:red\">"); pw.println(" <tspan id=\"userText\">Hello!</tspan>"); pw.println(" </text>"); pw.println("</svg>"); pw.close(); return sw.toString(); } public void setCircleForeground(Color color) { SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Circle circle = (Circle)diagram.getElement("bigCircle"); String colorStrn = Integer.toHexString(color.getRGB() & 0xffffff); try { if (!circle.hasAttribute("stroke", AnimationElement.AT_CSS)) { circle.addAttribute("stroke", AnimationElement.AT_CSS, "#" + colorStrn); } else { circle.setAttribute("stroke", AnimationElement.AT_CSS, "#" + colorStrn); } } catch (SVGElementException e) { e.printStackTrace(); } } public void setCircleBackground(Color color) { SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Circle circle = (Circle)diagram.getElement("bigCircle"); String colorStrn = Integer.toHexString(color.getRGB() & 0xffffff); try { if (!circle.hasAttribute("fill", AnimationElement.AT_CSS)) { circle.addAttribute("fill", AnimationElement.AT_CSS, "#" + colorStrn); } else { circle.setAttribute("fill", AnimationElement.AT_CSS, "#" + colorStrn); } } catch (SVGElementException e) { e.printStackTrace(); } } public void setText(String text) { SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Tspan tspan = (Tspan)diagram.getElement("userText"); tspan.setText(text); Text textEle = (Text)diagram.getElement("userTextParent"); try { textEle.rebuild(); } catch (Exception e) { e.printStackTrace(); } } public void addCircle() { SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Group group = (Group)diagram.getElement("extraElementGroup"); Circle circle = new Circle(); try { int cx = (int)(Math.random() * 400); int cy = (int)(Math.random() * 400); circle.addAttribute("cx", AnimationElement.AT_XML, "" + cx); circle.addAttribute("cy", AnimationElement.AT_XML, "" + cy); circle.addAttribute("r", AnimationElement.AT_XML, "10"); group.loaderAddChild(null, circle); //Update animation state or group and it's decendants so that it reflects new animation values. // We could also call diagram.update(0.0) or SVGCache.getSVGUniverse().update(). Note that calling // circle.update(0.0) won't display anything since even though it will update the circle's state, // it won't update the parent group's state. group.updateTime(0.0); //Keep track of circles so we can remove them later extraElements.add(circle); } catch (SVGException e) { e.printStackTrace(); } } public void addText() { SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Group group = (Group)diagram.getElement("extraElementGroup"); Text text = new Text(); try { int x = (int)(Math.random() * 300) + 50; int y = (int)(Math.random() * 300) + 50; text.addAttribute("x", AnimationElement.AT_XML, "" + x); text.addAttribute("y", AnimationElement.AT_XML, "" + y); text.addAttribute("font-size", AnimationElement.AT_CSS, "12"); // text.appendText("text"); Tspan tspan = new Tspan(); tspan.setText("text"); text.appendTspan(tspan); group.loaderAddChild(null, text); text.build(); //Update animation state or group and it's decendants so that it reflects new animation values. // We could also call diagram.update(0.0) or SVGCache.getSVGUniverse().update(). Note that calling // circle.update(0.0) won't display anything since even though it will update the circle's state, // it won't update the parent group's state. group.updateTime(0.0); //Keep track of circles so we can remove them later extraElements.add(text); } catch (SVGException e) { e.printStackTrace(); } } public void removeElement() { int size = extraElements.size(); if (size == 0) return; int idx = (int)(Math.random() * size); ShapeElement shapeElement = (ShapeElement)extraElements.remove(idx); SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); Group group = (Group)diagram.getElement("extraElementGroup"); try { group.removeChild(shapeElement); } catch (SVGException e) { e.printStackTrace(); } } } /** * * @author kitfox */ public class SVGIconDemoFrame extends javax.swing.JFrame { public static final long serialVersionUID = 0; DynamicIconPanel panel = new DynamicIconPanel(); /** Creates new form SVGIconDemo */ public SVGIconDemoFrame() { 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(); jPanel2 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); bn_back = new javax.swing.JButton(); bn_front = new javax.swing.JButton(); bn_add = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); bn_remove = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); text_userText = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); panel_display.setLayout(new java.awt.BorderLayout()); getContentPane().add(panel_display, java.awt.BorderLayout.CENTER); jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS)); bn_back.setText("Background"); bn_back.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bn_backActionPerformed(evt); } }); jPanel3.add(bn_back); bn_front.setText("Foreground"); bn_front.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bn_frontActionPerformed(evt); } }); jPanel3.add(bn_front); bn_add.setText("Add Circle"); bn_add.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bn_addActionPerformed(evt); } }); jPanel3.add(bn_add); jButton1.setText("Add Text"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jPanel3.add(jButton1); bn_remove.setText("Remove"); bn_remove.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bn_removeActionPerformed(evt); } }); jPanel3.add(bn_remove); jPanel2.add(jPanel3); jLabel1.setText("Text"); jPanel1.add(jLabel1); text_userText.setText("Hello!"); text_userText.setPreferredSize(new java.awt.Dimension(200, 20)); text_userText.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { text_userTextActionPerformed(evt); } }); jPanel1.add(text_userText); jPanel2.add(jPanel1); getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { panel.addText(); repaint(); } private void text_userTextActionPerformed(java.awt.event.ActionEvent evt) { panel.setText(text_userText.getText()); repaint(); } private void bn_removeActionPerformed(java.awt.event.ActionEvent evt) { panel.removeElement(); repaint(); } private void bn_addActionPerformed(java.awt.event.ActionEvent evt) { panel.addCircle(); repaint(); } private void bn_frontActionPerformed(java.awt.event.ActionEvent evt) { panel.setCircleForeground(new Color((float)Math.random(), (float)Math.random(), (float)Math.random())); repaint(); } private void bn_backActionPerformed(java.awt.event.ActionEvent evt) { panel.setCircleBackground(new Color((float)Math.random(), (float)Math.random(), (float)Math.random())); repaint(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SVGIconDemoFrame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton bn_add; private javax.swing.JButton bn_back; private javax.swing.JButton bn_front; private javax.swing.JButton bn_remove; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel panel_display; private javax.swing.JTextField text_userText; // End of variables declaration }svgsalamander-0~svn95.orig/www/docs/exampleCode/svgIODemoScreenShot.png 0000644 0001750 0001750 00000021734 10607673157 025173 0 ustar moon moon PNG IHDR r sRGB gAMA a cHRM z&