1 27 28 package org.nightlabs.editor2d.tools; 29 30 import org.apache.log4j.Logger; 31 import org.eclipse.draw2d.geometry.Point; 32 import org.eclipse.gef.Request; 33 import org.eclipse.swt.graphics.Cursor; 34 35 import org.nightlabs.editor2d.custom.EditorCursors; 36 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 37 import org.nightlabs.editor2d.request.EditorRotateRequest; 38 import org.nightlabs.editor2d.util.EditorUtil; 39 40 public class RotateTracker 41 extends AbstractDragTracker 42 { 43 public static final Logger LOGGER = Logger.getLogger(RotateTracker.class); 44 protected int direction; 45 46 public RotateTracker(AbstractDrawComponentEditPart owner, int direction) 47 { 48 super(owner); 49 this.direction = direction; 50 } 51 52 protected AbstractDrawComponentEditPart getAbstractDrawComponentEditPart() { 53 return (AbstractDrawComponentEditPart) owner; 54 } 55 56 59 protected Request createSourceRequest() 60 { 61 EditorRotateRequest rotateRequest = new EditorRotateRequest(); 62 rotateRequest.setType(REQ_ROTATE); 63 rotateRequest.setLocation(getLocation()); 64 rotateRequest.setEditParts(getCurrentViewer().getSelectedEditParts()); 65 return rotateRequest; 66 } 67 68 protected String getCommandName() 69 { 70 return REQ_ROTATE; 71 } 72 73 76 protected Cursor getDefaultCursor() 77 { 78 return EditorCursors.ROTATE; 79 } 80 81 protected Point rotationCenter; 82 83 86 protected void updateSourceRequest() 87 { 88 if (getEditorRotateRequest().getRotationCenter() == null && owner != null) 89 { 90 if (getEditorRotateRequest().getEditParts().size() > 1) { 91 rotationCenter = EditorUtil.getCenter(getEditorRotateRequest().getEditParts()); 92 getEditorRotateRequest().setRotationCenter(rotationCenter); 93 getEditorRotateRequest().setMultiple(true); 94 } 95 else { 96 rotationCenter = new Point(getAbstractDrawComponentEditPart().getDrawComponent().getRotationX(), 97 getAbstractDrawComponentEditPart().getDrawComponent().getRotationY()); 98 getEditorRotateRequest().setRotationCenter(rotationCenter); 99 getEditorRotateRequest().setMultiple(false); 100 } 101 } 102 getEditorRotateRequest().setLocation(getLocation()); 103 104 LOGGER.debug("updateSourceRequest.rotation = "+getEditorRotateRequest().getRotation()); 105 LOGGER.debug("rotationCenter = "+rotationCenter); 106 LOGGER.debug("location = "+getLocation()); 107 } 108 109 protected EditorRotateRequest getEditorRotateRequest() 110 { 111 return (EditorRotateRequest) getSourceRequest(); 112 } 113 114 protected String getDebugName() 115 { 116 return "Rotate Handle Tracker"; } 118 119 protected void performSelection() 121 { 122 123 } 124 } 125 | Popular Tags |