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.Arrays;
036: import java.util.Collection;
037: import java.util.Iterator;
038: import java.util.Map;
039:
040: import com.vividsolutions.jts.geom.Geometry;
041: import com.vividsolutions.jump.workbench.WorkbenchContext;
042: import com.vividsolutions.jump.workbench.model.FenceLayerFinder;
043: import com.vividsolutions.jump.workbench.model.Layer;
044: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
045: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
046: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
047: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
048: import com.vividsolutions.jump.workbench.ui.LayerNamePanel;
049: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
050:
051: public class SelectFeaturesInFencePlugIn extends AbstractPlugIn {
052: public SelectFeaturesInFencePlugIn() {
053: }
054:
055: public boolean execute(PlugInContext context) throws Exception {
056: reportNothingToUndoYet(context);
057: context.getLayerViewPanel().getSelectionManager().clear();
058: execute(context.getLayerViewPanel(), context
059: .getLayerNamePanel(), context.getLayerViewPanel()
060: .getFence(), true, false);
061:
062: return true;
063: }
064:
065: public static void execute(LayerViewPanel layerViewPanel,
066: LayerNamePanel layerNamePanel, Geometry fence,
067: boolean skipUnselectedLayers, boolean mentionModifierHelp) {
068: Collection selectedLayers = Arrays.asList(layerNamePanel
069: .getSelectedLayers());
070: Map layerToFeaturesInFenceMap = layerViewPanel
071: .visibleLayerToFeaturesInFenceMap(fence);
072:
073: for (Iterator i = layerToFeaturesInFenceMap.keySet().iterator(); i
074: .hasNext();) {
075: Layer layer = (Layer) i.next();
076:
077: if (layer == new FenceLayerFinder(layerViewPanel)
078: .getLayer()) {
079: continue;
080: }
081:
082: if (skipUnselectedLayers && !selectedLayers.contains(layer)) {
083: continue;
084: }
085:
086: layerViewPanel.getSelectionManager().getFeatureSelection()
087: .selectItems(
088: layer,
089: (Collection) layerToFeaturesInFenceMap
090: .get(layer));
091: }
092:
093: }
094:
095: public static MultiEnableCheck createEnableCheck(
096: WorkbenchContext workbenchContext) {
097: EnableCheckFactory checkFactory = new EnableCheckFactory(
098: workbenchContext);
099:
100: return new MultiEnableCheck()
101: .add(
102: checkFactory
103: .createWindowWithLayerViewPanelMustBeActiveCheck())
104: .add(checkFactory.createFenceMustBeDrawnCheck())
105: .add(
106: checkFactory
107: .createAtLeastNLayersMustBeSelectedCheck(1));
108: }
109: }
|