How to zoom using gef? [message #219202] |
Mon, 10 July 2006 05:05  |
Eclipse User |
|
|
|
Originally posted by: reynier.michele.free.fr
Hello,
I've used GEF to implement a diagram. And now I would like the user to be able to zoom using the mouseWheel. I've already read the org.eclipse.draw2d.examples.zoom code, but I've read somewhere that gef supports zoom. It seems to me that I must use a ScalableFreeformRootEditPart and a MouseWheelZoomHandler but I'm not sure ...
Can anybody explain me how to add zoom using gef or give me a link which could help me ?
Thanks by advance.
|
|
|
|
|
|
|
Re: How to zoom using gef? [message #219470 is a reply to message #219218] |
Thu, 13 July 2006 18:26   |
Eclipse User |
|
|
|
Originally posted by: cricard.businessobjects.com
How are things going?
In case you're still stuck, please find below three better ways to get
notified when the mousewheel is involved:
1- In the GraphicalViewer (use SWT.MOD1 instead of SWT.NONE if you want to
hook the event when the Ctrl key is pressed):
// Retrieve previous handler, if any...
final MouseWheelHandler mwh =
(MouseWheelHandler)getProperty(MouseWheelHandler.KeyGenerato r.getKey(SWT.NONE));
setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), new
MouseWheelHandler() { // ...and plug yours
public void handleMouseWheel(Event event, EditPartViewer
viewer) {
System.out.println("MouseWheel in Viewer");
/* Call previous handler if you like
if(mwh != null) // Variable access is allowed in
anonymous class if it was defined as "final"
mwh.handleMouseWheel(event, viewer);
*/
}
});
2- In the DefaultEditDomain:
@Override
public void mouseWheelScrolled(Event event, EditPartViewer viewer) {
System.out.println("MouseWheel in EditDomain");
super.mouseWheelScrolled(event, viewer);
}
3- In the content EditPart (for example):
public Object getAdapter(Class adapter) {
if(adapter == MouseWheelHelper.class) {
return new ViewportMouseWheelHelper(this) { //
Available in GEF for this purpose
public void handleMouseWheelScrolled(Event
event) {
System.out.println("MouseWheel in
toplevel Part");
super.handleMouseWheelScrolled(event);
}
};
}
return super.getAdapter(adapter);
}
This code works because the "default" MouseWheelHandler placed by
GEF (see [1]) is defined as follows:
private static class MouseWheelDelegateHandler implements
MouseWheelHandler
{
private static final MouseWheelHandler SINGLETON = new
MouseWheelDelegateHandler();
private MouseWheelDelegateHandler() { }
/**
* Delegates handling to the selected editpart's
MouseWheelHelper. <= See ?
* @see org.eclipse.gef.MouseWheelHandler#handleMouseWheel
* (org.eclipse.swt.widgets.Event,
org.eclipse.gef.EditPartViewer)
**/
public void handleMouseWheel(Event event, EditPartViewer
viewer) {
EditPart part = viewer.getFocusEditPart();
do {
// Just override "getAdapter" in the
EditPart of interest in the way depicted above, so the result is...
MouseWheelHelper helper =
(MouseWheelHelper)part.getAdapter(MouseWheelHelper.class); // ... no more
null.
if (helper != null)
helper.handleMouseWheelScrolled(event);
// Calls our MouseWheelHelper in [3]
part = part.getParent();
} while (event.doit && part != null);
}
}
If everything goes well, you should see the following lines appear in the
console:
MouseWheel in EditDomain
MouseWheel in Viewer
MouseWheel in toplevel Part
Hope it helps,
Christophe.
"cricri" <cricard@businessobjects.com> wrote in message
news:e8tdfb$f5a$1@utils.eclipse.org...
> As for the mousewheel, you can write this in your GraphicalEditor:
>
> FigureCanvas fc = (FigureCanvas)root.getViewer().getControl();
>
> if(fc != null) {
> fc.addListener(SWT.MouseWheel, new Listener() {
> public void handleEvent(Event event) {
> ActionRegistry registry =
> getActionRegistry();
> IAction action =
> registry.getAction((event.count > 0) ? GEFActionConstants.ZOOM_IN :
> GEFActionConstants.ZOOM_OUT);
>
> action.run();
> }
> });
> }
>
> It's certainly not the best way of doing things, but it works.
> However, since the zoom in/out is triggered by a listener, keep in mind
> that other listeners will still execute.
> For instance, the scroll will also take place :/
>
> "Michele Reynier" <reynier.michele@free.fr> wrote in message
> news:32940570.1152522366718.JavaMail.root@cp1.javalobby.org...
>> Hello,
>>
>> I've used GEF to implement a diagram. And now I would like the user to be
>> able to zoom using the mouseWheel. I've already read the
>> org.eclipse.draw2d.examples.zoom code, but I've read somewhere that gef
>> supports zoom. It seems to me that I must use a
>> ScalableFreeformRootEditPart and a MouseWheelZoomHandler but I'm not
>> sure ...
>>
>> Can anybody explain me how to add zoom using gef or give me a link which
>> could help me ?
>>
>> Thanks by advance.
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.07220 seconds