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.AcceptBehaviour;
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.DrawCreateVertexSnapAreaBehaviour;
038: import net.refractions.udig.tools.edit.behaviour.MouseDownVertexSelectorBehaviour;
039: import net.refractions.udig.tools.edit.behaviour.MoveVertexBehaviour;
040: import net.refractions.udig.tools.edit.behaviour.SelectGeometryBehaviour;
041: import net.refractions.udig.tools.edit.behaviour.SetSnapSizeBehaviour;
042: import net.refractions.udig.tools.edit.behaviour.StartEditingBehaviour;
043: import net.refractions.udig.tools.edit.behaviour.VertexSelectorBehaviour;
044: import net.refractions.udig.tools.edit.behaviour.WriteChangesBehaviour;
045: import net.refractions.udig.tools.edit.enablement.ValidToolDetectionActivator;
046: import net.refractions.udig.tools.edit.enablement.WithinLegalLayerBoundsBehaviour;
047: import net.refractions.udig.tools.edit.support.ShapeType;
048:
049: import org.eclipse.swt.SWT;
050: import org.geotools.filter.FilterType;
051:
052: import com.vividsolutions.jts.geom.Geometry;
053: import com.vividsolutions.jts.geom.MultiPoint;
054: import com.vividsolutions.jts.geom.Point;
055:
056: /**
057: * Creates and edits points.
058: *
059: * @author jones
060: * @since 1.1.0
061: */
062: public class PointTool extends AbstractEditTool {
063: @Override
064: protected void initEnablementBehaviours(
065: List<EnablementBehaviour> helper) {
066: helper.add(new WithinLegalLayerBoundsBehaviour());
067: helper.add(new ValidToolDetectionActivator(new Class[] {
068: Geometry.class, Point.class, MultiPoint.class }));
069: }
070:
071: @Override
072: protected void initActivators(Set<Activator> activators) {
073: activators.add(new EditStateListenerActivator());
074: activators.add(new DeleteGlobalActionSetterActivator());
075: activators.add(new DrawGeomsActivator(
076: DrawGeomsActivator.DrawType.POINT));
077: activators.add(new DrawCurrentGeomVerticesActivator());
078: activators.add(new SetSnapBehaviourCommandHandlerActivator());
079: activators.add(new AdvancedBehaviourCommandHandlerActivator());
080: activators.add(new SetRenderingFilter());
081: activators.add(new GridActivator());
082: }
083:
084: @Override
085: protected void initAcceptBehaviours(List<Behaviour> acceptBehaviours) {
086: acceptBehaviours.add(new WriteChangesBehaviour(Point.class));
087: }
088:
089: @Override
090: protected void initCancelBehaviours(List<Behaviour> cancelBehaviours) {
091: cancelBehaviours.add(new DefaultCancelBehaviour());
092: }
093:
094: @Override
095: protected void initEventBehaviours(
096: EditToolConfigurationHelper helper) {
097: helper.add(new DrawCreateVertexSnapAreaBehaviour());
098: helper.startAdvancedFeatures();
099: helper.add(new CursorControlBehaviour(handler,
100: new ConditionalProvider(handler,
101: Messages.PointTool_select_or_create_feature,
102: Messages.PointTool_add_vertex_or_finish),
103: new CursorControlBehaviour.SystemCursorProvider(
104: SWT.CURSOR_SIZEALL), new ConditionalProvider(
105: handler, Messages.PointTool_move_vertex, null),
106: new CursorControlBehaviour.SystemCursorProvider(
107: SWT.CURSOR_CROSS), new ConditionalProvider(
108: handler, Messages.PointTool_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: helper.startAdvancedFeatures();
114: helper.add(new MouseDownVertexSelectorBehaviour());
115: helper.add(new VertexSelectorBehaviour());
116: SelectGeometryBehaviour selectGeometryBehaviour = new SelectGeometryBehaviour(
117: new Class[] { Point.class, MultiPoint.class },
118: FilterType.GEOMETRY_BBOX);
119: selectGeometryBehaviour
120: .setCreateGeomOnNoneSelect(ShapeType.POINT);
121: helper.add(selectGeometryBehaviour);
122:
123: helper.startElseFeatures();
124: helper.add(new StartEditingBehaviour(ShapeType.POINT));
125: helper.stopElseFeatures();
126:
127: helper.stopAdvancedFeatures();
128: helper.stopMutualExclusiveList();
129:
130: helper.startAdvancedFeatures();
131: helper.add(new MoveVertexBehaviour());
132: helper.stopAdvancedFeatures();
133: helper.add(new AcceptBehaviour());
134: helper.add(new SetSnapSizeBehaviour());
135: helper.done();
136: }
137:
138: @Override
139: protected String getExtensionID() {
140: return "net.refractions.udig.tools.pointEdit"; //$NON-NLS-1$
141: }
142:
143: }
|