diva.canvas.toolbox
Class SVGParser

java.lang.Object
  extended by diva.canvas.toolbox.SVGParser

public class SVGParser
extends java.lang.Object

A collection of utilities to help parse graphics out of SVG files. For a description of SVG see the specification.

Version:
$Id: SVGParser.java 59167 2010-09-21 17:08:02Z cxh $
Author:
John Reekie, Steve Neuendorffer

Field Summary
private static java.lang.Class _refClass
           
 
Constructor Summary
SVGParser()
           
 
Method Summary
private static double _getDouble(java.util.Map map, java.lang.String name)
           
private static double _getDouble(java.util.Map map, java.lang.String name, double def)
           
static java.lang.String[] colorNames()
          Return a list of basic color names that are understood.
static PaintedList createPaintedList(XmlElement root)
          Given an XmlElement, create a PaintedList.
static PaintedObject createPaintedObject(java.lang.String type, java.util.Map attributes)
          Create a new painted object.
static PaintedObject createPaintedObject(java.lang.String type, java.util.Map attributes, java.lang.String content)
          Create a new painted object.
static PaintedObject createPaintedObject(java.lang.String type, java.lang.String attributes, java.lang.String content)
          Create a new painted object.
static void hashAttributes(java.lang.String s, java.util.Map map)
          Given a XML-style attribute string and a hash-table, add each attribute and its value to the table.
private static java.awt.Color lookupColor(java.lang.String color)
          Given a string, return a color.
private static double[] parseCoordString(java.lang.String s)
          Parse a string of numbers into an array of double.
private static void processPaintedPathAttributes(PaintedPath pp, java.util.Map attributes)
          Set the attributes of a PaintedPath from a hash-table
private static void processPaintedShapeAttributes(PaintedShape ps, java.util.Map attributes)
          Set the attributes of a PaintedShape from a hash-table
private static void processPaintedStringAttributes(PaintedString pp, java.util.Map attributes)
          Set the attributes of a PaintedString from a hash-table
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_refClass

private static java.lang.Class _refClass
Constructor Detail

SVGParser

public SVGParser()
Method Detail

colorNames

public static java.lang.String[] colorNames()
Return a list of basic color names that are understood. Note that colors can also be specified using #rrggbb notation, where rr is the hex representation of the red component, etc. This method can be used to construct a dialog listing available colors symbolically by name.

Returns:
An array of symbolic color names.

createPaintedObject

public static PaintedObject createPaintedObject(java.lang.String type,
                                                java.lang.String attributes,
                                                java.lang.String content)
Create a new painted object. The element is parsed from two strings, the first being a representation of the element type, and the second being an XML-style attribute string. Any attributes that are not recognized will be ignored. Legal types and their attributes are:

Parameters:
type - The element type
attributes - An XML-style attribute string
content - The content
Returns:
a new painted object.

createPaintedObject

public static PaintedObject createPaintedObject(java.lang.String type,
                                                java.util.Map attributes,
                                                java.lang.String content)
Create a new painted object. The first argument is a string representation of the element type, and the second is a hash-table containing attributes of the object. Any attributes that are not recognized will be ignored. See the add(String, String) for a description of legal types and their attributes.


createPaintedObject

public static PaintedObject createPaintedObject(java.lang.String type,
                                                java.util.Map attributes)
Create a new painted object. The first argument is a string representation of the element type, and the second is a hash-table containing attributes of the object. Any attributes that are not recognized will be ignored. See the add(String, String) for a description of legal types and their attributes.


hashAttributes

public static void hashAttributes(java.lang.String s,
                                  java.util.Map map)
Given a XML-style attribute string and a hash-table, add each attribute and its value to the table.

FIXME: this sucks.


lookupColor

private static java.awt.Color lookupColor(java.lang.String color)
                                   throws java.lang.NumberFormatException
Given a string, return a color.

Throws:
java.lang.NumberFormatException

parseCoordString

private static double[] parseCoordString(java.lang.String s)
Parse a string of numbers into an array of double. The doubles can be delimited by commas and spaces.


processPaintedShapeAttributes

private static void processPaintedShapeAttributes(PaintedShape ps,
                                                  java.util.Map attributes)
                                           throws java.lang.NumberFormatException
Set the attributes of a PaintedShape from a hash-table

Throws:
java.lang.NumberFormatException

processPaintedPathAttributes

private static void processPaintedPathAttributes(PaintedPath pp,
                                                 java.util.Map attributes)
                                          throws java.lang.NumberFormatException
Set the attributes of a PaintedPath from a hash-table

Throws:
java.lang.NumberFormatException

processPaintedStringAttributes

private static void processPaintedStringAttributes(PaintedString pp,
                                                   java.util.Map attributes)
                                            throws java.lang.NumberFormatException
Set the attributes of a PaintedString from a hash-table

Throws:
java.lang.NumberFormatException

createPaintedList

public static PaintedList createPaintedList(XmlElement root)
Given an XmlElement, create a PaintedList.

Parameters:
root - The XmlElement.
Returns:
The PaintedList.

_getDouble

private static double _getDouble(java.util.Map map,
                                 java.lang.String name,
                                 double def)

_getDouble

private static double _getDouble(java.util.Map map,
                                 java.lang.String name)