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.AddVertexOnEdgeBehaviour;
035: import net.refractions.udig.tools.edit.behaviour.AddVertexWhileCreatingBehaviour;
036: import net.refractions.udig.tools.edit.behaviour.CursorControlBehaviour;
037: import net.refractions.udig.tools.edit.behaviour.DefaultCancelBehaviour;
038: import net.refractions.udig.tools.edit.behaviour.DoubleClickRunAcceptBehaviour;
039: import net.refractions.udig.tools.edit.behaviour.DrawCreateVertexSnapAreaBehaviour;
040: import net.refractions.udig.tools.edit.behaviour.ExtendLineBehaviour;
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:
054: import org.eclipse.swt.SWT;
055: import org.geotools.filter.FilterType;
056:
057: import com.vividsolutions.jts.geom.Geometry;
058: import com.vividsolutions.jts.geom.LineString;
059: import com.vividsolutions.jts.geom.LinearRing;
060: import com.vividsolutions.jts.geom.MultiLineString;
061:
062: /**
063: * Creates and edits lines
064: * @author jones
065: * @since 1.1.0
066: */
067: public class LineTool extends AbstractEditTool {
068:
069: @Override
070: protected void initActivators(Set<Activator> activators) {
071: activators.add(new EditStateListenerActivator());
072: activators.add(new DeleteGlobalActionSetterActivator());
073: activators.add(new DrawGeomsActivator(
074: DrawGeomsActivator.DrawType.LINE));
075: activators.add(new DrawCurrentGeomVerticesActivator());
076: activators.add(new SetSnapBehaviourCommandHandlerActivator());
077: activators.add(new AdvancedBehaviourCommandHandlerActivator());
078: activators.add(new SetRenderingFilter());
079: activators.add(new GridActivator());
080: }
081:
082: @Override
083: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
084: acceptBehaviours
085: .add(new WriteChangesBehaviour(LineString.class));
086: }
087:
088: @Override
089: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
090: cancelBehaviours.add(new DefaultCancelBehaviour());
091: }
092:
093: @Override
094: protected void initEventBehaviours(
095: EditToolConfigurationHelper helper) {
096: helper.add(new DrawCreateVertexSnapAreaBehaviour());
097:
098: helper.startAdvancedFeatures();
099: helper.add(new CursorControlBehaviour(handler,
100: new ConditionalProvider(handler,
101: Messages.LineTool_select_or_create_feature,
102: Messages.LineTool_add_vertex_or_finish),
103: new CursorControlBehaviour.SystemCursorProvider(
104: SWT.CURSOR_SIZEALL), new ConditionalProvider(
105: handler, Messages.LineTool_move_vertex, null),
106: new CursorControlBehaviour.SystemCursorProvider(
107: SWT.CURSOR_CROSS), new ConditionalProvider(
108: handler, Messages.LineTool_add_vertex, null)));
109: helper.stopAdvancedFeatures();
110:
111: // vertex selection OR geometry selection should not both happen so make them a mutual exclusion behaviour
112: helper.startMutualExclusiveList();
113:
114: helper.add(new AddVertexWhileCreatingBehaviour());
115:
116: helper.startAdvancedFeatures();
117: helper.add(new MouseDownVertexSelectorBehaviour());
118: helper.add(new VertexSelectorBehaviour());
119: helper.stopAdvancedFeatures();
120:
121: helper.startAdvancedFeatures();
122: SelectGeometryBehaviour selectGeometryBehaviour = new SelectGeometryBehaviour(
123: new Class[] { LineString.class, LinearRing.class,
124: MultiLineString.class },
125: FilterType.GEOMETRY_INTERSECTS);
126: selectGeometryBehaviour
127: .setCreateGeomOnNoneSelect(ShapeType.LINE);
128: helper.add(selectGeometryBehaviour);
129: helper.add(new AddVertexOnEdgeBehaviour());
130:
131: helper.startElseFeatures();
132: helper.add(new StartEditingBehaviour(ShapeType.LINE));
133: helper.stopElseFeatures();
134:
135: helper.stopAdvancedFeatures();
136: helper.stopMutualExclusiveList();
137:
138: helper.startAdvancedFeatures();
139: helper.startMutualExclusiveList();
140: helper.add(new MoveVertexBehaviour());
141: helper.add(new MoveGeometryBehaviour());
142: helper.stopMutualExclusiveList();
143:
144: helper.add(new SelectionBoxBehaviour());
145: helper.stopAdvancedFeatures();
146: helper.add(new DoubleClickRunAcceptBehaviour());
147: helper.add(new SetSnapSizeBehaviour());
148: helper.add(new ExtendLineBehaviour());
149: helper.done();
150: }
151:
152: @Override
153: protected void initEnablementBehaviours(
154: List<EnablementBehaviour> helper) {
155: helper.add(new WithinLegalLayerBoundsBehaviour());
156: helper.add(new ValidToolDetectionActivator(
157: new Class[] { Geometry.class, LineString.class,
158: MultiLineString.class }));
159: }
160:
161: @Override
162: protected String getExtensionID() {
163: return "net.refractions.udig.tools.lineEdit"; //$NON-NLS-1$
164: }
165:
166: }
|