1 8 package com.nightlabs.editor2d.command; 9 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 14 import org.eclipse.gef.commands.Command; 15 16 import com.nightlabs.editor2d.DrawComponent; 17 import com.nightlabs.editor2d.EditorGuide; 18 import com.nightlabs.editor2d.EditorPlugin; 19 import com.nightlabs.editor2d.EditorRuler; 20 21 public class DeleteGuideCommand 22 extends Command 23 { 24 private EditorRuler parent; 25 private EditorGuide guide; 26 private Map oldParts; 27 28 public DeleteGuideCommand(EditorGuide guide, EditorRuler parent) { 29 super(EditorPlugin.getResourceString("command_delete_guide")); 30 this.guide = guide; 31 this.parent = parent; 32 } 33 34 public boolean canUndo() { 35 return true; 36 } 37 38 public void execute() 39 { 40 oldParts = new HashMap (guide.getMap()); 41 Iterator iter = oldParts.keySet().iterator(); 42 while (iter.hasNext()) { 43 guide.detachPart((DrawComponent)iter.next()); 44 } 45 parent.removeGuide(guide); 46 } 47 48 public void undo() 49 { 50 parent.addGuide(guide); 51 Iterator iter = oldParts.keySet().iterator(); 52 while (iter.hasNext()) { 53 DrawComponent part = (DrawComponent)iter.next(); 54 guide.attachPart(part, ((Integer )oldParts.get(part)).intValue()); 55 } 56 } 57 58 } 59 | Popular Tags |