1 27 28 package org.nightlabs.editor2d.tools; 29 30 import java.util.List ; 31 32 import org.eclipse.draw2d.PositionConstants; 33 import org.eclipse.gef.GraphicalEditPart; 34 import org.eclipse.gef.Request; 35 import org.eclipse.swt.graphics.Cursor; 36 37 import org.nightlabs.editor2d.custom.EditorCursors; 38 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 39 import org.nightlabs.editor2d.request.EditorShearRequest; 40 import org.nightlabs.editor2d.util.J2DUtil; 41 42 43 public class ShearTracker 44 extends AbstractDragTracker 45 { 46 protected int direction; 47 48 51 public ShearTracker(GraphicalEditPart owner, int direction) { 52 super(owner); 53 this.direction = direction; 54 } 55 56 59 protected Request createSourceRequest() 60 { 61 EditorShearRequest request = new EditorShearRequest(); 62 request.setType(REQ_SHEAR); 63 request.setLocation(getLocation()); 64 request.setDirection(direction); 65 List selectedParts = getCurrentViewer().getSelectedEditParts(); 66 if (!selectedParts.isEmpty()) { 67 AbstractDrawComponentEditPart part = (AbstractDrawComponentEditPart) selectedParts.get(0); 68 request.setShearBounds(J2DUtil.toDraw2D(part.getDrawComponent().getBounds())); 69 } 70 request.setEditParts(selectedParts); 71 return request; 72 } 73 74 77 protected void updateSourceRequest() 78 { 79 getEditorShearRequest().setLocation(getLocation()); 83 } 84 85 protected EditorShearRequest getEditorShearRequest() { 86 return (EditorShearRequest) getSourceRequest(); 87 } 88 89 92 protected String getCommandName() { 93 return REQ_SHEAR; 94 } 95 96 99 protected Cursor getDefaultCursor() 100 { 101 switch(direction) 102 { 103 case(PositionConstants.NORTH): 104 case(PositionConstants.SOUTH): 105 return EditorCursors.SHEAR_HORIZONTAL; 106 case(PositionConstants.WEST): 107 case(PositionConstants.EAST): 108 return EditorCursors.SHEAR_VERTICAL; 109 } 110 return EditorCursors.NO; 111 } 112 } 113 | Popular Tags |