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.geometry.Dimension; 33 import org.eclipse.draw2d.geometry.Rectangle; 34 import org.eclipse.gef.DragTracker; 35 import org.eclipse.gef.EditPart; 36 import org.eclipse.gef.handles.AbstractHandle; 37 import org.eclipse.gef.handles.RelativeHandleLocator; 38 import org.eclipse.swt.graphics.Color; 39 import org.eclipse.swt.graphics.Image; 40 41 import org.nightlabs.editor2d.custom.EditorCursors; 42 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 43 import org.nightlabs.editor2d.tools.RotateTracker; 44 45 public class RotateHandle 46 extends AbstractHandle 47 { 48 protected int cursorDirection = 0; 49 protected Image image; 50 51 public RotateHandle(AbstractDrawComponentEditPart owner, int direction) 53 { 54 setOwner(owner); 55 setLocator(new RelativeHandleLocator(owner.getFigure(), direction)); 56 setCursor(EditorCursors.ROTATE); 57 cursorDirection = direction; 58 } 59 60 protected DragTracker createDragTracker() { 61 return new RotateTracker((AbstractDrawComponentEditPart)getOwner(), cursorDirection); 62 } 63 64 68 protected boolean isPrimary() { 69 return getOwner().getSelected() == EditPart.SELECTED_PRIMARY; 70 } 71 72 76 protected Color getFillColor() { 77 return (isPrimary()) 78 ? ColorConstants.black 79 : ColorConstants.white; 80 } 81 82 86 protected Color getBorderColor() { 87 return (isPrimary()) 88 ? ColorConstants.white 89 : ColorConstants.black; 90 } 91 92 98 public void paintFigure(Graphics g) 99 { 100 Rectangle r = getBounds(); 102 r.shrink(1, 1); 103 try { 104 g.setBackgroundColor(getFillColor()); 105 g.fillRectangle(r.x, r.y, r.width, r.height); 106 g.setForegroundColor(getBorderColor()); 107 g.drawRectangle(r.x, r.y, r.width, r.height); 108 } finally { 109 r.expand(1, 1); 111 } 112 } 113 114 117 protected static final int DEFAULT_HANDLE_SIZE = 7; 118 119 { 120 init(); 121 } 122 123 126 protected void init() { 127 setPreferredSize(new Dimension(DEFAULT_HANDLE_SIZE, DEFAULT_HANDLE_SIZE)); 128 } 129 } 130 131 | Popular Tags |