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.Shape;
038: import java.awt.geom.Point2D;
039: import java.awt.geom.RectangularShape;
040:
041: import com.vividsolutions.jts.geom.Coordinate;
042: import com.vividsolutions.jts.util.Assert;
043: import com.vividsolutions.jump.feature.Feature;
044: import com.vividsolutions.jump.workbench.model.Layer;
045: import com.vividsolutions.jump.workbench.ui.GUIUtil;
046: import com.vividsolutions.jump.workbench.ui.Viewport;
047:
048: public abstract class VertexStyle implements Style {
049: //UT
050: //protected RectangularShape shape;
051: protected Shape shape;
052:
053: protected int size = 4;
054: private Color fillColor;
055: private boolean enabled = false;
056:
057: //UT
058: private Color strokeColor;
059:
060: protected VertexStyle() {
061: }
062:
063: //UT made RectangularShape shape a Shape
064: protected VertexStyle(Shape shape) {
065: this .shape = shape;
066: }
067:
068: public void setEnabled(boolean enabled) {
069: this .enabled = enabled;
070: }
071:
072: public boolean isEnabled() {
073: return enabled;
074: }
075:
076: public void setSize(int size) {
077: this .size = size;
078: }
079:
080: public int getSize() {
081: return size;
082: }
083:
084: public void initialize(Layer layer) {
085: //Set the vertices' fill color to the layer's line color
086: fillColor = GUIUtil.alphaColor(layer.getBasicStyle()
087: .getFillColor(), layer.getBasicStyle().getAlpha());
088: strokeColor = GUIUtil.alphaColor(layer.getBasicStyle()
089: .getLineColor(), layer.getBasicStyle().getAlpha());
090:
091: }
092:
093: public void paint(Feature f, Graphics2D g, Viewport viewport)
094: throws Exception {
095: Coordinate[] coordinates = f.getGeometry().getCoordinates();
096: g.setColor(fillColor);
097:
098: for (int i = 0; i < coordinates.length; i++) {
099: if (!viewport.getEnvelopeInModelCoordinates().contains(
100: coordinates[i])) {
101: //Otherwise get "sun.dc.pr.PRException: endPath: bad path" exception [Jon Aquino 10/22/2003]
102: continue;
103: }
104: paint(g, viewport.toViewPoint(new Point2D.Double(
105: coordinates[i].x, coordinates[i].y)));
106: }
107: }
108:
109: public void paint(Graphics2D g, Point2D p) {
110: setFrame(p);
111: render(g);
112: }
113:
114: private void setFrame(Point2D p) {
115: //UT
116: /*shape.setFrame(p.getX() - (getSize() / 2d),
117: p.getY() - (getSize() / 2d), getSize(), getSize());*/
118: ((RectangularShape) shape).setFrame(
119: p.getX() - (getSize() / 2d), p.getY()
120: - (getSize() / 2d), getSize(), getSize());
121: }
122:
123: protected void render(Graphics2D g) {
124: //UT was
125: // g.fill(shape);
126:
127: // deeJUMP
128: g.setColor(strokeColor);
129: g.draw(shape);
130: g.setColor(fillColor);
131: g.fill(shape);
132: }
133:
134: public Object clone() {
135: try {
136: return super .clone();
137: } catch (CloneNotSupportedException e) {
138: Assert.shouldNeverReachHere();
139:
140: return null;
141: }
142: }
143: }
|