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: * JUMP is Copyright (C) 2003 Vivid Solutions
006: *
007: * This program implements extensions to JUMP and is
008: * Copyright (C) 2004 Integrated Systems Analysts, Inc.
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU General Public License for more details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
023: *
024: * For more information, contact:
025: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida
029: * USA
030: *
031: * (850)862-7321
032: */
033:
034: package org.openjump.core.ui.plugin.edittoolbox.cursortools;
035:
036: import java.awt.geom.NoninvertibleTransformException;
037: import java.util.Collection;
038: import java.util.Iterator;
039: import java.util.List;
040:
041: import javax.swing.Icon;
042: import javax.swing.ImageIcon;
043:
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.ui.LayerViewPanel;
048: import com.vividsolutions.jump.workbench.ui.cursortool.SelectTool;
049: import com.vividsolutions.jump.workbench.ui.renderer.FeatureSelectionRenderer;
050:
051: public class SelectOneItemTool extends SelectTool {
052:
053: final static String sSelectOneItem = I18N
054: .get("org.openjump.core.ui.plugin.edittoolbox.cursortools.SelectOneItemTool.Select-One-Item");
055:
056: private LayerViewPanel layerViewPanel;
057: private int maxFID = 2147483647;
058: private int highFID = 0;
059: Layer botLayer = null;
060: Feature botFeature = null;
061: boolean featureSelected = false;
062:
063: public SelectOneItemTool() {
064: super (FeatureSelectionRenderer.CONTENT_ID);
065: }
066:
067: public Icon getIcon() {
068: return new ImageIcon(getClass().getResource("SelectOne.gif"));
069: }
070:
071: public String getName() {
072: return sSelectOneItem;
073: }
074:
075: private void reset() {
076: maxFID = 2147483647;
077: highFID = 0;
078: botLayer = null;
079: botFeature = null;
080: featureSelected = false;
081: }
082:
083: public void activate(LayerViewPanel layerViewPanel) {
084: this .layerViewPanel = layerViewPanel;
085: super .activate(layerViewPanel);
086: selection = layerViewPanel.getSelectionManager()
087: .getFeatureSelection();
088: reset();
089: }
090:
091: protected void gestureFinished()
092: throws NoninvertibleTransformException {
093: super .gestureFinished();
094: List layerList = layerViewPanel.getLayerManager()
095: .getVisibleLayers(false);
096: Layer topLayer = null;
097: Feature topFeature = null;
098: featureSelected = false;
099:
100: for (Iterator i = layerList.iterator(); i.hasNext();) {
101: Layer layer = (Layer) i.next();
102: Collection selectedFeatures = layerViewPanel
103: .getSelectionManager()
104: .getFeaturesWithSelectedItems(layer);
105:
106: for (Iterator j = selectedFeatures.iterator(); j.hasNext();) {
107: featureSelected = true;
108: Feature feature = (Feature) j.next();
109: int fID = feature.getID();
110: layerViewPanel.getSelectionManager()
111: .getFeatureSelection().unselectItems(layer,
112: feature);
113: if ((fID > highFID) && (fID < maxFID)) {
114: topLayer = layer;
115: topFeature = feature;
116: highFID = fID;
117: }
118: }
119: }
120:
121: if (!featureSelected)
122: reset();
123:
124: if ((topLayer != null) && (topFeature != null)) {
125: if (highFID > 0)
126: maxFID = highFID;
127: highFID = 0;
128: botLayer = topLayer;
129: botFeature = topFeature;
130: layerViewPanel.getSelectionManager().getFeatureSelection()
131: .selectItems(topLayer, topFeature);
132: } else if ((botLayer != null) && (botFeature != null)) {
133: layerViewPanel.getSelectionManager().getFeatureSelection()
134: .selectItems(botLayer, botFeature);
135: }
136: }
137: }
|