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.DeleteGlobalActionSetterActivator;
027: import net.refractions.udig.tools.edit.activator.DrawCurrentGeomVerticesActivator;
028: import net.refractions.udig.tools.edit.activator.DrawGeomsActivator;
029: import net.refractions.udig.tools.edit.activator.EditStateListenerActivator;
030: import net.refractions.udig.tools.edit.activator.GridActivator;
031: import net.refractions.udig.tools.edit.activator.SetRenderingFilter;
032: import net.refractions.udig.tools.edit.activator.SetSnapBehaviourCommandHandlerActivator;
033: import net.refractions.udig.tools.edit.behaviour.AcceptWhenOverFirstVertexBehaviour;
034: import net.refractions.udig.tools.edit.behaviour.AddVertexWhileCreatingBehaviour;
035: import net.refractions.udig.tools.edit.behaviour.CursorControlBehaviour;
036: import net.refractions.udig.tools.edit.behaviour.DefaultCancelBehaviour;
037: import net.refractions.udig.tools.edit.behaviour.DoubleClickRunAcceptBehaviour;
038: import net.refractions.udig.tools.edit.behaviour.SelectGeometryBehaviour;
039: import net.refractions.udig.tools.edit.behaviour.SetSnapSizeBehaviour;
040: import net.refractions.udig.tools.edit.behaviour.StartHoleCuttingBehaviour;
041: import net.refractions.udig.tools.edit.behaviour.WriteChangesBehaviour;
042: import net.refractions.udig.tools.edit.enablement.ValidToolDetectionActivator;
043: import net.refractions.udig.tools.edit.enablement.WithinLegalLayerBoundsBehaviour;
044: import net.refractions.udig.tools.edit.validator.ValidHoleValidator;
045:
046: import org.eclipse.swt.SWT;
047: import org.geotools.filter.FilterType;
048:
049: import com.vividsolutions.jts.geom.Geometry;
050: import com.vividsolutions.jts.geom.MultiPolygon;
051: import com.vividsolutions.jts.geom.Polygon;
052:
053: /**
054: * Edits and creates holes in Polygons
055: * @author jones
056: * @since 1.1.0
057: */
058: public class HoleTool extends AbstractEditTool {
059:
060: @Override
061: protected void initActivators(Set<Activator> activators) {
062: activators.add(new EditStateListenerActivator());
063: activators.add(new DeleteGlobalActionSetterActivator());
064: activators.add(new DrawGeomsActivator(
065: DrawGeomsActivator.DrawType.POLYGON));
066: activators.add(new DrawCurrentGeomVerticesActivator());
067: activators.add(new SetRenderingFilter());
068: activators.add(new SetSnapBehaviourCommandHandlerActivator());
069: activators.add(new GridActivator());
070: }
071:
072: @Override
073: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
074: acceptBehaviours.add(new WriteChangesBehaviour(Polygon.class));
075: }
076:
077: @Override
078: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
079: cancelBehaviours.add(new DefaultCancelBehaviour());
080: }
081:
082: @Override
083: protected void initEventBehaviours(
084: EditToolConfigurationHelper helper) {
085: helper.add(new CursorControlBehaviour(handler,
086: new ConditionalProvider(handler,
087: Messages.HoleTool_create_feature,
088: Messages.HoleTool_add_vertex_or_finish),
089: new CursorControlBehaviour.SystemCursorProvider(
090: SWT.CURSOR_SIZEALL), new ConditionalProvider(
091: handler, Messages.HoleTool_move_vertex, null),
092: new CursorControlBehaviour.SystemCursorProvider(
093: SWT.CURSOR_CROSS), new ConditionalProvider(
094: handler, Messages.HoleTool_add_vertex, null)));
095:
096: helper.startMutualExclusiveList();
097: helper.startOrderedList(false);
098: AddVertexWhileCreatingBehaviour addVertexWhileCreatingBehaviour = new AddVertexWhileCreatingBehaviour();
099: addVertexWhileCreatingBehaviour
100: .setEditValidator(new ValidHoleValidator());
101: helper.add(addVertexWhileCreatingBehaviour);
102: helper.add(new AcceptWhenOverFirstVertexBehaviour());
103: helper.stopOrderedList();
104: helper.startOrderedList(true);
105: // behaviours that select the geometry and hole
106: helper.add(new SelectGeometryBehaviour(new Class[] {
107: Polygon.class, MultiPolygon.class },
108: FilterType.GEOMETRY_BBOX));
109: helper.add(new StartHoleCuttingBehaviour());
110: helper.stopOrderedList();
111: helper.stopMutualExclusiveList();
112:
113: helper.add(new SetSnapSizeBehaviour());
114: helper.add(new DoubleClickRunAcceptBehaviour());
115: helper.done();
116: }
117:
118: @Override
119: protected String getExtensionID() {
120: return "net.refractions.udig.tools.holeEdit"; //$NON-NLS-1$
121: }
122:
123: @Override
124: protected void initEnablementBehaviours(
125: List<EnablementBehaviour> helper) {
126: helper.add(new WithinLegalLayerBoundsBehaviour());
127: helper.add(new ValidToolDetectionActivator(new Class[] {
128: Geometry.class, Polygon.class, MultiPolygon.class }));
129: }
130:
131: }
|