|
Re: Moving Diagram with Mouse [message #1772101 is a reply to message #1772094] |
Tue, 05 September 2017 13:59   |
|
Which version of GEF are you using?
For the current version (GEF 5.x), you can implement an IOnDragHandler that accesses ViewportPolicy to scroll/pan in response to relative mouse movement. The handler can be registered at the root part, and it can disregard events that are processed by other handlers, so that only mouse drags on the background are considered for scrolling.
You can take a look at PanOrZoomOnScrollHandler for an example on how to use ViewportPolicy (and PanningSupport):
@Override
public void startScroll(ScrollEvent event) {
this.viewportPolicy = determineViewportPolicy();
init(viewportPolicy);
// delegate to scroll() to perform panning/zooming
scroll(event);
}
public void scroll(ScrollEvent event) {
// each event is tested for suitability so that you can switch between
// multiple scroll actions instantly when pressing/releasing modifiers
if (isPan(event)) {
pan(event);
} else if (isZoom(event)) {
zoom(event);
}
}
protected void pan(ScrollEvent event) {
// Determine horizontal and vertical translation.
Dimension delta = computePanTranslation(event);
// change viewport via operation
viewportPolicy.scroll(true, delta.width, delta.height);
// restrict panning to contents
if (isContentRestricted()) {
panningSupport.removeFreeSpace(viewportPolicy, Pos.TOP_LEFT, true);
panningSupport.removeFreeSpace(viewportPolicy, Pos.BOTTOM_RIGHT,
false);
}
}
public void endScroll() {
commit(viewportPolicy);
this.viewportPolicy = null;
}
The ViewportPolicy is initialised when the interaction starts, and it is committed when the interaction ends. In response to interaction callbacks, such as scroll() or drag(), the ViewportPolicy is used to scroll the viewer. Additionally, PanningSupport can be used to restrict scrolling to the contents.
You can take a look at FocusAndSelectOnClickHandler for an example on how to determine if another (more specific) handler already processed the event:
if (host instanceof IRootPart) {
// check if click on background (either one of the root visuals, or
// an unregistered visual)
if (!isRegistered(e.getTarget())
|| isRegisteredForHost(e.getTarget())) {
// click on background
The solution differs when using the older GEF4 1.x or GEF Legacy (3.x).
Best regards,
Matthias
|
|
|
|
Re: Moving Diagram with Mouse [message #1772110 is a reply to message #1772105] |
Tue, 05 September 2017 15:59   |
|
For GEF-Legacy, the solution given in the forum thread that is referenced in your opening post should be the way to go. However, I was not involved with development back in the day, so I do not know my way around either. What exactly is problematic?
Best regards,
Matthias
|
|
|
|
Powered by
FUDForum. Page generated in 0.02290 seconds