01: /*
02: * PointSystem.java
03: *
04: * Created on 19 January 2007, 17:57
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package com.xoetrope.svg;
11:
12: import com.kitfox.svg.SVGRoot;
13: import com.xoetrope.svg.XSvgImageMap;
14: import java.awt.geom.Point2D;
15:
16: /**
17: *
18: *
19: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
20: * the GNU Public License (GPL), please see license.txt for more details. If
21: * you make commercial use of this software you must purchase a commercial
22: * license from Xoetrope.</p>
23: * <p> $Revision: 1.2 $</p>
24: */
25: public class XPointSystem {
26: protected XSvgImageMap imageMap;
27:
28: /**
29: * Creates a new instance of PointSystem
30: * This class is used to convert points from the glasspane coordinate system to the svg coordinate system and vice-versa.
31: */
32: public XPointSystem(XSvgImageMap imageMap) {
33: this .imageMap = imageMap;
34: }
35:
36: /**
37: * Converts a coordinate from the glasspane coordinate system to the svg map coordinate system.
38: * @param x a <CODE>double</CODE> specifying the x coordinate to be converted.
39: * @param y a <CODE>double</CODE> specifying the y coordinate to be converted.
40: * @return <CODE>Point2D</CODE> object containing the converted coordinates.
41: */
42: public Point2D glassPaneToSvg(double x, double y) {
43: SVGRoot root = imageMap.getSvgDiagram().getRoot();
44: double[] attr = root.getPresAbsolute("viewBox").getDoubleList();
45:
46: int returnX = (int) ((x / (root.getDeviceWidth() / attr[2])) + attr[0]);
47: int returnY = (int) ((y / (root.getDeviceHeight() / attr[3])) + attr[1]);
48:
49: return new Point2D.Double(returnX, returnY);
50: }
51:
52: /**
53: * Converts a coordinate from the svg map coordinate system to the glasspane coordinate system.
54: * @param x a <CODE>double</CODE> specifying the x coordinate to be converted.
55: * @param y a <CODE>double</CODE> specifying the y coordinate to be converted.
56: * @return <CODE>Point2D</CODE> object containing the converted coordinates.
57: */
58: public Point2D svgToGlassPane(double x, double y) {
59: SVGRoot root = imageMap.getSvgDiagram().getRoot();
60: double[] attr = root.getPresAbsolute("viewBox").getDoubleList();
61:
62: int returnX = (int) ((x - attr[0]) * (root.getDeviceWidth() / attr[2]));
63: int returnY = (int) ((y - attr[1]) * (root.getDeviceHeight() / attr[3]));
64:
65: return new Point2D.Double(returnX, returnY);
66: }
67: }
|