1 8 package com.nightlabs.editor2d.command; 9 10 import java.util.Iterator ; 11 12 import org.eclipse.draw2d.geometry.Point; 13 import org.eclipse.gef.commands.Command; 14 15 import com.nightlabs.editor2d.DrawComponent; 16 import com.nightlabs.editor2d.EditorGuide; 17 import com.nightlabs.editor2d.EditorPlugin; 18 19 public class MoveGuideCommand 20 extends Command 21 { 22 private int pDelta; 23 private EditorGuide guide; 24 25 public MoveGuideCommand(EditorGuide guide, int positionDelta) { 26 super(EditorPlugin.getResourceString("command_move_guide")); 27 this.guide = guide; 28 pDelta = positionDelta; 29 } 30 31 public void execute() 32 { 33 guide.setPosition(guide.getPosition() + pDelta); 34 Iterator iter = guide.getMap().keySet().iterator(); 35 while (iter.hasNext()) { 36 DrawComponent part = (DrawComponent)iter.next(); 37 Point location = new Point(part.getX(), part.getY()).getCopy(); 38 41 if (guide.isHorizontal()) { 42 location.y += pDelta; 43 } else { 44 location.x += pDelta; 45 } 46 part.setX(location.x); 48 part.setY(location.y); 49 } 50 } 51 52 public void undo() { 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()); 59 if (guide.isHorizontal()) { 60 location.y -= pDelta; 61 } else { 62 location.x -= pDelta; 63 } 64 part.setX(location.x); 66 part.setY(location.y); 67 } 68 } 69 70 } 71 | Popular Tags |