001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.renderer.style;
017:
018: // J2SE dependencies
019: import java.awt.Shape;
020: import java.awt.geom.Rectangle2D;
021:
022: import org.geotools.geometry.jts.TransformedShape;
023: import org.geotools.resources.Utilities;
024:
025: /**
026: * Style to represent points as small filled and stroked shapes
027: *
028: * @author Andrea Aime
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/render/src/main/java/org/geotools/renderer/style/MarkStyle2D.java $
030: * @version $Id: MarkStyle2D.java 24458 2007-02-16 17:05:44Z simboss $
031: */
032: public class MarkStyle2D extends PolygonStyle2D {
033: Shape shape;
034: int size;
035: float rotation;
036:
037: /**
038: * Returns the shape rotation, in radians
039: *
040: */
041: public float getRotation() {
042: return rotation;
043: }
044:
045: /**
046: * Returns the shape to be used to render the mark
047: *
048: */
049: public Shape getShape() {
050: return shape;
051: }
052:
053: /**
054: * Returns a shape that can be used to draw the mark at the x, y coordinates
055: * with appropriated rotation and size (according to the current style)
056: *
057: * @param x the x coordinate where the mark will be drawn
058: * @param y the y coordinate where the mark will be drawn
059: *
060: * @return a shape that can be used to draw the mark
061: */
062: public Shape getTransformedShape(float x, float y) {
063: if (shape != null) {
064: Rectangle2D bounds = shape.getBounds2D();
065: double shapeSize = Math.max(bounds.getWidth(), bounds
066: .getHeight());
067: double scale = size / shapeSize;
068: TransformedShape ts = new TransformedShape();
069: ts.shape = shape;
070: ts.translate(x, y);
071: ts.rotate(rotation);
072: ts.scale(scale, -scale);
073:
074: return ts;
075: } else {
076: return null;
077: }
078: }
079:
080: /**
081: * Returns the size of the shape, in pixels
082: *
083: */
084: public int getSize() {
085: return size;
086: }
087:
088: /**
089: * Sets the shape rotation, in radians
090: *
091: * @param f
092: */
093: public void setRotation(float f) {
094: rotation = f;
095: }
096:
097: /**
098: * Sets the shape to be used to render the mark
099: *
100: * @param shape
101: */
102: public void setShape(Shape shape) {
103: this .shape = shape;
104: }
105:
106: /**
107: * Sets the size of the shape, in pixels
108: *
109: * @param i
110: */
111: public void setSize(int i) {
112: size = i;
113: }
114:
115: /**
116: * Returns a string representation of this style.
117: */
118: public String toString() {
119: return Utilities.getShortClassName(this ) + '[' + shape + ']';
120: }
121: }
|