1 27 28 package org.nightlabs.editor2d.handle; 29 30 import org.eclipse.draw2d.ColorConstants; 31 import org.eclipse.draw2d.Graphics; 32 import org.eclipse.draw2d.PositionConstants; 33 import org.eclipse.draw2d.geometry.Rectangle; 34 import org.eclipse.gef.DragTracker; 35 import org.eclipse.gef.GraphicalEditPart; 36 import org.eclipse.gef.handles.RelativeHandleLocator; 37 import org.eclipse.swt.graphics.Cursor; 38 39 import org.nightlabs.editor2d.custom.EditorCursors; 40 import org.nightlabs.editor2d.tools.ShearTracker; 41 42 43 public class ShearHandle 44 extends EditorAbstractHandle 45 { 46 protected int cursorDirection = 0; 47 48 public ShearHandle(GraphicalEditPart owner, int direction) 49 { 50 setOwner(owner); 51 setLocator(new RelativeHandleLocator(owner.getFigure(), direction)); 52 cursorDirection = direction; 53 setCursor(getDefaultCursor(direction)); 54 } 55 56 protected Cursor getDefaultCursor(int direction) 57 { 58 switch(direction) 59 { 60 case(PositionConstants.NORTH): 61 case(PositionConstants.SOUTH): 62 return EditorCursors.SHEAR_HORIZONTAL; 63 case(PositionConstants.WEST): 64 case(PositionConstants.EAST): 65 return EditorCursors.SHEAR_VERTICAL; 66 } 67 return EditorCursors.NO; 68 } 69 81 public void paintFigure(Graphics g) 82 { 83 Rectangle r = getBounds(); 85 r.shrink(1, 1); 86 try { 87 g.setBackgroundColor(ColorConstants.black); 88 g.fillRectangle(r.x, r.y, r.width, r.height); 89 g.setForegroundColor(ColorConstants.white); 90 g.drawRectangle(r.x, r.y, r.width, r.height); 91 } finally { 92 r.expand(1, 1); 94 } 95 } 96 97 protected void paintHandle(Graphics g, int direction) 98 { 99 g.setForegroundColor(ColorConstants.black); 100 switch(direction) 101 { 102 case(PositionConstants.EAST): 103 case(PositionConstants.WEST): 104 g.drawLine(2, 2, 6, 6); 106 g.drawLine(6, 6, 5, 5); 107 g.drawLine(6, 6, 6, 5); 108 g.drawLine(6, 6, 2, 2); 110 g.drawLine(2, 2, 3, 3); 111 g.drawLine(2, 2, 1, 3); 112 break; 113 case(PositionConstants.NORTH): 114 case(PositionConstants.SOUTH): 115 g.drawLine(2, 2, 6, 6); 117 g.drawLine(6, 6, 5, 5); 118 g.drawLine(6, 6, 6, 5); 119 g.drawLine(6, 6, 2, 2); 121 g.drawLine(2, 2, 3, 3); 122 g.drawLine(2, 2, 1, 3); 123 break; 124 } 125 } 126 127 protected DragTracker createDragTracker() { 128 return new ShearTracker(getOwner(), cursorDirection); 129 } 130 131 } 132 | Popular Tags |