KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > handle > ShearHandle


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 14.04.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

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 // public void paintFigure(Graphics g)
50
// {
51
// Rectangle r = getBounds();
52
// r.shrink(1, 1);
53
// try {
54
// paintHandle(g, cursorDirection);
55
// } finally {
56
// //We don't really own rect 'r', so fix it.
57
// r.expand(1, 1);
58
// }
59
// }
60

61   public void paintFigure(Graphics g)
62   {
63     // TODO: draw Rotate Handles
64
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       //We don't really own rect 'r', so fix it.
73
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         // draw down Arrow
85
g.drawLine(2, 2, 6, 6);
86         g.drawLine(6, 6, 5, 5);
87         g.drawLine(6, 6, 6, 5);
88         // draw up Arrow
89
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         // draw down Arrow
96
g.drawLine(2, 2, 6, 6);
97         g.drawLine(6, 6, 5, 5);
98         g.drawLine(6, 6, 6, 5);
99         // draw up Arrow
100
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