dip.gui.map
Class SVGUtils

java.lang.Object
  extended bydip.gui.map.SVGUtils

public class SVGUtils
extends java.lang.Object

Assorted utilities for altering the Batik SVG DOM.

The add/remove/replace methods are not only thread safe but also follow Batik guidelines for altering the DOM. If the SVGComponent has been set to dynamic prior to loading of the SVG document, then any DOM change will be rendered automatically.

Also note that for the title/descriptions setting methods, it would be faster to create a Title or Description SVG element and use add / remove / replace as appropriate. This could be an issue if there are frequent title or description changes.


Constructor Summary
SVGUtils()
           
 
Method Summary
static void appendFloat(java.lang.StringBuffer sb, float v)
          Formats a Floating-Point value into a StringBuffer, using the jDip default precision.
static org.w3c.dom.svg.SVGUseElement createUseElement(org.w3c.dom.svg.SVGDocument document, java.lang.String symbolName, java.lang.String id, java.lang.String attClass, float x, float y, MapMetadata.SymbolSize symbolSize)
          Creates an SVG <use> element.
static org.w3c.dom.Node findNodeWithID(org.w3c.dom.Node node, java.lang.String id)
          Walks the DOM tree from root, until the first element with the same ID is found.
static java.lang.String floatToString(float v)
          Formats a Floating-Point value into a String, using the jDip default precision.
static void getBestFit(org.apache.batik.swing.JSVGCanvas canvas)
          Calculates the maximum possible stretching of a canvas, remaining inside the bounds of a given scrollPane.
static org.w3c.dom.svg.SVGElement[] idFinderSVG(org.w3c.dom.Node root)
          Returns all elements with IDs under the given root, as an array of SVGElement objects.
static void setDescription(org.w3c.dom.svg.SVGDocument document, org.w3c.dom.svg.SVGElement element, java.lang.String description)
          Sets the description of an SVG element.
static void setTitle(org.w3c.dom.svg.SVGDocument document, org.w3c.dom.svg.SVGElement element, java.lang.String title)
          Sets the title of an SVG element.
static java.util.Map tagFinderSVG(java.util.List lookList, org.w3c.dom.Node root)
          Given a list of objects, finds the first SVG tag that has an ID that matches the object.
static java.util.Map tagFinderSVG(java.util.List lookList, org.w3c.dom.Node root, boolean anySVGElement)
          As above, but allows any SVG element to be returned
static void tagFinderSVG(java.util.Map map, java.util.List lookList, org.w3c.dom.Node root)
          Given a list of objects, finds the first SVG tag that has an ID that matches the object.
static void tagFinderSVG(java.util.Map map, java.util.List lookList, org.w3c.dom.Node root, boolean anySVGElement)
          As above but allows any SVG element to be returned
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVGUtils

public SVGUtils()
Method Detail

setTitle

public static void setTitle(org.w3c.dom.svg.SVGDocument document,
                            org.w3c.dom.svg.SVGElement element,
                            java.lang.String title)
Sets the title of an SVG element.

a null title is not valid.


setDescription

public static void setDescription(org.w3c.dom.svg.SVGDocument document,
                                  org.w3c.dom.svg.SVGElement element,
                                  java.lang.String description)
Sets the description of an SVG element.

A null description is not valid.


createUseElement

public static org.w3c.dom.svg.SVGUseElement createUseElement(org.w3c.dom.svg.SVGDocument document,
                                                             java.lang.String symbolName,
                                                             java.lang.String id,
                                                             java.lang.String attClass,
                                                             float x,
                                                             float y,
                                                             MapMetadata.SymbolSize symbolSize)
Creates an SVG <use> element.

Allows insertion of a previously-defined <symbol> element. If id is null, no ID is used. If style is null, no style is used.

x,y are required.
SymbolSize will specify the width/height; if null, no width/height will be specified.


tagFinderSVG

public static java.util.Map tagFinderSVG(java.util.List lookList,
                                         org.w3c.dom.Node root)
Given a list of objects, finds the first SVG tag that has an ID that matches the object. That element is stored in the returned HashMap, and can be retreived via the Object key

Null objects are ignored.

Supported Objects in the looklist are:


tagFinderSVG

public static java.util.Map tagFinderSVG(java.util.List lookList,
                                         org.w3c.dom.Node root,
                                         boolean anySVGElement)
As above, but allows any SVG element to be returned


tagFinderSVG

public static void tagFinderSVG(java.util.Map map,
                                java.util.List lookList,
                                org.w3c.dom.Node root)
Given a list of objects, finds the first SVG tag that has an ID that matches the object. That element is stored in the returned HashMap, and can be retreived via the Object key

The SVG elements found are put into the supplied java.util.Map object.

Null objects are ignored.

Supported Objects in the looklist are:


tagFinderSVG

public static void tagFinderSVG(java.util.Map map,
                                java.util.List lookList,
                                org.w3c.dom.Node root,
                                boolean anySVGElement)
As above but allows any SVG element to be returned


idFinderSVG

public static org.w3c.dom.svg.SVGElement[] idFinderSVG(org.w3c.dom.Node root)
Returns all elements with IDs under the given root, as an array of SVGElement objects. Objects w/o IDs are ignored.


findNodeWithID

public static org.w3c.dom.Node findNodeWithID(org.w3c.dom.Node node,
                                              java.lang.String id)
Walks the DOM tree from root, until the first element with the same ID is found. Case Insensitive.


getBestFit

public static void getBestFit(org.apache.batik.swing.JSVGCanvas canvas)
Calculates the maximum possible stretching of a canvas, remaining inside the bounds of a given scrollPane.

Parameters:
canvas - the canvas to be fitted

floatToString

public static java.lang.String floatToString(float v)
Formats a Floating-Point value into a String, using the jDip default precision.


appendFloat

public static void appendFloat(java.lang.StringBuffer sb,
                               float v)
Formats a Floating-Point value into a StringBuffer, using the jDip default precision.



Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.