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.tools.edit.AbstractEditTool;
021: import net.refractions.udig.tools.edit.Activator;
022: import net.refractions.udig.tools.edit.Behaviour;
023: import net.refractions.udig.tools.edit.EditToolConfigurationHelper;
024: import net.refractions.udig.tools.edit.EnablementBehaviour;
025: import net.refractions.udig.tools.edit.activator.DrawCurrentGeomVerticesActivator;
026: import net.refractions.udig.tools.edit.activator.DrawGeomsActivator;
027: import net.refractions.udig.tools.edit.activator.EditStateListenerActivator;
028: import net.refractions.udig.tools.edit.activator.GridActivator;
029: import net.refractions.udig.tools.edit.activator.ResetAllStateActivator;
030: import net.refractions.udig.tools.edit.activator.SetRenderingFilter;
031: import net.refractions.udig.tools.edit.activator.SetSnapBehaviourCommandHandlerActivator;
032: import net.refractions.udig.tools.edit.behaviour.AddVertexWhileCreatingBehaviour;
033: import net.refractions.udig.tools.edit.behaviour.DefaultCancelBehaviour;
034: import net.refractions.udig.tools.edit.behaviour.DoubleClickRunAcceptBehaviour;
035: import net.refractions.udig.tools.edit.behaviour.DrawCreateVertexSnapAreaBehaviour;
036: import net.refractions.udig.tools.edit.behaviour.SplitGeometryBehaviour;
037: import net.refractions.udig.tools.edit.behaviour.StartEditingBehaviour;
038: import net.refractions.udig.tools.edit.enablement.ValidToolDetectionActivator;
039: import net.refractions.udig.tools.edit.enablement.WithinLegalLayerBoundsBehaviour;
040: import net.refractions.udig.tools.edit.support.ShapeType;
041:
042: import com.vividsolutions.jts.geom.Geometry;
043: import com.vividsolutions.jts.geom.MultiPolygon;
044: import com.vividsolutions.jts.geom.Polygon;
045:
046: /**
047: * A tool that can split geometries.
048: *
049: * @author jones
050: * @since 1.1.0
051: */
052: public class SplitTool extends AbstractEditTool {
053: @Override
054: protected void initEnablementBehaviours(
055: List<EnablementBehaviour> helper) {
056: helper.add(new WithinLegalLayerBoundsBehaviour());
057: helper.add(new ValidToolDetectionActivator(new Class[] {
058: Geometry.class, Polygon.class, MultiPolygon.class }));
059: }
060:
061: @Override
062: protected void initActivators(Set<Activator> activators) {
063: activators.add(new EditStateListenerActivator());
064: activators.add(new DrawGeomsActivator(
065: DrawGeomsActivator.DrawType.LINE));
066: activators.add(new DrawCurrentGeomVerticesActivator());
067: activators.add(new ResetAllStateActivator());
068: activators.add(new SetSnapBehaviourCommandHandlerActivator());
069: activators.add(new SetRenderingFilter());
070: activators.add(new GridActivator());
071: }
072:
073: @Override
074: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
075: acceptBehaviours.add(new SplitGeometryBehaviour());
076: }
077:
078: @Override
079: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
080: cancelBehaviours.add(new DefaultCancelBehaviour());
081: }
082:
083: @Override
084: protected void initEventBehaviours(
085: EditToolConfigurationHelper helper) {
086: helper.add(new DrawCreateVertexSnapAreaBehaviour());
087: helper.startMutualExclusiveList();
088: helper.add(new AddVertexWhileCreatingBehaviour());
089: //override so that editing will not be started if there are no geometries on the blackboard.
090: helper.add(new StartEditingBehaviour(ShapeType.LINE));
091: helper.stopMutualExclusiveList();
092:
093: helper.add(new DoubleClickRunAcceptBehaviour());
094: helper.done();
095: }
096:
097: @Override
098: protected String getExtensionID() {
099: return "net.refractions.udig.tools.splitTool"; //$NON-NLS-1$
100: }
101:
102: }
|