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.editpolicies;
|
12
|
|
13
|
import org.eclipse.draw2d.Connection;
|
14
|
import org.eclipse.draw2d.ConnectionAnchor;
|
15
|
import org.eclipse.draw2d.XYAnchor;
|
16
|
import org.eclipse.draw2d.geometry.Point;
|
17
|
|
18
|
/**
|
19
|
* Helps display connection feedback during drags of the connection ends. This
|
20
|
* class is used internally by the provided EditPolicy implementation.
|
21
|
*
|
22
|
* @author hudsonr
|
23
|
*/
|
24
|
public class FeedbackHelper {
|
25
|
|
26
|
private Connection connection;
|
27
|
private XYAnchor dummyAnchor;
|
28
|
private boolean isMovingStartAnchor = false;
|
29
|
|
30
|
/**
|
31
|
* Constructs a new FeedbackHelper.
|
32
|
*/
|
33
|
public FeedbackHelper() {
|
34
|
dummyAnchor = new XYAnchor(new Point(10, 10));
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* Returns the connection being used to show feedback.
|
39
|
*
|
40
|
* @return the connection
|
41
|
*/
|
42
|
protected Connection getConnection() {
|
43
|
return connection;
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Returns true is the feedback is moving the source anchor
|
48
|
*
|
49
|
* @return <code>true</code> if moving start
|
50
|
*/
|
51
|
protected boolean isMovingStartAnchor() {
|
52
|
return isMovingStartAnchor;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Sets the connection.
|
57
|
*
|
58
|
* @param c
|
59
|
* connection
|
60
|
*/
|
61
|
public void setConnection(Connection c) {
|
62
|
connection = c;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Sets if moving start of connection.
|
67
|
*
|
68
|
* @param value
|
69
|
* <code>true</code> if the starts is being moved
|
70
|
*/
|
71
|
public void setMovingStartAnchor(boolean value) {
|
72
|
isMovingStartAnchor = value;
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Sets the anchor for the end being moved.
|
77
|
*
|
78
|
* @param anchor
|
79
|
* the new anchor
|
80
|
*/
|
81
|
protected void setAnchor(ConnectionAnchor anchor) {
|
82
|
if (isMovingStartAnchor())
|
83
|
getConnection().setSourceAnchor(anchor);
|
84
|
else
|
85
|
getConnection().setTargetAnchor(anchor);
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Updates the feedback based on the given anchor or point. The anchor is
|
90
|
* used unless <code>null</code>. The point is used when there is no anchor.
|
91
|
*
|
92
|
* @param anchor
|
93
|
* <code>null</code> or an anchor
|
94
|
* @param p
|
95
|
* the point to use when there is no anchor
|
96
|
*/
|
97
|
public void update(ConnectionAnchor anchor, Point p) {
|
98
|
if (anchor != null)
|
99
|
setAnchor(anchor);
|
100
|
else {
|
101
|
dummyAnchor.setLocation(p);
|
102
|
setAnchor(dummyAnchor);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
}
|