01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.commands;
16:
17: import net.refractions.udig.project.command.AbstractCommand;
18: import net.refractions.udig.project.command.UndoableMapCommand;
19: import net.refractions.udig.tool.edit.internal.Messages;
20: import net.refractions.udig.tools.edit.support.EditBlackboard;
21: import net.refractions.udig.tools.edit.support.Point;
22:
23: import org.eclipse.core.runtime.IProgressMonitor;
24:
25: /**
26: * Moves Vertex in the {@link net.refractions.udig.tools.edit.support.EditBlackboard}
27: * @author jones
28: * @since 1.1.0
29: */
30: public class MoveVertexCommand extends AbstractCommand implements
31: UndoableMapCommand {
32:
33: EditBlackboard bb;
34: Point src;
35: private Point dest;
36: private boolean ran = false;
37: private boolean redoUndoOnly = false;
38:
39: /**
40: *
41: * @param bb blackboard to manipulate
42: * @param src point to move
43: * @param dest where to move point.
44: * @param coords the coords to move from the src point location. If null all points will be moved.
45: */
46: public MoveVertexCommand(EditBlackboard bb, Point src, Point dest) {
47: this .bb = bb;
48: this .src = src;
49: this .dest = dest;
50: }
51:
52: public void run(IProgressMonitor monitor) throws Exception {
53: if (!ran && redoUndoOnly) {
54: // this is a bit of a hack, see setRedoUndoOnly.
55: ran = true;
56: return;
57: }
58:
59: bb.moveCoords(src.getX(), src.getY(), dest.getX(), dest.getY());
60: }
61:
62: public String getName() {
63: return Messages.MoveVertexCommand_name;
64: }
65:
66: public void rollback(IProgressMonitor monitor) throws Exception {
67: bb.moveCoords(dest.getX(), dest.getY(), src.getX(), src.getY());
68: }
69:
70: /**
71: * This determines whether the first time the method is ran whether it will do anything.
72: * <p>
73: * In the case of the MoveVertex behaviour the vertices are moved
74: * little by little, pixel by pixel often. So undoing and redoing all that would be
75: * pointless. For those cases this command has a RedoUndoOnly parameter so that when the command
76: * is sent to the map it does nothing. But once undo is called redo will still work. If this is false then
77: * it will operate normally.
78: * </p>
79: * @param redoUndoOnly
80: */
81: public void setRedoUndoOnly(boolean redoUndoOnly) {
82: this.redoUndoOnly = redoUndoOnly;
83: }
84:
85: }
|