001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.tools.edit.impl;
016:
017: import java.util.List;
018: import java.util.Set;
019:
020: import net.refractions.udig.tool.edit.internal.Messages;
021: import net.refractions.udig.tools.edit.AbstractEditTool;
022: import net.refractions.udig.tools.edit.Activator;
023: import net.refractions.udig.tools.edit.Behaviour;
024: import net.refractions.udig.tools.edit.EditToolConfigurationHelper;
025: import net.refractions.udig.tools.edit.EnablementBehaviour;
026: import net.refractions.udig.tools.edit.activator.AdvancedBehaviourCommandHandlerActivator;
027: import net.refractions.udig.tools.edit.activator.DeleteGlobalActionSetterActivator;
028: import net.refractions.udig.tools.edit.activator.DrawCurrentGeomVerticesActivator;
029: import net.refractions.udig.tools.edit.activator.DrawGeomsActivator;
030: import net.refractions.udig.tools.edit.activator.EditStateListenerActivator;
031: import net.refractions.udig.tools.edit.activator.GridActivator;
032: import net.refractions.udig.tools.edit.activator.SetRenderingFilter;
033: import net.refractions.udig.tools.edit.activator.SetSnapBehaviourCommandHandlerActivator;
034: import net.refractions.udig.tools.edit.behaviour.AcceptWhenOverFirstVertexBehaviour;
035: import net.refractions.udig.tools.edit.behaviour.AddVertexOnEdgeBehaviour;
036: import net.refractions.udig.tools.edit.behaviour.AddVertexWhileCreatingBehaviour;
037: import net.refractions.udig.tools.edit.behaviour.CursorControlBehaviour;
038: import net.refractions.udig.tools.edit.behaviour.DefaultCancelBehaviour;
039: import net.refractions.udig.tools.edit.behaviour.DoubleClickRunAcceptBehaviour;
040: import net.refractions.udig.tools.edit.behaviour.DrawCreateVertexSnapAreaBehaviour;
041: import net.refractions.udig.tools.edit.behaviour.MouseDownVertexSelectorBehaviour;
042: import net.refractions.udig.tools.edit.behaviour.MoveGeometryBehaviour;
043: import net.refractions.udig.tools.edit.behaviour.MoveVertexBehaviour;
044: import net.refractions.udig.tools.edit.behaviour.SelectGeometryBehaviour;
045: import net.refractions.udig.tools.edit.behaviour.SelectionBoxBehaviour;
046: import net.refractions.udig.tools.edit.behaviour.SetSnapSizeBehaviour;
047: import net.refractions.udig.tools.edit.behaviour.StartEditingBehaviour;
048: import net.refractions.udig.tools.edit.behaviour.VertexSelectorBehaviour;
049: import net.refractions.udig.tools.edit.behaviour.WriteChangesBehaviour;
050: import net.refractions.udig.tools.edit.enablement.ValidToolDetectionActivator;
051: import net.refractions.udig.tools.edit.enablement.WithinLegalLayerBoundsBehaviour;
052: import net.refractions.udig.tools.edit.support.ShapeType;
053: import net.refractions.udig.tools.edit.validator.PolygonCreationValidator;
054:
055: import org.eclipse.swt.SWT;
056: import org.geotools.filter.FilterType;
057:
058: import com.vividsolutions.jts.geom.Geometry;
059: import com.vividsolutions.jts.geom.MultiPolygon;
060: import com.vividsolutions.jts.geom.Polygon;
061:
062: /**
063: * Creates and edits Polygons
064: *
065: * @author Jesse
066: * @since 1.1.0
067: */
068: public class PolygonTool extends AbstractEditTool {
069:
070: @Override
071: protected String getExtensionID() {
072: return "net.refractions.udig.tools.polygonEdit"; //$NON-NLS-1$
073: }
074:
075: @Override
076: protected void initEnablementBehaviours(
077: List<EnablementBehaviour> helper) {
078: helper.add(new WithinLegalLayerBoundsBehaviour());
079: helper.add(new ValidToolDetectionActivator(new Class[] {
080: Geometry.class, Polygon.class, MultiPolygon.class }));
081: }
082:
083: @Override
084: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
085: cancelBehaviours.add(new DefaultCancelBehaviour());
086: }
087:
088: @Override
089: protected void initEventBehaviours(
090: EditToolConfigurationHelper helper) {
091: helper.add(new DrawCreateVertexSnapAreaBehaviour());
092: helper.startAdvancedFeatures();
093: helper
094: .add(new CursorControlBehaviour(
095: handler,
096: new ConditionalProvider(
097: handler,
098: Messages.PolygonTool_add_vertex_or_finish,
099: Messages.PolygonTool_create_feature),
100: new CursorControlBehaviour.SystemCursorProvider(
101: SWT.CURSOR_SIZEALL),
102: new ConditionalProvider(handler,
103: Messages.PolygonTool_move_vertex, null),
104: new CursorControlBehaviour.SystemCursorProvider(
105: SWT.CURSOR_CROSS),
106: new ConditionalProvider(handler,
107: Messages.PolygonTool_add_vertex, null)));
108: helper.stopAdvancedFeatures();
109: // vertex selection OR geometry selection should not both happen so make them a mutual exclusion behaviour
110: helper.startMutualExclusiveList();
111: helper.startOrderedList(false);
112: AddVertexWhileCreatingBehaviour addVertexWhileCreatingBehaviour = new AddVertexWhileCreatingBehaviour();
113: addVertexWhileCreatingBehaviour
114: .setEditValidator(new PolygonCreationValidator());
115: helper.add(addVertexWhileCreatingBehaviour);
116: helper.add(new AcceptWhenOverFirstVertexBehaviour());
117: helper.stopOrderedList();
118: helper.startAdvancedFeatures();
119: helper.add(new MouseDownVertexSelectorBehaviour());
120: helper.add(new VertexSelectorBehaviour());
121: helper.stopAdvancedFeatures();
122:
123: helper.startAdvancedFeatures();
124: SelectGeometryBehaviour selectGeometryBehaviour = new SelectGeometryBehaviour(
125: new Class[] { Polygon.class, MultiPolygon.class },
126: FilterType.GEOMETRY_INTERSECTS);
127: selectGeometryBehaviour
128: .setCreateGeomOnNoneSelect(ShapeType.POLYGON);
129: helper.add(selectGeometryBehaviour);
130: helper.add(new AddVertexOnEdgeBehaviour());
131:
132: helper.startElseFeatures();
133: helper.add(new StartEditingBehaviour(ShapeType.POLYGON));
134: helper.stopElseFeatures();
135:
136: helper.stopAdvancedFeatures();
137: helper.stopMutualExclusiveList();
138:
139: helper.startAdvancedFeatures();
140: helper.startMutualExclusiveList();
141: helper.add(new MoveVertexBehaviour());
142: helper.add(new MoveGeometryBehaviour());
143: helper.stopMutualExclusiveList();
144:
145: helper.add(new SelectionBoxBehaviour());
146: helper.stopAdvancedFeatures();
147: helper.add(new DoubleClickRunAcceptBehaviour());
148: helper.add(new SetSnapSizeBehaviour());
149: helper.done();
150:
151: }
152:
153: @Override
154: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
155: acceptBehaviours.add(new WriteChangesBehaviour(Polygon.class));
156: }
157:
158: @Override
159: protected void initActivators(Set<Activator> activators) {
160: activators.add(new EditStateListenerActivator());
161: activators.add(new DeleteGlobalActionSetterActivator());
162: activators.add(new DrawCurrentGeomVerticesActivator());
163: activators.add(new DrawGeomsActivator(
164: DrawGeomsActivator.DrawType.POLYGON));
165: activators.add(new SetSnapBehaviourCommandHandlerActivator());
166: activators.add(new AdvancedBehaviourCommandHandlerActivator());
167: activators.add(new SetRenderingFilter());
168: activators.add(new GridActivator());
169: }
170:
171: }
|