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.Color;
036: import java.awt.Graphics2D;
037: import java.awt.Image;
038: import java.awt.geom.Point2D;
039:
040: import javax.swing.Icon;
041:
042: import com.vividsolutions.jts.geom.Coordinate;
043: import com.vividsolutions.jts.geom.Geometry;
044: import com.vividsolutions.jts.util.Assert;
045: import com.vividsolutions.jump.feature.Feature;
046: import com.vividsolutions.jump.workbench.model.Layer;
047: import com.vividsolutions.jump.workbench.ui.Viewport;
048: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
049:
050: public class PinEqualCoordinatesStyle implements Style {
051: public boolean isEnabled() {
052: return enabled;
053: }
054:
055: public void initialize(Layer layer) {
056: }
057:
058: public Object clone() {
059: try {
060: return super .clone();
061: } catch (CloneNotSupportedException e) {
062: Assert.shouldNeverReachHere();
063:
064: return null;
065: }
066: }
067:
068: public void paint(Feature f, Graphics2D g, Viewport viewport)
069: throws Exception {
070: paintGeometry(f.getGeometry(), g, viewport);
071: }
072:
073: public void setEnabled(boolean enabled) {
074: this .enabled = enabled;
075: }
076:
077: private boolean enabled = true;
078:
079: /**
080: * Parameterless constructor for Java2XML persistence. [Jon Aquino]
081: */
082: public PinEqualCoordinatesStyle() {
083: this (Color.black);
084: }
085:
086: public PinEqualCoordinatesStyle(Color color) {
087: setColor(color);
088: }
089:
090: private Color color;
091:
092: protected void paintGeometry(Geometry geometry,
093: Graphics2D graphics, Viewport viewport) throws Exception {
094: if (geometry.isEmpty()) {
095: return;
096: }
097: if (!coordinatesEqual(geometry)) {
098: return;
099: }
100: graphics.setColor(color);
101: Point2D viewCentre = viewport.toViewPoint(geometry
102: .getCoordinate());
103: graphics.drawImage(image, (int) viewCentre.getX() - 9,
104: (int) viewCentre.getY() - 19, null);
105: }
106:
107: private static Image image = IconLoader
108: .icon("GreenPinPushedIn.gif").getImage();
109:
110: public static boolean coordinatesEqual(Geometry geometry) {
111: //Coordinates may be expensive to build (e.g. GeometryCollections) ,
112: //so build it once. [Jon Aquino]
113: Coordinate[] coordinates = geometry.getCoordinates();
114: for (int i = 1; i < coordinates.length; i++) {
115: if (!coordinates[i].equals(coordinates[0])) {
116: return false;
117: }
118: }
119: return true;
120: }
121:
122: public Color getColor() {
123: return color;
124: }
125:
126: public void setColor(Color color) {
127: this.color = color;
128: }
129:
130: }
|