1 27 28 package org.nightlabs.editor2d.command; 29 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 import org.eclipse.draw2d.geometry.Point; 35 import org.eclipse.gef.EditPart; 36 import org.eclipse.gef.commands.Command; 37 38 import org.nightlabs.editor2d.DrawComponent; 39 import org.nightlabs.editor2d.EditorPlugin; 40 import org.nightlabs.editor2d.request.EditorRotateCenterRequest; 41 import org.nightlabs.editor2d.util.EditorUtil; 42 43 44 public class RotateCenterCommand 45 extends Command 46 { 47 protected Map dc2RotationCenter; 48 protected EditorRotateCenterRequest request; 49 50 protected Point rotationCenter; 51 public Point getRotationCenter() { 52 return rotationCenter; 53 } 54 public void setRotationCenter(Point rotationCenter) { 55 this.rotationCenter = rotationCenter; 56 } 57 58 protected boolean multiple = false; 59 public boolean isMultiple() { 60 return multiple; 61 } 62 public void setMultiple(boolean multiple) { 63 this.multiple = multiple; 64 } 65 66 public RotateCenterCommand(EditorRotateCenterRequest request) 67 { 68 super(); 69 this.request = request; 70 this.multiple = request.isMultiple(); 71 setLabel(EditorPlugin.getResourceString("command.rotate.center")); 72 } 73 74 public void execute() 75 { 76 dc2RotationCenter = new HashMap (request.getEditParts().size()); 77 for (Iterator it = request.getEditParts().iterator(); it.hasNext(); ) 78 { 79 EditPart editPart = (EditPart) it.next(); 80 DrawComponent dc = (DrawComponent) editPart.getModel(); 81 Point oldRotationCenter = new Point(dc.getRotationX(), dc.getRotationY()); 82 dc2RotationCenter.put(dc, oldRotationCenter); 83 if (isMultiple()) { 84 dc.setTmpRotationX(rotationCenter.x); 85 dc.setTmpRotationY(rotationCenter.y); 86 } else { 87 dc.setRotationX(rotationCenter.x); 88 dc.setRotationY(rotationCenter.y); 89 } 90 } 91 EditorUtil.selectEditParts(request.getEditParts()); 92 } 93 94 public void redo() 95 { 96 for (Iterator it = dc2RotationCenter.keySet().iterator(); it.hasNext(); ) 97 { 98 DrawComponent dc = (DrawComponent) it.next(); 99 if (isMultiple()) { 100 dc.setTmpRotationX(rotationCenter.x); 101 dc.setTmpRotationY(rotationCenter.y); 102 } else { 103 dc.setRotationX(rotationCenter.x); 104 dc.setRotationY(rotationCenter.y); 105 } 106 } 107 EditorUtil.selectEditParts(request.getEditParts()); 108 } 109 110 public void undo() 111 { 112 for (Iterator it = dc2RotationCenter.keySet().iterator(); it.hasNext(); ) 113 { 114 DrawComponent dc = (DrawComponent) it.next(); 115 Point oldRotationCenter = (Point) dc2RotationCenter.get(dc); 116 if (isMultiple()) { 117 dc.setTmpRotationX(DrawComponent.ROTATION_X_DEFAULT); 118 dc.setTmpRotationY(DrawComponent.ROTATION_Y_DEFAULT); 119 } else { 120 dc.setRotationX(oldRotationCenter.x); 121 dc.setRotationY(oldRotationCenter.y); 122 } 123 } 124 EditorUtil.selectEditParts(request.getEditParts()); 125 } 126 } 127 | Popular Tags |