001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.renderer.style;
034:
035: import java.awt.*;
036: import java.awt.geom.AffineTransform;
037: import java.awt.geom.GeneralPath;
038: import java.awt.geom.NoninvertibleTransformException;
039: import java.awt.geom.Point2D;
040: import java.awt.font.*;
041:
042: import com.vividsolutions.jump.I18N;
043: import com.vividsolutions.jump.workbench.model.Layer;
044: import com.vividsolutions.jump.workbench.ui.GUIUtil;
045: import com.vividsolutions.jump.workbench.ui.Viewport;
046: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
047: import com.vividsolutions.jts.geom.*;
048:
049: /**
050: * Displays line segment length and absolute angle.
051: *
052: * @author Martin Davis
053: * @version 1.0
054: */
055: public class MetricsLineStringSegmentStyle extends
056: LineStringSegmentStyle {
057: public final static int FONT_BASE_SIZE = 10;
058: private Font font = new Font("Dialog", Font.PLAIN, FONT_BASE_SIZE);
059:
060: /**
061: * @param finAngle degrees
062: * @param finLength pixels
063: */
064: public MetricsLineStringSegmentStyle(String name, String iconFile) {
065: super (name, IconLoader.icon(iconFile));
066: }
067:
068: protected void paint(Coordinate p0, Coordinate p1,
069: Viewport viewport, Graphics2D graphics) throws Exception {
070: String lenStr = Double.toString(p0.distance(p1));
071: double ang = Math.toDegrees(Math
072: .atan2(p1.y - p0.y, p1.x - p0.x));
073: String angStr = Double.toString(ang);
074: String text = lenStr + " / " + angStr;
075:
076: paint(text, viewport
077: .toViewPoint(new Point2D.Double(p0.x, p0.y)), viewport
078: .toViewPoint(new Point2D.Double(p1.x, p1.y)), viewport,
079: graphics);
080: }
081:
082: private void paint(String text, Point2D p0, Point2D p1,
083: Viewport viewport, Graphics2D g)
084: throws NoninvertibleTransformException {
085: if (p0.equals(p1)) {
086: return;
087: }
088:
089: Point2D mid = new Point2D.Float(
090: (float) ((p0.getX() + p1.getX()) / 2), (float) ((p0
091: .getY() + p1.getY()) / 2));
092:
093: g.setColor(Color.BLACK);
094: g.setStroke(stroke);
095:
096: TextLayout layout = new TextLayout(text, font, g
097: .getFontRenderContext());
098: layout.draw(g, (float) mid.getX(), (float) mid.getY());
099: }
100:
101: protected void paint(Point2D p0, Point2D p1, Viewport viewport,
102: Graphics2D g) throws NoninvertibleTransformException {
103: throw new UnsupportedOperationException(
104: "This method should never be called");
105: }
106:
107: public static class LengthAngle extends
108: MetricsLineStringSegmentStyle {
109: public LengthAngle() {
110: super (
111: I18N
112: .get("ui.renderer.style.MetricsLineStringSegmentStyle.Segment-Metrics"),
113: "LengthAngleDecorator.gif");
114: }
115: }
116:
117: }
|