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.commands;
016:
017: import net.refractions.udig.project.ILayer;
018: import net.refractions.udig.project.command.AbstractCommand;
019: import net.refractions.udig.project.command.UndoableMapCommand;
020: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
021: import net.refractions.udig.tool.edit.internal.Messages;
022: import net.refractions.udig.tools.edit.EditState;
023: import net.refractions.udig.tools.edit.EditToolHandler;
024: import net.refractions.udig.tools.edit.support.EditBlackboard;
025: import net.refractions.udig.tools.edit.support.EditGeom;
026: import net.refractions.udig.tools.edit.support.Point;
027: import net.refractions.udig.tools.edit.support.PrimitiveShape;
028: import net.refractions.udig.tools.edit.support.ShapeType;
029:
030: import org.eclipse.core.runtime.IProgressMonitor;
031:
032: /**
033: * <ul>
034: * <li>Sets the currentGeom to be the first geom on the black board</li>
035: * <li>Sets the state to CREATING</li>
036: * <li>Adds a point to the geom</li>
037: * </ul>
038: *
039: * @author jones
040: * @since 1.1.0
041: * @see net.refractions.udig.tools.edit.behaviour.StartEditingBehaviour
042: */
043: public class StartEditingCommand extends AbstractCommand implements
044: UndoableMapCommand {
045:
046: private final EditToolHandler handler;
047: private EditState currentState;
048: private PrimitiveShape currentShape;
049: private ILayer layer;
050: private ShapeType type;
051: private EditState endState;
052: private AddVertexCommand addVertexCommand;
053:
054: public StartEditingCommand(EditToolHandler handler,
055: MapMouseEvent event, ShapeType type) {
056: this (handler, event, type, EditState.CREATING);
057: }
058:
059: public StartEditingCommand(EditToolHandler handler,
060: MapMouseEvent event, ShapeType type, EditState endState) {
061: this .handler = handler;
062: this .layer = handler.getEditLayer();
063: this .type = type;
064: this .endState = endState;
065: addVertexCommand = new AddVertexCommand(handler, handler
066: .getEditBlackboard(layer), Point.valueOf(event.x,
067: event.y));
068: }
069:
070: public void run(IProgressMonitor monitor) throws Exception {
071: monitor.beginTask(Messages.StartEditingCommand_name, 32);
072: monitor.worked(2);
073:
074: EditBlackboard editBlackboard = handler
075: .getEditBlackboard(layer);
076:
077: EditGeom editGeom = editBlackboard.getGeoms().get(0);
078: if (editGeom.getShell().getNumPoints() > 0)
079: editGeom = editBlackboard.newGeom(null, type);
080:
081: this .currentState = handler.getCurrentState();
082: this .currentShape = handler.getCurrentShape();
083: handler.setCurrentShape(editGeom.getShell());
084: handler.setCurrentState(endState);
085:
086: addVertexCommand.setMap(handler.getContext().getMap());
087: addVertexCommand.run((monitor));
088: monitor.done();
089: }
090:
091: public String getName() {
092: return Messages.StartEditingCommand_name;
093: }
094:
095: public void rollback(IProgressMonitor monitor) throws Exception {
096: monitor.beginTask(Messages.StartEditingCommand_undo, 32);
097: monitor.worked(2);
098: handler.setCurrentState(currentState);
099: handler.setCurrentShape(currentShape);
100: monitor.done();
101: }
102:
103: }
|