001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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: import java.awt.Shape;
019: import java.awt.geom.AffineTransform;
020: import java.awt.geom.GeneralPath;
021: import java.awt.geom.Rectangle2D;
022: import java.util.logging.Logger;
023:
024: /**
025: * Utility class that will return the Shape for well known marks
026: *
027: * @author Ian Turton
028: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/render/src/main/java/org/geotools/renderer/style/Java2DMark.java $
029: * @version $Id: Java2DMark.java 27862 2007-11-12 19:51:19Z desruisseaux $
030: */
031: public class Java2DMark {
032: /** The logger for the rendering module. */
033: private static final Logger LOGGER = org.geotools.util.logging.Logging
034: .getLogger("org.geotools.rendering");
035: static GeneralPath cross;
036: static GeneralPath star;
037: static GeneralPath triangle;
038: static GeneralPath arrow;
039: static Shape X;
040: static GeneralPath hatch;
041:
042: static {
043: cross = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
044: cross.moveTo(0.5f, 0.125f);
045: cross.lineTo(0.125f, 0.125f);
046: cross.lineTo(0.125f, 0.5f);
047: cross.lineTo(-0.125f, 0.5f);
048: cross.lineTo(-0.125f, 0.125f);
049: cross.lineTo(-0.5f, 0.125f);
050: cross.lineTo(-0.5f, -0.125f);
051: cross.lineTo(-0.125f, -0.125f);
052: cross.lineTo(-0.125f, -0.5f);
053: cross.lineTo(0.125f, -0.5f);
054: cross.lineTo(0.125f, -0.125f);
055: cross.lineTo(0.5f, -0.125f);
056: cross.lineTo(0.5f, 0.125f);
057:
058: AffineTransform at = new AffineTransform();
059: at.rotate(Math.PI / 4.0);
060: X = cross.createTransformedShape(at);
061: star = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
062: star.moveTo(0.191f, 0.0f);
063: star.lineTo(0.25f, 0.344f);
064: star.lineTo(0.0f, 0.588f);
065: star.lineTo(0.346f, 0.638f);
066: star.lineTo(0.5f, 0.951f);
067: star.lineTo(0.654f, 0.638f);
068: star.lineTo(1.0f, 0.588f); // max = 7.887
069: star.lineTo(0.75f, 0.344f);
070: star.lineTo(0.89f, 0f);
071: star.lineTo(0.5f, 0.162f);
072: star.lineTo(0.191f, 0.0f);
073: at = new AffineTransform();
074: at.translate(-.5, -.5);
075: star.transform(at);
076: triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
077: triangle.moveTo(0f, 1f);
078: triangle.lineTo(0.866f, -.5f);
079: triangle.lineTo(-0.866f, -.5f);
080: triangle.lineTo(0f, 1f);
081: at = new AffineTransform();
082:
083: at.translate(0, -.25);
084: at.scale(.5, .5);
085:
086: triangle.transform(at);
087:
088: arrow = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
089: arrow.moveTo(0f, -.5f);
090: arrow.lineTo(.5f, 0f);
091: arrow.lineTo(0f, .5f);
092: arrow.lineTo(0f, .1f);
093: arrow.lineTo(-.5f, .1f);
094: arrow.lineTo(-.5f, -.1f);
095: arrow.lineTo(0f, -.1f);
096: arrow.lineTo(0f, -.5f);
097:
098: hatch = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
099: hatch.moveTo(.55f, .57f);
100: hatch.lineTo(.52f, .57f);
101: hatch.lineTo(-.57f, -.52f);
102: hatch.lineTo(-.57f, -.57f);
103: hatch.lineTo(-.52f, -.57f);
104: hatch.lineTo(.57f, .52f);
105: hatch.lineTo(.57f, .57f);
106:
107: hatch.moveTo(.57f, -.49f);
108: hatch.lineTo(.49f, -.57f);
109: hatch.lineTo(.57f, -.57f);
110: hatch.lineTo(.57f, -.49f);
111:
112: hatch.moveTo(-.57f, .5f);
113: hatch.lineTo(-.5f, .57f);
114: hatch.lineTo(-.57f, .57f);
115: hatch.lineTo(-.57f, .5f);
116:
117: }
118:
119: public static Shape getWellKnownMark(String wellKnownName) {
120: LOGGER.finer("fetching mark of name " + wellKnownName);
121:
122: if (wellKnownName.equalsIgnoreCase("cross")) {
123: LOGGER.finer("returning cross");
124:
125: return cross;
126: }
127:
128: if (wellKnownName.equalsIgnoreCase("circle")) {
129: LOGGER.finer("returning circle");
130:
131: return new java.awt.geom.Ellipse2D.Double(-.5, -.5, 1., 1.);
132: }
133:
134: if (wellKnownName.equalsIgnoreCase("triangle")) {
135: LOGGER.finer("returning triangle");
136:
137: return triangle;
138: }
139:
140: if (wellKnownName.equalsIgnoreCase("X")) {
141: LOGGER.finer("returning X");
142:
143: return X;
144: }
145:
146: if (wellKnownName.equalsIgnoreCase("star")) {
147: LOGGER.finer("returning star");
148:
149: return star;
150: }
151:
152: if (wellKnownName.equalsIgnoreCase("arrow")) {
153: LOGGER.finer("returning arrow");
154:
155: return arrow;
156: }
157:
158: if (wellKnownName.equalsIgnoreCase("hatch")) {
159: LOGGER.finer("returning hatch");
160:
161: return hatch;
162: }
163:
164: // failing that return a square?
165: LOGGER.finer("returning square");
166:
167: return new Rectangle2D.Double(-.5, -.5, 1., 1.);
168: }
169: }
|