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.warp;
034:
035: import java.awt.geom.NoninvertibleTransformException;
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.Iterator;
039:
040: import com.vividsolutions.jts.geom.Envelope;
041: import com.vividsolutions.jts.util.Assert;
042: import com.vividsolutions.jump.feature.Feature;
043: import com.vividsolutions.jump.geom.EnvelopeUtil;
044: import com.vividsolutions.jump.workbench.model.AbstractVectorLayerFinder;
045: import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
046: import com.vividsolutions.jump.workbench.model.UndoableCommand;
047: import com.vividsolutions.jump.workbench.ui.cursortool.Animations;
048: import com.vividsolutions.jump.workbench.ui.cursortool.SpecifyFeaturesTool;
049:
050: public abstract class AbstractDeleteVectorTool extends
051: SpecifyFeaturesTool {
052:
053: public AbstractDeleteVectorTool() {
054: super ();
055: //The cursor is big and the pin icons are big, so make the click buffer big. [Jon Aquino]
056: setViewClickBuffer(6);
057: }
058:
059: private void showAnimation(Collection vectorFeatures) {
060: try {
061: Animations.drawExpandingRings(getPanel().getViewport()
062: .toViewPoints(centres(vectorFeatures)), true,
063: getColor(), getPanel(), new float[] { 15, 15 });
064: } catch (NoninvertibleTransformException e) {
065: //Eat it. [Jon Aquino]
066: }
067: }
068:
069: private Collection centres(Collection vectorFeatures) {
070: ArrayList centers = new ArrayList();
071: for (Iterator i = vectorFeatures.iterator(); i.hasNext();) {
072: Feature vectorFeature = (Feature) i.next();
073: Envelope envelope = vectorFeature.getGeometry()
074: .getEnvelopeInternal();
075: //<<TODO>> Envelope shouldn't be null. Use assert instead of if. [Jon Aquino]
076: if (envelope.isNull()) {
077: continue;
078: }
079: centers.add(EnvelopeUtil.centre(envelope));
080: }
081: return centers;
082: }
083:
084: protected abstract AbstractVectorLayerFinder createVectorLayerFinder(
085: LayerManagerProxy layerManagerProxy);
086:
087: protected void gestureFinished() throws Exception {
088: reportNothingToUndoYet();
089: AbstractVectorLayerFinder finder = createVectorLayerFinder(getPanel());
090: if (finder.getLayer() == null) {
091: return;
092: }
093: if (!layerToSpecifiedFeaturesMap().containsKey(
094: finder.getLayer())) {
095: return;
096: }
097: execute(createCommand());
098: }
099:
100: protected UndoableCommand createCommand()
101: throws NoninvertibleTransformException {
102: final AbstractVectorLayerFinder finder = createVectorLayerFinder(getPanel());
103: final Collection vectorFeaturesToDelete = (Collection) layerToSpecifiedFeaturesMap()
104: .get(finder.getLayer());
105: Assert.isTrue(vectorFeaturesToDelete != null);
106: Assert.isTrue(!vectorFeaturesToDelete.isEmpty());
107: return new UndoableCommand(getName()) {
108: public void execute() {
109: finder.getLayer().getFeatureCollectionWrapper()
110: .removeAll(vectorFeaturesToDelete);
111: showAnimation(vectorFeaturesToDelete);
112: }
113:
114: public void unexecute() {
115: finder.getLayer().getFeatureCollectionWrapper().addAll(
116: vectorFeaturesToDelete);
117: }
118: };
119: }
120:
121: }
|