1 27 28 package org.nightlabs.editor2d.command; 29 30 import org.eclipse.gef.commands.Command; 31 32 import org.nightlabs.editor2d.DrawComponent; 33 import org.nightlabs.editor2d.EditorGuide; 34 35 public class ChangeGuideCommand 36 extends Command 37 { 38 private DrawComponent part; 39 private EditorGuide oldGuide, newGuide; 40 private int oldAlign, newAlign; 41 private boolean horizontal; 42 43 public ChangeGuideCommand(DrawComponent part, boolean horizontalGuide) { 44 super(); 45 this.part = part; 46 horizontal = horizontalGuide; 47 } 48 49 protected void changeGuide(EditorGuide oldGuide, EditorGuide newGuide, int newAlignment) { 50 if (oldGuide != null && oldGuide != newGuide) { 51 oldGuide.detachPart(part); 52 } 53 if (newGuide != null) { 56 newGuide.attachPart(part, newAlignment); 57 } 58 } 59 60 public void execute() { 61 oldGuide = horizontal ? part.getHorizontalGuide() : part.getVerticalGuide(); 63 if (oldGuide != null) 64 oldAlign = oldGuide.getAlignment(part); 65 66 redo(); 67 } 68 69 public void redo() { 70 changeGuide(oldGuide, newGuide, newAlign); 71 } 72 73 public void setNewGuide(EditorGuide guide, int alignment) { 74 newGuide = guide; 75 newAlign = alignment; 76 } 77 78 public void undo() { 79 changeGuide(newGuide, oldGuide, oldAlign); 80 } 81 } 82 | Popular Tags |