KickJava   Java API By Example, From Geeks To Geeks.

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


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: 13.01.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.handle;
9
10 import org.eclipse.draw2d.Cursors;
11 import org.eclipse.draw2d.LineBorder;
12 import org.eclipse.draw2d.geometry.Dimension;
13 import org.eclipse.draw2d.geometry.Rectangle;
14 import org.eclipse.gef.DragTracker;
15 import org.eclipse.gef.handles.SquareHandle;
16
17 import com.nightlabs.editor2d.edit.ShapeDrawComponentEditPart;
18 import com.nightlabs.editor2d.figures.ShapeFigure;
19 import com.nightlabs.editor2d.tools.ShapeEditTracker;
20
21
22 public class ShapeEditHandle
23 extends SquareHandle
24 {
25   protected ShapeDrawComponentEditPart owner;
26   protected int pathSegmentIndex;
27   
28   public ShapeEditHandle(ShapeDrawComponentEditPart owner, int pathSegmentIndex)
29   {
30     super(owner, new ShapeHandleLocator(owner, pathSegmentIndex));
31     this.owner = owner;
32     this.pathSegmentIndex = pathSegmentIndex;
33     initialize();
34 // setLocation(p);
35
}
36     
37   /* (non-Javadoc)
38    * @see org.eclipse.gef.handles.AbstractHandle#createDragTracker()
39    */

40   protected DragTracker createDragTracker() {
41     return new ShapeEditTracker(owner, pathSegmentIndex);
42   }
43   
44   public static final int DEFAULT_SIZE = 6;
45       
46   /**
47    * Initializes the handle. Sets the {@link DragTracker} and
48    * DragCursor.
49    */

50   protected void initialize() {
51     setOpaque(false);
52     setBorder(new LineBorder(1));
53     setCursor(Cursors.CROSS);
54     setPreferredSize(new Dimension(DEFAULT_SIZE, DEFAULT_SIZE));
55     setSize(DEFAULT_SIZE, DEFAULT_SIZE);
56     
57 // setLocation(getPathSegmentLocation());
58
}
59      
60   public void setBounds(Rectangle rect)
61   {
62     super.setBounds(new Rectangle(rect.x, rect.y, DEFAULT_SIZE, DEFAULT_SIZE));
63   }
64   
65   private boolean fixed = false;
66   
67   /**
68    * Returns true if the handle cannot be dragged.
69    * @return <code>true</code> if the handle cannot be dragged
70    */

71   protected boolean isFixed() {
72     return fixed;
73   }
74   
75   /**
76    * Sets whether the handle is fixed and cannot be moved
77    * @param fixed <code>true</code> if the handle should be unmovable
78    */

79   public void setFixed(boolean fixed)
80   {
81     this.fixed = fixed;
82     if (fixed)
83         setCursor(Cursors.NO);
84     else
85         setCursor(Cursors.CROSS);
86   }
87     
88 // protected Point getPathSegmentLocation()
89
// {
90
// ShapeFigure sf = (ShapeFigure) owner.getFigure();
91
// PathSegment ps = sf.getGeneralShape().getPathSegment(pathSegmentIndex);
92
// if (ps != null) {
93
// return J2DUtil.toDraw2D(ps.getPoint());
94
// }
95
// return new Point();
96
// }
97

98 }
99
Popular Tags