KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.handle;
29
30 import org.eclipse.draw2d.Cursors;
31 import org.eclipse.draw2d.LineBorder;
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.handles.SquareHandle;
36 import org.nightlabs.editor2d.edit.ShapeDrawComponentEditPart;
37 import org.nightlabs.editor2d.tools.ShapeEditTracker;
38
39
40 public class ShapeEditHandle
41 extends SquareHandle
42 {
43   protected ShapeDrawComponentEditPart owner;
44   protected int pathSegmentIndex;
45   
46   public ShapeEditHandle(ShapeDrawComponentEditPart owner, int pathSegmentIndex)
47   {
48     super(owner, new ShapeHandleLocator(owner, pathSegmentIndex));
49     this.owner = owner;
50     this.pathSegmentIndex = pathSegmentIndex;
51     initialize();
52 // setLocation(p);
53
}
54     
55   /* (non-Javadoc)
56    * @see org.eclipse.gef.handles.AbstractHandle#createDragTracker()
57    */

58   protected DragTracker createDragTracker() {
59     return new ShapeEditTracker(owner, pathSegmentIndex);
60   }
61   
62   public static final int DEFAULT_SIZE = 6;
63       
64   /**
65    * Initializes the handle. Sets the {@link DragTracker} and
66    * DragCursor.
67    */

68   protected void initialize() {
69     setOpaque(false);
70     setBorder(new LineBorder(1));
71     setCursor(Cursors.CROSS);
72     setPreferredSize(new Dimension(DEFAULT_SIZE, DEFAULT_SIZE));
73     setSize(DEFAULT_SIZE, DEFAULT_SIZE);
74     
75 // setLocation(getPathSegmentLocation());
76
}
77      
78   public void setBounds(Rectangle rect)
79   {
80     super.setBounds(new Rectangle(rect.x, rect.y, DEFAULT_SIZE, DEFAULT_SIZE));
81   }
82   
83   private boolean fixed = false;
84   
85   /**
86    * Returns true if the handle cannot be dragged.
87    * @return <code>true</code> if the handle cannot be dragged
88    */

89   protected boolean isFixed() {
90     return fixed;
91   }
92   
93   /**
94    * Sets whether the handle is fixed and cannot be moved
95    * @param fixed <code>true</code> if the handle should be unmovable
96    */

97   public void setFixed(boolean fixed)
98   {
99     this.fixed = fixed;
100     if (fixed)
101         setCursor(Cursors.NO);
102     else
103         setCursor(Cursors.CROSS);
104   }
105     
106 // protected Point getPathSegmentLocation()
107
// {
108
// ShapeFigure sf = (ShapeFigure) owner.getFigure();
109
// PathSegment ps = sf.getGeneralShape().getPathSegment(pathSegmentIndex);
110
// if (ps != null) {
111
// return J2DUtil.toDraw2D(ps.getPoint());
112
// }
113
// return new Point();
114
// }
115

116 }
117
Popular Tags