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 java.beans.PropertyChangeEvent;
|
14
|
import java.beans.PropertyChangeListener;
|
15
|
|
16
|
import org.eclipse.draw2d.Connection;
|
17
|
import org.eclipse.draw2d.Cursors;
|
18
|
|
19
|
/**
|
20
|
* The base implementation for handles used with editparts whose figure is a
|
21
|
* {@link org.eclipse.draw2d.Connection}. This class adds an additional listener
|
22
|
* to the owner's connection figure to receive notification whenever the owner's
|
23
|
* connection's points are changed. Changing the points of a connection does not
|
24
|
* fire "figure moved", it only fires "points" property as changing.
|
25
|
*/
|
26
|
public abstract class ConnectionHandle extends SquareHandle implements
|
27
|
PropertyChangeListener {
|
28
|
|
29
|
private boolean fixed = false;
|
30
|
|
31
|
/**
|
32
|
* Creates a new ConnectionHandle.
|
33
|
*/
|
34
|
public ConnectionHandle() {
|
35
|
setCursor(Cursors.CROSS);
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Creates a new handle with the given fixed setting. If the handle is
|
40
|
* fixed, it cannot be dragged.
|
41
|
*
|
42
|
* @param fixed
|
43
|
* <code>true</code> if the handle cannot be dragged.
|
44
|
*/
|
45
|
public ConnectionHandle(boolean fixed) {
|
46
|
setFixed(fixed);
|
47
|
if (fixed)
|
48
|
setCursor(Cursors.NO);
|
49
|
else
|
50
|
setCursor(Cursors.CROSS);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Adds this as a {@link org.eclipse.draw2d.FigureListener} to the owner's
|
55
|
* {@link org.eclipse.draw2d.Figure}.
|
56
|
*/
|
57
|
public void addNotify() {
|
58
|
super.addNotify();
|
59
|
getConnection().addPropertyChangeListener(Connection.PROPERTY_POINTS,
|
60
|
this);
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Convenience method to return the owner's figure typed as
|
65
|
* <code>Connection</code>.
|
66
|
*
|
67
|
* @return the owner's connection
|
68
|
*/
|
69
|
public Connection getConnection() {
|
70
|
return (Connection) getOwnerFigure();
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Returns true if the handle cannot be dragged.
|
75
|
*
|
76
|
* @return <code>true</code> if the handle cannot be dragged
|
77
|
*/
|
78
|
protected boolean isFixed() {
|
79
|
return fixed;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
84
|
*/
|
85
|
public void propertyChange(PropertyChangeEvent evt) {
|
86
|
if (evt.getPropertyName().equals(Connection.PROPERTY_POINTS))
|
87
|
revalidate();
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Extended to remove a listener.
|
92
|
*
|
93
|
* @see org.eclipse.draw2d.IFigure#removeNotify()
|
94
|
*/
|
95
|
public void removeNotify() {
|
96
|
getConnection().removePropertyChangeListener(
|
97
|
Connection.PROPERTY_POINTS, this);
|
98
|
super.removeNotify();
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Sets whether the handle is fixed and cannot be moved
|
103
|
*
|
104
|
* @param fixed
|
105
|
* <code>true</code> if the handle should be unmovable
|
106
|
*/
|
107
|
public void setFixed(boolean fixed) {
|
108
|
this.fixed = fixed;
|
109
|
if (fixed)
|
110
|
setCursor(Cursors.NO);
|
111
|
else
|
112
|
setCursor(Cursors.CROSS);
|
113
|
}
|
114
|
|
115
|
}
|