1 8 package com.nightlabs.editor2d.handle; 9 10 import org.eclipse.draw2d.ColorConstants; 11 import org.eclipse.draw2d.Graphics; 12 import org.eclipse.draw2d.PositionConstants; 13 import org.eclipse.draw2d.geometry.Rectangle; 14 import org.eclipse.gef.DragTracker; 15 import org.eclipse.gef.GraphicalEditPart; 16 import org.eclipse.gef.handles.RelativeHandleLocator; 17 import org.eclipse.swt.graphics.Cursor; 18 19 import com.nightlabs.editor2d.custom.EditorCursors; 20 import com.nightlabs.editor2d.tools.ShearTracker; 21 22 23 public class ShearHandle 24 extends EditorAbstractHandle 25 { 26 protected int cursorDirection = 0; 27 28 public ShearHandle(GraphicalEditPart owner, int direction) 29 { 30 setOwner(owner); 31 setLocator(new RelativeHandleLocator(owner.getFigure(), direction)); 32 cursorDirection = direction; 33 setCursor(getDefaultCursor(direction)); 34 } 35 36 protected Cursor getDefaultCursor(int direction) 37 { 38 switch(direction) 39 { 40 case(PositionConstants.NORTH): 41 case(PositionConstants.SOUTH): 42 return EditorCursors.SHEAR_HORIZONTAL; 43 case(PositionConstants.WEST): 44 case(PositionConstants.EAST): 45 return EditorCursors.SHEAR_VERTICAL; 46 } 47 return EditorCursors.NO; 48 } 49 61 public void paintFigure(Graphics g) 62 { 63 Rectangle r = getBounds(); 65 r.shrink(1, 1); 66 try { 67 g.setBackgroundColor(ColorConstants.black); 68 g.fillRectangle(r.x, r.y, r.width, r.height); 69 g.setForegroundColor(ColorConstants.white); 70 g.drawRectangle(r.x, r.y, r.width, r.height); 71 } finally { 72 r.expand(1, 1); 74 } 75 } 76 77 protected void paintHandle(Graphics g, int direction) 78 { 79 g.setForegroundColor(ColorConstants.black); 80 switch(direction) 81 { 82 case(PositionConstants.EAST): 83 case(PositionConstants.WEST): 84 g.drawLine(2, 2, 6, 6); 86 g.drawLine(6, 6, 5, 5); 87 g.drawLine(6, 6, 6, 5); 88 g.drawLine(6, 6, 2, 2); 90 g.drawLine(2, 2, 3, 3); 91 g.drawLine(2, 2, 1, 3); 92 break; 93 case(PositionConstants.NORTH): 94 case(PositionConstants.SOUTH): 95 g.drawLine(2, 2, 6, 6); 97 g.drawLine(6, 6, 5, 5); 98 g.drawLine(6, 6, 6, 5); 99 g.drawLine(6, 6, 2, 2); 101 g.drawLine(2, 2, 3, 3); 102 g.drawLine(2, 2, 1, 3); 103 break; 104 } 105 } 106 107 protected DragTracker createDragTracker() { 108 return new ShearTracker(getOwner(), cursorDirection); 109 } 110 111 } 112
| Popular Tags
|