1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.gef.handles;
|
12
|
|
13
|
import org.eclipse.draw2d.Cursors;
|
14
|
import org.eclipse.draw2d.LineBorder;
|
15
|
import org.eclipse.draw2d.Locator;
|
16
|
import org.eclipse.draw2d.geometry.Point;
|
17
|
import org.eclipse.draw2d.geometry.Rectangle;
|
18
|
|
19
|
import org.eclipse.gef.DragTracker;
|
20
|
import org.eclipse.gef.GraphicalEditPart;
|
21
|
import org.eclipse.gef.tools.DragEditPartsTracker;
|
22
|
|
23
|
/**
|
24
|
* A Handle used for moving {@link GraphicalEditPart}s.
|
25
|
*/
|
26
|
public class MoveHandle extends AbstractHandle {
|
27
|
|
28
|
/**
|
29
|
* The hit-threshold for {@link #containsPoint(int, int)}.
|
30
|
*
|
31
|
* @deprecated subclasses should not reference this field.
|
32
|
*/
|
33
|
protected static final int INNER_PAD = 2;
|
34
|
|
35
|
/**
|
36
|
* Creates a MoveHandle for the given <code>GraphicalEditPart</code> using a
|
37
|
* default {@link Locator}.
|
38
|
*
|
39
|
* @param owner
|
40
|
* The GraphicalEditPart to be moved by this handle.
|
41
|
*/
|
42
|
public MoveHandle(GraphicalEditPart owner) {
|
43
|
this(owner, new MoveHandleLocator(owner.getFigure()));
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Creates a MoveHandle for the given <code>GraphicalEditPart</code> using
|
48
|
* the given <code>Locator</code>.
|
49
|
*
|
50
|
* @param owner
|
51
|
* The GraphicalEditPart to be moved by this handle.
|
52
|
* @param loc
|
53
|
* The Locator used to place the handle.
|
54
|
*/
|
55
|
public MoveHandle(GraphicalEditPart owner, Locator loc) {
|
56
|
super(owner, loc);
|
57
|
initialize();
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Overridden to create a {@link DragEditPartsTracker}.
|
62
|
*
|
63
|
* @see org.eclipse.gef.handles.AbstractHandle#createDragTracker()
|
64
|
*/
|
65
|
protected DragTracker createDragTracker() {
|
66
|
DragEditPartsTracker tracker = new DragEditPartsTracker(getOwner());
|
67
|
tracker.setDefaultCursor(getCursor());
|
68
|
return tracker;
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Returns <code>true</code> if the point (x,y) is contained within this
|
73
|
* handle.
|
74
|
*
|
75
|
* @param x
|
76
|
* The x coordinate.
|
77
|
* @param y
|
78
|
* The y coordinate.
|
79
|
* @return <code>true</code> if the point (x,y) is contained within this
|
80
|
* handle.
|
81
|
*/
|
82
|
public boolean containsPoint(int x, int y) {
|
83
|
if (!super.containsPoint(x, y))
|
84
|
return false;
|
85
|
return !Rectangle.SINGLETON.setBounds(getBounds())
|
86
|
.shrink(INNER_PAD, INNER_PAD).contains(x, y);
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Returns a point along the right edge of the handle.
|
91
|
*
|
92
|
* @see org.eclipse.gef.Handle#getAccessibleLocation()
|
93
|
*/
|
94
|
public Point getAccessibleLocation() {
|
95
|
Point p = getBounds().getTopRight().translate(-1,
|
96
|
getBounds().height / 4);
|
97
|
translateToAbsolute(p);
|
98
|
return p;
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Initializes the handle. Sets the {@link DragTracker} and DragCursor.
|
103
|
*/
|
104
|
protected void initialize() {
|
105
|
setOpaque(false);
|
106
|
setBorder(new LineBorder(1));
|
107
|
setCursor(Cursors.SIZEALL);
|
108
|
}
|
109
|
|
110
|
}
|