Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 10-19
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.gef.tools; |
11 |
package org.eclipse.gef.tools; |
12 |
|
12 |
|
|
|
13 |
import java.util.Collections; |
13 |
import java.util.List; |
14 |
import java.util.List; |
14 |
|
15 |
|
15 |
import org.eclipse.swt.SWT; |
16 |
import org.eclipse.swt.SWT; |
16 |
import org.eclipse.swt.graphics.Cursor; |
17 |
import org.eclipse.swt.graphics.Cursor; |
|
|
18 |
import org.eclipse.swt.widgets.Display; |
17 |
|
19 |
|
18 |
import org.eclipse.draw2d.IFigure; |
20 |
import org.eclipse.draw2d.IFigure; |
19 |
import org.eclipse.draw2d.PositionConstants; |
21 |
import org.eclipse.draw2d.PositionConstants; |
Lines 23-28
Link Here
|
23 |
import org.eclipse.draw2d.geometry.PrecisionPoint; |
25 |
import org.eclipse.draw2d.geometry.PrecisionPoint; |
24 |
import org.eclipse.draw2d.geometry.PrecisionRectangle; |
26 |
import org.eclipse.draw2d.geometry.PrecisionRectangle; |
25 |
|
27 |
|
|
|
28 |
import org.eclipse.gef.AutoexposeHelper; |
26 |
import org.eclipse.gef.EditPart; |
29 |
import org.eclipse.gef.EditPart; |
27 |
import org.eclipse.gef.GraphicalEditPart; |
30 |
import org.eclipse.gef.GraphicalEditPart; |
28 |
import org.eclipse.gef.Request; |
31 |
import org.eclipse.gef.Request; |
Lines 55-61
Link Here
|
55 |
private GraphicalEditPart owner; |
58 |
private GraphicalEditPart owner; |
56 |
private PrecisionRectangle sourceRect; |
59 |
private PrecisionRectangle sourceRect; |
57 |
private SnapToHelper snapToHelper; |
60 |
private SnapToHelper snapToHelper; |
|
|
61 |
private PrecisionPoint sourceRelativeStartPoint; |
58 |
|
62 |
|
|
|
63 |
private AutoexposeHelper exposeHelper; |
64 |
|
65 |
class QueuedAutoexpose implements Runnable { |
66 |
public void run() { |
67 |
if (exposeHelper != null) |
68 |
doAutoexpose(); |
69 |
} |
70 |
} |
71 |
/** |
72 |
* Called to perform an iteration of the autoexpose process. If the expose helper is set, |
73 |
* it will be asked to step at the current mouse location. If it returns true, another |
74 |
* expose iteration will be queued. There is no delay between autoexpose events, other |
75 |
* than the time required to perform the step(). |
76 |
*/ |
77 |
protected void doAutoexpose() { |
78 |
if (exposeHelper == null) |
79 |
return; |
80 |
if (exposeHelper.step(getLocation())) { |
81 |
handleAutoexpose(); |
82 |
Display.getCurrent().asyncExec(new QueuedAutoexpose()); |
83 |
} else |
84 |
setAutoexposeHelper(null); |
85 |
} |
86 |
protected void handleAutoexpose() { |
87 |
updateSourceRequest(); |
88 |
showSourceFeedback(); |
89 |
showTargetFeedback(); |
90 |
setCurrentCommand(getCommand()); |
91 |
} |
92 |
/** |
93 |
* Returns <code>null</code> or the current autoexpose helper. |
94 |
* @return null or a helper |
95 |
*/ |
96 |
protected AutoexposeHelper getAutoexposeHelper() { |
97 |
return exposeHelper; |
98 |
} |
99 |
/** |
100 |
* Sets the active autoexpose helper to the given helper, or <code>null</code>. If the |
101 |
* helper is not <code>null</code>, a runnable is queued on the event thread that will |
102 |
* trigger a subsequent {@link #doAutoexpose()}. The helper is typically updated only on |
103 |
* a hover event. |
104 |
* @param helper the new autoexpose helper or <code>null</code> |
105 |
*/ |
106 |
protected void setAutoexposeHelper(AutoexposeHelper helper) { |
107 |
exposeHelper = helper; |
108 |
if (exposeHelper == null) |
109 |
return; |
110 |
Display.getCurrent().asyncExec(new QueuedAutoexpose()); |
111 |
|
112 |
if (sourceRelativeStartPoint == null && isInDragInProgress()) { |
113 |
IFigure figure = getTargetEditPart().getFigure(); |
114 |
sourceRelativeStartPoint = new PrecisionPoint(getStartLocation()); |
115 |
figure.translateToRelative(sourceRelativeStartPoint); |
116 |
} |
117 |
} |
118 |
/** |
119 |
* Updates the active {@link AutoexposeHelper}. Does nothing if there is still an active |
120 |
* helper. Otherwise, obtains a new helper (possible <code>null</code>) at the current |
121 |
* mouse location and calls {@link #setAutoexposeHelper(AutoexposeHelper)}. |
122 |
*/ |
123 |
protected void updateAutoexposeHelper() { |
124 |
if (exposeHelper != null) |
125 |
return; |
126 |
AutoexposeHelper.Search search; |
127 |
search = new AutoexposeHelper.Search(getLocation()); |
128 |
getCurrentViewer() |
129 |
.findObjectAtExcluding(getLocation(), Collections.EMPTY_LIST, search); |
130 |
setAutoexposeHelper(search.result); |
131 |
} |
132 |
|
133 |
/** |
134 |
* If auto scroll (also called auto expose) is being performed, the start location moves |
135 |
* during the scroll. This method updates that location. |
136 |
*/ |
137 |
protected void repairStartLocation() { |
138 |
if (sourceRelativeStartPoint == null) |
139 |
return; |
140 |
IFigure figure = getTargetEditPart().getFigure(); |
141 |
PrecisionPoint newStart = (PrecisionPoint)sourceRelativeStartPoint.getCopy(); |
142 |
figure.translateToAbsolute(newStart); |
143 |
Point delta = new Point(newStart.x - getStartLocation().x, |
144 |
newStart.y - getStartLocation().y); |
145 |
setStartLocation(newStart); |
146 |
// sourceRect needs to be updated as well when auto-scrolling |
147 |
if (sourceRect != null) |
148 |
sourceRect.translate(delta); |
149 |
; |
150 |
} |
59 |
/** |
151 |
/** |
60 |
* Constructs a resize tracker that resizes in the specified direction. The direction is |
152 |
* Constructs a resize tracker that resizes in the specified direction. The direction is |
61 |
* specified using {@link PositionConstants#NORTH}, {@link PositionConstants#NORTH_EAST}, |
153 |
* specified using {@link PositionConstants#NORTH}, {@link PositionConstants#NORTH_EAST}, |
Lines 133-138
Link Here
|
133 |
// For the case where ESC key was hit while resizing |
225 |
// For the case where ESC key was hit while resizing |
134 |
eraseTargetFeedback(); |
226 |
eraseTargetFeedback(); |
135 |
|
227 |
|
|
|
228 |
sourceRelativeStartPoint = null; |
229 |
setAutoexposeHelper(null); |
136 |
sourceRect = null; |
230 |
sourceRect = null; |
137 |
snapToHelper = null; |
231 |
snapToHelper = null; |
138 |
super.deactivate(); |
232 |
super.deactivate(); |
Lines 234-241
Link Here
|
234 |
showTargetFeedback(); |
328 |
showTargetFeedback(); |
235 |
setCurrentCommand(getCommand()); |
329 |
setCurrentCommand(getCommand()); |
236 |
} |
330 |
} |
|
|
331 |
|
237 |
return true; |
332 |
return true; |
238 |
} |
333 |
} |
|
|
334 |
protected boolean handleHover() { |
335 |
if (isInDragInProgress()) |
336 |
updateAutoexposeHelper(); |
337 |
return true; |
338 |
} |
239 |
|
339 |
|
240 |
/** |
340 |
/** |
241 |
* This method is invoked as the drag is happening. It notifies the |
341 |
* This method is invoked as the drag is happening. It notifies the |
Lines 251-256
Link Here
|
251 |
* @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest() |
351 |
* @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest() |
252 |
*/ |
352 |
*/ |
253 |
protected void updateSourceRequest() { |
353 |
protected void updateSourceRequest() { |
|
|
354 |
repairStartLocation(); |
355 |
|
254 |
ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest(); |
356 |
ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest(); |
255 |
Dimension d = getDragMoveDelta(); |
357 |
Dimension d = getDragMoveDelta(); |
256 |
|
358 |
|