|
Re: Moving Diagram with Mouse [message #1772101 is a reply to message #1772094] |
Tue, 05 September 2017 09:59   |
Eclipse User |
|
|
|
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 #1772153 is a reply to message #1772110] |
Wed, 06 September 2017 03:43  |
Eclipse User |
|
|
|
I am a newbie in gef and should work more to explain what is the problem but thank you, i will try harder to solve this according to forum thread in my first post. If something comes up i will try to explain later.
Thank you for your guidance.
Umut
|
|
|
Powered by
FUDForum. Page generated in 0.08312 seconds