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;
034:
035: import java.util.ArrayList;
036: import java.util.Collection;
037: import java.util.Iterator;
038: import java.util.List;
039:
040: import com.vividsolutions.jts.geom.Geometry;
041: import com.vividsolutions.jts.geom.GeometryCollection;
042: import com.vividsolutions.jts.geom.LineString;
043: import com.vividsolutions.jts.util.Assert;
044: import com.vividsolutions.jump.feature.Feature;
045: import com.vividsolutions.jump.workbench.model.Layer;
046: import com.vividsolutions.jump.workbench.ui.renderer.PartSelectionRenderer;
047:
048: /**
049: * A collection of selected {@link Geometry} objects (parts of larger
050: * selections).
051: */
052:
053: public class PartSelection extends AbstractSelection {
054:
055: public List items(Geometry geometry) {
056: ArrayList items = new ArrayList();
057:
058: if (geometry instanceof GeometryCollection) {
059: for (int i = 0; i < ((GeometryCollection) geometry)
060: .getNumGeometries(); i++) {
061: items.addAll(items(((GeometryCollection) geometry)
062: .getGeometryN(i)));
063: }
064: } else {
065: items.add(geometry);
066: }
067: return items;
068: }
069:
070: public PartSelection(SelectionManager selectionManager) {
071: super (selectionManager);
072: }
073:
074: public String getRendererContentID() {
075: return PartSelectionRenderer.CONTENT_ID;
076: }
077:
078: protected boolean selectedInAncestors(Layer layer, Feature feature,
079: Geometry item) {
080: Assert.isTrue(getParent() instanceof FeatureSelection);
081: return getParent().getFeaturesWithSelectedItems().contains(
082: feature);
083: }
084:
085: protected void unselectInDescendants(Layer layer, Feature feature,
086: Collection items) {
087: Assert.isTrue(getChild() instanceof LineStringSelection);
088: for (Iterator i = items.iterator(); i.hasNext();) {
089: Geometry part = (Geometry) i.next();
090: List partLineStrings = getChild().items(part);
091: for (Iterator j = getChild().getSelectedItems(layer,
092: feature).iterator(); j.hasNext();) {
093: LineString selectedLineString = (LineString) j.next();
094: if (partLineStrings.contains(selectedLineString)) {
095: getChild()
096: .unselectItem(
097: layer,
098: feature,
099: partLineStrings
100: .indexOf(selectedLineString));
101: }
102: }
103: }
104: }
105:
106: }
|