1 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.EditorGuide; 14 15 public class ChangeGuideCommand 16 extends Command 17 { 18 private DrawComponent part; 19 private EditorGuide oldGuide, newGuide; 20 private int oldAlign, newAlign; 21 private boolean horizontal; 22 23 public ChangeGuideCommand(DrawComponent part, boolean horizontalGuide) { 24 super(); 25 this.part = part; 26 horizontal = horizontalGuide; 27 } 28 29 protected void changeGuide(EditorGuide oldGuide, EditorGuide newGuide, int newAlignment) { 30 if (oldGuide != null && oldGuide != newGuide) { 31 oldGuide.detachPart(part); 32 } 33 if (newGuide != null) { 36 newGuide.attachPart(part, newAlignment); 37 } 38 } 39 40 public void execute() { 41 oldGuide = horizontal ? part.getHorizontalGuide() : part.getVerticalGuide(); 43 if (oldGuide != null) 44 oldAlign = oldGuide.getAlignment(part); 45 46 redo(); 47 } 48 49 public void redo() { 50 changeGuide(oldGuide, newGuide, newAlign); 51 } 52 53 public void setNewGuide(EditorGuide guide, int alignment) { 54 newGuide = guide; 55 newAlign = alignment; 56 } 57 58 public void undo() { 59 changeGuide(newGuide, oldGuide, oldAlign); 60 } 61 } 62 | Popular Tags |