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.geom.Polygon;
044: import com.vividsolutions.jts.util.Assert;
045: import com.vividsolutions.jump.feature.Feature;
046: import com.vividsolutions.jump.workbench.model.Layer;
047: import com.vividsolutions.jump.workbench.ui.renderer.LineStringSelectionRenderer;
048:
049: /**
050: * A collection of selected {@link LineString LineStrings}.
051: */
052:
053: public class LineStringSelection extends AbstractSelection {
054: public List items(Geometry geometry) {
055: ArrayList items = new ArrayList();
056:
057: if (geometry instanceof LineString) {
058: items.add(geometry);
059: }
060:
061: if (geometry instanceof Polygon) {
062: Polygon polygon = (Polygon) geometry;
063: items.add(polygon.getExteriorRing());
064:
065: for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
066: items.add(polygon.getInteriorRingN(i));
067: }
068: }
069:
070: if (geometry instanceof GeometryCollection) {
071: GeometryCollection geometryCollection = (GeometryCollection) geometry;
072:
073: for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
074: items.addAll(items(geometryCollection.getGeometryN(i)));
075: }
076: }
077:
078: return items;
079: }
080:
081: public LineStringSelection(SelectionManager selectionManager) {
082: super (selectionManager);
083: }
084:
085: public String getRendererContentID() {
086: return LineStringSelectionRenderer.CONTENT_ID;
087: }
088:
089: protected boolean selectedInAncestors(Layer layer, Feature feature,
090: Geometry item) {
091: Assert
092: .isTrue(getParent().getParent() instanceof FeatureSelection);
093: Assert.isTrue(getParent() instanceof PartSelection);
094: if (getParent().getParent().getFeaturesWithSelectedItems()
095: .contains(feature)) {
096: return true;
097: }
098: for (Iterator i = getParent().getSelectedItems(layer, feature)
099: .iterator(); i.hasNext();) {
100: Geometry selectedPart = (Geometry) i.next();
101: if (items(selectedPart).contains(item)) {
102: return true;
103: }
104: }
105: return false;
106: }
107:
108: protected void unselectInDescendants(Layer layer, Feature feature,
109: Collection items) {
110: Assert.isTrue(getChild() == null);
111: }
112:
113: }
|