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.cursortool.editing;
034:
035: import java.awt.Shape;
036: import java.awt.geom.NoninvertibleTransformException;
037:
038: import javax.swing.Icon;
039: import javax.swing.JComponent;
040:
041: import com.vividsolutions.jts.geom.Coordinate;
042: import com.vividsolutions.jts.geom.GeometryFactory;
043: import com.vividsolutions.jts.util.Assert;
044: import com.vividsolutions.jump.I18N;
045: import com.vividsolutions.jump.feature.Feature;
046: import com.vividsolutions.jump.workbench.model.Layer;
047: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
048: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
049: import com.vividsolutions.jump.workbench.ui.cursortool.NClickTool;
050:
051: public class SnapVerticesToSelectedVertexClickTool extends NClickTool {
052: private EnableCheckFactory checkFactory;
053: private GeometryFactory factory = new GeometryFactory();
054:
055: public SnapVerticesToSelectedVertexClickTool(
056: EnableCheckFactory checkFactory) {
057: super (1);
058: this .checkFactory = checkFactory;
059: }
060:
061: public Icon getIcon() {
062: Assert.shouldNeverReachHere();
063: return null;
064: }
065:
066: protected void gestureFinished() throws java.lang.Exception {
067: reportNothingToUndoYet();
068: final Coordinate clickCoordinate = (Coordinate) getCoordinates()
069: .get(0);
070: if (!check(checkFactory
071: .createAtLeastNLayersMustBeEditableCheck(1))) {
072: return;
073: }
074: if (!check(checkFactory.createFenceMustBeDrawnCheck())) {
075: return;
076: }
077: if (!check(new EnableCheck() {
078: public String check(JComponent component) {
079: if (!getPanel().getFence().contains(
080: factory.createPoint(clickCoordinate))) {
081: return I18N
082: .get("ui.cursortool.editing.SnapVerticesToSelectedVertexClickTool.please-click-inside-the-fence");
083: }
084: if (getPanel().getSelectionManager().getSelectedItems()
085: .isEmpty()) {
086: return I18N
087: .get("ui.cursortool.editing.SnapVerticesToSelectedVertexClickTool.select-a-feature-part-or-linestring-in-the-fence-containing-the-vertex-to-snap-to");
088: }
089: if (getPanel().getSelectionManager().getSelectedItems()
090: .size() > 1) {
091: return I18N
092: .get("ui.cursortool.editing.SnapVerticesToSelectedVertexClickTool.select-only-one-feature-part-or-linestring-containing-the-vertex-to-snap-to");
093: }
094: return null;
095: }
096: })) {
097: return;
098: }
099: new SnapVerticesOp()
100: .execute(
101: getPanel().getFence(),
102: getPanel().getLayerManager()
103: .getEditableLayers(),
104: isRollingBackInvalidEdits(),
105: getPanel(),
106: getTaskFrame().getTask(),
107: clickCoordinate,
108: (Feature) getPanel()
109: .getSelectionManager()
110: .getFeaturesWithSelectedItems(
111: (Layer) getPanel()
112: .getSelectionManager()
113: .getLayersWithSelectedItems()
114: .iterator().next())
115: .iterator().next(),
116: getWorkbench()
117: .getBlackboard()
118: .get(
119: SnapVerticesOp.INSERT_VERTICES_IF_NECESSARY_KEY,
120: true));
121: }
122:
123: protected Shape getShape() throws NoninvertibleTransformException {
124: return null;
125: }
126:
127: }
|