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.SetSnapBehaviourCommandHandlerActivator;
031: import net.refractions.udig.tools.edit.behaviour.AcceptWhenOverFirstVertexBehaviour;
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.DifferenceFeatureAcceptor;
035: import net.refractions.udig.tools.edit.behaviour.DoubleClickRunAcceptBehaviour;
036: import net.refractions.udig.tools.edit.behaviour.DrawCreateVertexSnapAreaBehaviour;
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.LineString;
044: import com.vividsolutions.jts.geom.MultiLineString;
045: import com.vividsolutions.jts.geom.MultiPolygon;
046: import com.vividsolutions.jts.geom.Polygon;
047:
048: /**
049: * Creates a new Feature by calculating the difference between the current shape and another selected shape.
050: *
051: * @author jones
052: * @since 1.1.0
053: */
054: public class FillDifferenceTool extends AbstractEditTool {
055:
056: @Override
057: protected void initActivators(Set<Activator> activators) {
058: activators.add(new EditStateListenerActivator());
059: activators.add(new DrawGeomsActivator(
060: DrawGeomsActivator.DrawType.LINE));
061: activators.add(new DrawCurrentGeomVerticesActivator());
062: activators.add(new ResetAllStateActivator());
063: activators.add(new SetSnapBehaviourCommandHandlerActivator());
064: activators.add(new GridActivator());
065: }
066:
067: @Override
068: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
069: acceptBehaviours.add(new DifferenceFeatureAcceptor());
070: }
071:
072: @Override
073: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
074: cancelBehaviours.add(new DefaultCancelBehaviour());
075: }
076:
077: @Override
078: protected void initEventBehaviours(
079: EditToolConfigurationHelper helper) {
080: helper.add(new DrawCreateVertexSnapAreaBehaviour());
081: helper.startMutualExclusiveList();
082:
083: helper.startOrderedList(false);
084: helper.add(new AddVertexWhileCreatingBehaviour());
085: helper.add(new AcceptWhenOverFirstVertexBehaviour());
086: helper.stopOrderedList();
087:
088: //override so that editing will not be started if there are no geometries on the blackboard.
089: helper.add(new StartEditingBehaviour(ShapeType.POLYGON));
090: helper.stopMutualExclusiveList();
091:
092: helper.add(new DoubleClickRunAcceptBehaviour());
093: helper.done();
094: }
095:
096: @Override
097: protected String getExtensionID() {
098: return "net.refractions.udig.tools.splitTool"; //$NON-NLS-1$
099: }
100:
101: @Override
102: protected void initEnablementBehaviours(
103: List<EnablementBehaviour> helper) {
104: helper.add(new WithinLegalLayerBoundsBehaviour());
105: helper.add(new ValidToolDetectionActivator(new Class[] {
106: Geometry.class, LineString.class,
107: MultiLineString.class, Polygon.class,
108: MultiPolygon.class }));
109: }
110:
111: }
|