KickJava   Java API By Example, From Geeks To Geeks.

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


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: 14.12.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.command;
9
10 import org.eclipse.gef.commands.Command;
11
12 import com.nightlabs.editor2d.DrawComponent;
13 import com.nightlabs.editor2d.DrawComponentContainer;
14 import com.nightlabs.editor2d.EditorPlugin;
15
16
17 public class DrawComponentReorderCommand
18 extends Command
19 {
20   private int oldIndex, newIndex;
21   private DrawComponent child;
22   private DrawComponentContainer parent;
23
24   public DrawComponentReorderCommand(DrawComponent child, DrawComponentContainer parent, int newIndex )
25   {
26     super(EditorPlugin.getResourceString("command_reorder_drawcomponent"));
27     this.child = child;
28     this.parent = parent;
29     this.newIndex = newIndex;
30   }
31
32   public void execute()
33   {
34     oldIndex = parent.getDrawComponents().indexOf(child);
35     parent.getDrawComponents().remove(child);
36     parent.getDrawComponents().add(newIndex, child);
37   }
38
39   public void undo()
40   {
41     parent.getDrawComponents().remove(child);
42     parent.getDrawComponents().add(oldIndex, child);
43   }
44 }
45
Popular Tags