de.lmu.ifi.dbs.elki.visualization.svg
Class SVGUtil

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.visualization.svg.SVGUtil

public final class SVGUtil
extends Object

Utility class for SVG processing. Much of the classes are to allow easier attribute setting (conversion to string) and Namespace handling


Field Summary
private static StyleSheet colorLookupStylesheet
          CSS Stylesheet from Javax, to parse color values.
static NumberFormat FMT
          Formatter to output numbers in a valid SVG number format.
static String HOURGLASS_PATH
          Hourglass object.
static String HOURGLASS_STYLE
          Hourglass style.
private static HashMap<String,Integer> SVG_COLOR_NAMES
          SVG color names conversion.
 
Constructor Summary
SVGUtil()
           
 
Method Summary
static void addCSSClass(Element e, String cssclass)
          Add a CSS class to an Element.
static String colorToString(Color col)
          Convert a color name from an AWT color object to CSS syntax
static org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt)
          Convert the coordinates of an DOM Event from screen into element coordinates.
static String fmt(double x)
          Format a double according to the SVG specs.
static String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double margin)
          Make a transform string to add margins
static String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double xmargin, double ymargin)
          Make a transform string to add margins
static String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double lmargin, double tmargin, double rmargin, double bmargin)
          Make a transform string to add margins
static Element makeStyleElement(Document document)
          Make a new CSS style element for the given Document.
static void removeCSSClass(Element e, String cssclass)
          Remove a CSS class from an Element.
static void removeLastChild(Element tag)
          Remove last child of an element, when present
static void setAtt(Element el, String name, double d)
          Set a SVG attribute
static void setAtt(Element el, String name, int d)
          Set a SVG attribute
static void setAtt(Element el, String name, String d)
          Set a SVG attribute
static void setCSSClass(Element e, String cssclass)
          Set the CSS class of an Element.
static void setStyle(Element el, String d)
          Set a SVG style attribute
static Color stringToColor(String str)
          Convert a color name from SVG syntax to an AWT color object.
static Element svgCircle(Document document, double cx, double cy, double r)
          Create a SVG circle element.
static Element svgElement(Document document, String name)
          Create a SVG element in appropriate namespace
static Element svgLine(Document document, double x1, double y1, double x2, double y2)
          Create a SVG line element.
static Element svgRect(Document document, double x, double y, double w, double h)
          Create a SVG rectangle element.
static Element svgText(Document document, double x, double y, String text)
          Create a SVG text element.
static Element svgWaitIcon(Document document, double x, double y, double w, double h)
          Draw a simple "please wait" icon (in-progress) as placeholder for running renderings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FMT

public static final NumberFormat FMT
Formatter to output numbers in a valid SVG number format.


HOURGLASS_PATH

public static final String HOURGLASS_PATH
Hourglass object.

See Also:
Constant Field Values

HOURGLASS_STYLE

public static final String HOURGLASS_STYLE
Hourglass style.

See Also:
Constant Field Values

SVG_COLOR_NAMES

private static final HashMap<String,Integer> SVG_COLOR_NAMES
SVG color names conversion.


colorLookupStylesheet

private static final StyleSheet colorLookupStylesheet
CSS Stylesheet from Javax, to parse color values.

Constructor Detail

SVGUtil

public SVGUtil()
Method Detail

fmt

public static String fmt(double x)
Format a double according to the SVG specs.

Parameters:
x - number to format
Returns:
String representation

svgElement

public static Element svgElement(Document document,
                                 String name)
Create a SVG element in appropriate namespace

Parameters:
document - containing document
name - node name
Returns:
new SVG element.

setAtt

public static void setAtt(Element el,
                          String name,
                          double d)
Set a SVG attribute

Parameters:
el - element
name - attribute name
d - double value

setAtt

public static void setAtt(Element el,
                          String name,
                          int d)
Set a SVG attribute

Parameters:
el - element
name - attribute name
d - integer value

setAtt

public static void setAtt(Element el,
                          String name,
                          String d)
Set a SVG attribute

Parameters:
el - element
name - attribute name
d - string value

setStyle

public static void setStyle(Element el,
                            String d)
Set a SVG style attribute

Parameters:
el - element
d - style value

setCSSClass

public static void setCSSClass(Element e,
                               String cssclass)
Set the CSS class of an Element. See also addCSSClass(org.w3c.dom.Element, java.lang.String) and removeCSSClass(org.w3c.dom.Element, java.lang.String).

Parameters:
e - Element
cssclass - class to set.

addCSSClass

public static void addCSSClass(Element e,
                               String cssclass)
Add a CSS class to an Element.

Parameters:
e - Element
cssclass - class to add.

removeCSSClass

public static void removeCSSClass(Element e,
                                  String cssclass)
Remove a CSS class from an Element.

Parameters:
e - Element
cssclass - class to remove.

makeStyleElement

public static Element makeStyleElement(Document document)
Make a new CSS style element for the given Document.

Parameters:
document - document (factory)
Returns:
new CSS style element.

svgRect

public static Element svgRect(Document document,
                              double x,
                              double y,
                              double w,
                              double h)
Create a SVG rectangle element.

Parameters:
document - document to create in (factory)
x - X coordinate
y - Y coordinate
w - Width
h - Height
Returns:
new element

svgCircle

public static Element svgCircle(Document document,
                                double cx,
                                double cy,
                                double r)
Create a SVG circle element.

Parameters:
document - document to create in (factory)
cx - center X
cy - center Y
r - radius
Returns:
new element

svgLine

public static Element svgLine(Document document,
                              double x1,
                              double y1,
                              double x2,
                              double y2)
Create a SVG line element. Do not confuse this with path elements.

Parameters:
document - document to create in (factory)
x1 - first point x
y1 - first point y
x2 - second point x
y2 - second point y
Returns:
new element

svgText

public static Element svgText(Document document,
                              double x,
                              double y,
                              String text)
Create a SVG text element.

Parameters:
document - document to create in (factory)
x - first point x
y - first point y
text - Content of text element.
Returns:
New text element.

svgWaitIcon

public static Element svgWaitIcon(Document document,
                                  double x,
                                  double y,
                                  double w,
                                  double h)
Draw a simple "please wait" icon (in-progress) as placeholder for running renderings.

Parameters:
document - Document.
x - Left
y - Top
w - Width
h - Height
Returns:
New element (currently a SVGConstants.SVG_PATH_TAG)

stringToColor

public static Color stringToColor(String str)
Convert a color name from SVG syntax to an AWT color object.

Parameters:
str - Color name
Returns:
Color value

colorToString

public static String colorToString(Color col)
Convert a color name from an AWT color object to CSS syntax

Parameters:
col - Color value
Returns:
Color string

makeMarginTransform

public static String makeMarginTransform(double owidth,
                                         double oheight,
                                         double iwidth,
                                         double iheight,
                                         double lmargin,
                                         double tmargin,
                                         double rmargin,
                                         double bmargin)
Make a transform string to add margins

Parameters:
owidth - Width of outer (embedding) canvas
oheight - Height of outer (embedding) canvas
iwidth - Width of inner (embedded) canvas
iheight - Height of inner (embedded) canvas
lmargin - Left margin (in inner canvas' units)
tmargin - Top margin (in inner canvas' units)
rmargin - Right margin (in inner canvas' units)
bmargin - Bottom margin (in inner canvas' units)
Returns:
Transform string

makeMarginTransform

public static String makeMarginTransform(double owidth,
                                         double oheight,
                                         double iwidth,
                                         double iheight,
                                         double xmargin,
                                         double ymargin)
Make a transform string to add margins

Parameters:
owidth - Width of outer (embedding) canvas
oheight - Height of outer (embedding) canvas
iwidth - Width of inner (embedded) canvas
iheight - Height of inner (embedded) canvas
xmargin - Left and right margin (in inner canvas' units)
ymargin - Top and bottom margin (in inner canvas' units)
Returns:
Transform string

makeMarginTransform

public static String makeMarginTransform(double owidth,
                                         double oheight,
                                         double iwidth,
                                         double iheight,
                                         double margin)
Make a transform string to add margins

Parameters:
owidth - Width of outer (embedding) canvas
oheight - Height of outer (embedding) canvas
iwidth - Width of inner (embedded) canvas
iheight - Height of inner (embedded) canvas
margin - Margin (in inner canvas' units)
Returns:
Transform string

elementCoordinatesFromEvent

public static org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(Document doc,
                                                                   Element tag,
                                                                   Event evt)
Convert the coordinates of an DOM Event from screen into element coordinates.

Parameters:
doc - Document context
tag - Element containing the coordinate system
evt - Event to interpret
Returns:
coordinates

removeLastChild

public static void removeLastChild(Element tag)
Remove last child of an element, when present

Parameters:
tag - Parent

Release 0.4.0 (2011-09-20_1324)