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.plugin;
034:
035: import java.util.ArrayList;
036: import java.util.Iterator;
037:
038: import com.vividsolutions.jump.I18N;
039: import com.vividsolutions.jump.feature.Feature;
040: import com.vividsolutions.jump.feature.FeatureCollection;
041: import com.vividsolutions.jump.feature.FeatureSchema;
042: import com.vividsolutions.jump.feature.FeatureUtil;
043: import com.vividsolutions.jump.workbench.WorkbenchContext;
044: import com.vividsolutions.jump.workbench.model.Layer;
045: import com.vividsolutions.jump.workbench.model.UndoableCommand;
046: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
047: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
048: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
049: import com.vividsolutions.jump.workbench.ui.EnterWKTDialog;
050:
051: public class AddNewFeaturesPlugIn extends WKTPlugIn {
052: public AddNewFeaturesPlugIn() {
053: }
054:
055: protected Layer layer(PlugInContext context) {
056: return context.getLayerNamePanel().chooseEditableLayer();
057: }
058:
059: public boolean execute(PlugInContext context) throws Exception {
060: reportNothingToUndoYet(context);
061:
062: return super .execute(context);
063: }
064:
065: protected void apply(FeatureCollection c,
066: final PlugInContext context) {
067: //Can't use WeakHashMap, otherwise the features will vanish when the command
068: //is undone! [Jon Aquino]
069: final ArrayList features = new ArrayList();
070:
071: FeatureSchema fs = this .layer.getFeatureCollectionWrapper()
072: .getFeatureSchema();
073:
074: for (Iterator i = c.iterator(); i.hasNext();) {
075: Feature feature = (Feature) i.next();
076: features.add(FeatureUtil.toFeature(feature.getGeometry(),
077: fs));
078: }
079:
080: execute(new UndoableCommand(getName()) {
081: public void execute() {
082: layer.getFeatureCollectionWrapper().addAll(features);
083: }
084:
085: public void unexecute() {
086: layer.getFeatureCollectionWrapper().removeAll(features);
087: }
088: }, context);
089: }
090:
091: protected EnterWKTDialog createDialog(PlugInContext context) {
092: EnterWKTDialog d = super .createDialog(context);
093: d.setTitle(I18N
094: .get("ui.plugin.AddNewFeaturesPlugIn.add-features-to")
095: + " " + layer);
096: d
097: .setDescription("<HTML>"
098: + I18N
099: .get("ui.plugin.AddNewFeaturesPlugIn.enter-well-known-text-for-one-or-more-geometries")
100: + "</HTML>");
101:
102: return d;
103:
104: //<<TODO:DEFECT>> Look at the points drawn. The line and the fill do not line
105: //up perfectly. [Jon Aquino]
106: }
107:
108: public static MultiEnableCheck createEnableCheck(
109: WorkbenchContext workbenchContext) {
110: EnableCheckFactory checkFactory = new EnableCheckFactory(
111: workbenchContext);
112:
113: return new MultiEnableCheck()
114: .add(
115: checkFactory
116: .createWindowWithLayerNamePanelMustBeActiveCheck())
117: .add(
118: checkFactory
119: .createAtLeastNLayersMustBeEditableCheck(1));
120: }
121: }
|