001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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.lite;
017:
018: import java.awt.Shape;
019: import java.awt.geom.AffineTransform;
020: import java.awt.geom.GeneralPath;
021: import java.awt.geom.Rectangle2D.Double;
022: import java.util.logging.Logger;
023:
024: /**
025: * Utility class used to get 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/lite/Java2DMark.java $
029: * @version $Id: Java2DMark.java 27862 2007-11-12 19:51:19Z desruisseaux $
030: */
031: 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:
036: /** Cross general path */
037: private static GeneralPath cross;
038:
039: /** Star general path */
040: private static GeneralPath star;
041:
042: /** Triangle general path */
043: private static GeneralPath triangle;
044:
045: /** Arrow general path */
046: private static GeneralPath arrow;
047:
048: /** X general path */
049: private static Shape X;
050:
051: /** hatch path */
052: static GeneralPath hatch;
053:
054: static {
055: cross = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
056: cross.moveTo(0.5f, 0.125f);
057: cross.lineTo(0.125f, 0.125f);
058: cross.lineTo(0.125f, 0.5f);
059: cross.lineTo(-0.125f, 0.5f);
060: cross.lineTo(-0.125f, 0.125f);
061: cross.lineTo(-0.5f, 0.125f);
062: cross.lineTo(-0.5f, -0.125f);
063: cross.lineTo(-0.125f, -0.125f);
064: cross.lineTo(-0.125f, -0.5f);
065: cross.lineTo(0.125f, -0.5f);
066: cross.lineTo(0.125f, -0.125f);
067: cross.lineTo(0.5f, -0.125f);
068: cross.lineTo(0.5f, 0.125f);
069:
070: AffineTransform at = new AffineTransform();
071: at.rotate(Math.PI / 4.0);
072: X = cross.createTransformedShape(at);
073: star = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
074: star.moveTo(0.191f, 0.0f);
075: star.lineTo(0.25f, 0.344f);
076: star.lineTo(0.0f, 0.588f);
077: star.lineTo(0.346f, 0.638f);
078: star.lineTo(0.5f, 0.951f);
079: star.lineTo(0.654f, 0.638f);
080: star.lineTo(1.0f, 0.588f); // max = 7.887
081: star.lineTo(0.75f, 0.344f);
082: star.lineTo(0.89f, 0f);
083: star.lineTo(0.5f, 0.162f);
084: star.lineTo(0.191f, 0.0f);
085: at = new AffineTransform();
086: at.translate(-.5, -.5);
087: star.transform(at);
088: triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
089: triangle.moveTo(0f, 1f);
090: triangle.lineTo(0.866f, -.5f);
091: triangle.lineTo(-0.866f, -.5f);
092: triangle.lineTo(0f, 1f);
093: at = new AffineTransform();
094:
095: at.translate(0, -.25);
096: at.scale(.5, .5);
097:
098: triangle.transform(at);
099:
100: arrow = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
101: arrow.moveTo(0f, -.5f);
102: arrow.lineTo(.5f, 0f);
103: arrow.lineTo(0f, .5f);
104: arrow.lineTo(0f, .1f);
105: arrow.lineTo(-.5f, .1f);
106: arrow.lineTo(-.5f, -.1f);
107: arrow.lineTo(0f, -.1f);
108: arrow.lineTo(0f, -.5f);
109:
110: hatch = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
111: hatch.moveTo(.55f, .57f);
112: hatch.lineTo(.52f, .57f);
113: hatch.lineTo(-.57f, -.52f);
114: hatch.lineTo(-.57f, -.57f);
115: hatch.lineTo(-.52f, -.57f);
116: hatch.lineTo(.57f, .52f);
117: hatch.lineTo(.57f, .57f);
118:
119: hatch.moveTo(.57f, -.49f);
120: hatch.lineTo(.49f, -.57f);
121: hatch.lineTo(.57f, -.57f);
122: hatch.lineTo(.57f, -.49f);
123:
124: hatch.moveTo(-.57f, .5f);
125: hatch.lineTo(-.5f, .57f);
126: hatch.lineTo(-.57f, .57f);
127: hatch.lineTo(-.57f, .5f);
128: }
129:
130: /**
131: * Java2DMark is an utility class, instantiation is not allowed
132: */
133: private Java2DMark() {
134: }
135:
136: /**
137: * Returns the shape representing the well known name passed
138: *
139: * @param wellKnownName the name of a well known shape
140: *
141: * @return the shape representing the well known name passed
142: */
143: public static Shape getWellKnownMark(String wellKnownName) {
144: LOGGER.finer("fetching mark of name " + wellKnownName);
145:
146: if (wellKnownName.equalsIgnoreCase("cross")) {
147: LOGGER.finer("returning cross");
148:
149: return cross;
150: }
151:
152: if (wellKnownName.equalsIgnoreCase("circle")) {
153: LOGGER.finer("returning circle");
154:
155: return new java.awt.geom.Ellipse2D.Double(-.5, -.5, 1., 1.);
156: }
157:
158: if (wellKnownName.equalsIgnoreCase("triangle")) {
159: LOGGER.finer("returning triangle");
160:
161: return triangle;
162: }
163:
164: if (wellKnownName.equalsIgnoreCase("X")) {
165: LOGGER.finer("returning X");
166:
167: return X;
168: }
169:
170: if (wellKnownName.equalsIgnoreCase("star")) {
171: LOGGER.finer("returning star");
172:
173: return star;
174: }
175:
176: if (wellKnownName.equalsIgnoreCase("arrow")) {
177: LOGGER.finer("returning arrow");
178:
179: return arrow;
180: }
181:
182: if (wellKnownName.equalsIgnoreCase("hatch")) {
183: LOGGER.finer("returning hatch");
184:
185: return hatch;
186: }
187:
188: // failing that return a square?
189: LOGGER.finer("returning square");
190:
191: return new Double(-.5, -.5, 1., 1.);
192: }
193: }
|