01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for
03: * visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License as published by the Free Software
09: * Foundation; either version 2 of the License, or (at your option) any later
10: * version.
11: *
12: * This program is distributed in the hope that it will be useful, but WITHOUT
13: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15: * details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19: * Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions Suite #1A 2328 Government Street Victoria BC V8T 5G5 Canada
24: *
25: * (250)385-6040 www.vividsolutions.com
26: */
27: package com.vividsolutions.jump.workbench.ui;
28:
29: import java.util.ArrayList;
30: import java.util.Collection;
31: import java.util.Collections;
32: import java.util.List;
33:
34: import com.vividsolutions.jts.geom.Geometry;
35: import com.vividsolutions.jts.util.Assert;
36: import com.vividsolutions.jump.feature.Feature;
37: import com.vividsolutions.jump.workbench.model.Layer;
38: import com.vividsolutions.jump.workbench.ui.renderer.FeatureSelectionRenderer;
39:
40: /**
41: * A collection of selected {@link Feature Features}
42: */
43: public class FeatureSelection extends AbstractSelection {
44: public List items(Geometry geometry) {
45: ArrayList items = new ArrayList();
46: items.add(geometry);
47: return items;
48: }
49:
50: public FeatureSelection(SelectionManager selectionManager) {
51: super (selectionManager);
52: }
53:
54: public Collection indices(Geometry geometry, Collection items) {
55: //An enhancement to allow selection to work with datasets not stored in
56: //memory. In collaboration with Michael Michaud
57: //[michael.michaud@free.fr].
58: //[Jon Aquino 2004-04-27]
59: Assert.isTrue(items.size() == 1 || items.isEmpty());
60: return items.isEmpty() ? Collections.EMPTY_SET : Collections
61: .singleton(new Integer(0));
62: }
63:
64: public String getRendererContentID() {
65: return FeatureSelectionRenderer.CONTENT_ID;
66: }
67:
68: protected boolean selectedInAncestors(Layer layer, Feature feature,
69: Geometry item) {
70: Assert.isTrue(getParent() == null);
71: return false;
72: }
73:
74: protected void unselectInDescendants(Layer layer, Feature feature,
75: Collection items) {
76: Assert.isTrue(getChild() instanceof PartSelection);
77: Assert
78: .isTrue(getChild().getChild() instanceof LineStringSelection);
79: getChild().unselectItems(layer, feature);
80: getChild().getChild().unselectItems(layer, feature);
81: }
82: }
|