KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > command > MoveGuideCommand


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 11.11.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.command;
9
10 import java.util.Iterator JavaDoc;
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 JavaDoc 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 // Point location = part.getLocation().getCopy();
39
// Point location = new Point(part.getX(), part.getY());
40

41         if (guide.isHorizontal()) {
42             location.y += pDelta;
43         } else {
44             location.x += pDelta;
45         }
46 // part.setLocation(location);
47
part.setX(location.x);
48         part.setY(location.y);
49     }
50   }
51
52   public void undo() {
53     guide.setPosition(guide.getPosition() - pDelta);
54     Iterator JavaDoc iter = guide.getMap().keySet().iterator();
55     while (iter.hasNext()) {
56       DrawComponent part = (DrawComponent)iter.next();
57 // Point location = part.getLocation().getCopy();
58
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.setLocation(location);
65
part.setX(location.x);
66         part.setY(location.y);
67     }
68   }
69   
70 }
71
Popular Tags