1 27 28 package org.nightlabs.editor2d.command; 29 30 import java.util.Iterator ; 31 32 import org.eclipse.draw2d.geometry.Point; 33 import org.eclipse.gef.commands.Command; 34 35 import org.nightlabs.editor2d.DrawComponent; 36 import org.nightlabs.editor2d.EditorGuide; 37 import org.nightlabs.editor2d.EditorPlugin; 38 39 public class MoveGuideCommand 40 extends Command 41 { 42 private int pDelta; 43 private EditorGuide guide; 44 45 public MoveGuideCommand(EditorGuide guide, int positionDelta) { 46 super(EditorPlugin.getResourceString("command.move.guide")); 47 this.guide = guide; 48 pDelta = positionDelta; 49 } 50 51 public void execute() 52 { 53 guide.setPosition(guide.getPosition() + pDelta); 54 Iterator iter = guide.getMap().keySet().iterator(); 55 while (iter.hasNext()) { 56 DrawComponent part = (DrawComponent)iter.next(); 57 Point location = new Point(part.getX(), part.getY()).getCopy(); 58 61 if (guide.isHorizontal()) { 62 location.y += pDelta; 63 } else { 64 location.x += pDelta; 65 } 66 part.setX(location.x); 68 part.setY(location.y); 69 } 70 } 71 72 public void undo() { 73 guide.setPosition(guide.getPosition() - pDelta); 74 Iterator iter = guide.getMap().keySet().iterator(); 75 while (iter.hasNext()) { 76 DrawComponent part = (DrawComponent)iter.next(); 77 Point location = new Point(part.getX(), part.getY()); 79 if (guide.isHorizontal()) { 80 location.y -= pDelta; 81 } else { 82 location.x -= pDelta; 83 } 84 part.setX(location.x); 86 part.setY(location.y); 87 } 88 } 89 90 } 91 | Popular Tags |