1 8 package com.nightlabs.editor2d.tools; 9 10 import org.apache.log4j.Logger; 11 import org.eclipse.draw2d.geometry.Point; 12 import org.eclipse.gef.Request; 13 import org.eclipse.swt.graphics.Cursor; 14 15 import com.nightlabs.editor2d.custom.EditorCursors; 16 import com.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 17 import com.nightlabs.editor2d.request.EditorRotateRequest; 18 import com.nightlabs.editor2d.util.EditorUtil; 19 20 public class RotateTracker 21 extends AbstractDragTracker 22 { 23 public static final Logger LOGGER = Logger.getLogger(RotateTracker.class); 24 protected int direction; 25 26 public RotateTracker(AbstractDrawComponentEditPart owner, int direction) 27 { 28 super(owner); 29 this.direction = direction; 30 } 31 32 protected AbstractDrawComponentEditPart getAbstractDrawComponentEditPart() { 33 return (AbstractDrawComponentEditPart) owner; 34 } 35 36 39 protected Request createSourceRequest() 40 { 41 EditorRotateRequest rotateRequest = new EditorRotateRequest(); 42 rotateRequest.setType(REQ_ROTATE); 43 rotateRequest.setLocation(getLocation()); 44 rotateRequest.setEditParts(getCurrentViewer().getSelectedEditParts()); 45 return rotateRequest; 46 } 47 48 protected String getCommandName() 49 { 50 return REQ_ROTATE; 51 } 52 53 56 protected Cursor getDefaultCursor() 57 { 58 return EditorCursors.ROTATE; 59 } 60 61 protected Point rotationCenter; 62 63 66 protected void updateSourceRequest() 67 { 68 if (getEditorRotateRequest().getRotationCenter() == null && owner != null) 69 { 70 if (getEditorRotateRequest().getEditParts().size() > 1) { 71 rotationCenter = EditorUtil.getCenter(getEditorRotateRequest().getEditParts()); 72 getEditorRotateRequest().setRotationCenter(rotationCenter); 73 getEditorRotateRequest().setMultiple(true); 74 } 75 else { 76 rotationCenter = new Point(getAbstractDrawComponentEditPart().getDrawComponent().getRotationX(), 77 getAbstractDrawComponentEditPart().getDrawComponent().getRotationY()); 78 getEditorRotateRequest().setRotationCenter(rotationCenter); 79 getEditorRotateRequest().setMultiple(false); 80 } 81 } 82 getEditorRotateRequest().setLocation(getLocation()); 83 84 LOGGER.debug("updateSourceRequest.rotation = "+getEditorRotateRequest().getRotation()); 85 LOGGER.debug("rotationCenter = "+rotationCenter); 86 LOGGER.debug("location = "+getLocation()); 87 } 88 89 protected EditorRotateRequest getEditorRotateRequest() 90 { 91 return (EditorRotateRequest) getSourceRequest(); 92 } 93 94 protected String getDebugName() 95 { 96 return "Rotate Handle Tracker"; } 98 99 protected void performSelection() 101 { 102 103 } 104 } 105 | Popular Tags |