Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to zoom using gef?
How to zoom using gef? [message #219202] Mon, 10 July 2006 09:05 Go to next message
Eclipse UserFriend
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 #219210 is a reply to message #219202] Mon, 10 July 2006 11:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cricard.businessobjects.com

Please have a look at page 159 of this pdf:
http://www.redbooks.ibm.com/redbooks/pdfs/sg246302.pdf
It's pretty straightforward.

"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.
Re: How to zoom using gef? [message #219218 is a reply to message #219202] Mon, 10 July 2006 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cricard.businessobjects.com

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.
Re: How to zoom using gef? [message #219226 is a reply to message #219210] Mon, 10 July 2006 12:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: reynier.michele.free.fr

Thanks a lot, I've read the part Zooming of the pdf and tried to make my root EditPart a
ScalableFreeformRootEditPart.
But when I open the view, I obtain the following exception :
java.lang.ClassCastException: org.eclipse.draw2d.FreeformLayer
at org.eclipse.gef.editparts.ScalableFreeformRootEditPart.<init >(ScalableFreeformRootEditPart.java:93)
at org.objectweb.proactive.ic2d.monitoring.editparts.WorldEditP art. <init>(WorldEditPart.java:54)
...

My root EditPart is WorldEditPart, before it extended AbstractGraphicalEditPart.

I think it is because my method createFigure returns a FreeFormLayer but I'm not sure. If it's due to that, what is the figure that I must return ?

Thanks
Re: How to zoom using gef? [message #219243 is a reply to message #219226] Mon, 10 July 2006 13:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cricard.businessobjects.com

Read sections 3.3.7 (RootEditparts) and 3.4.4 (Attaching the viewer).
In the samples provided, the writers have made the choice to use
ScalableFreeformRootEditPart, but perhaps your app was created using a
ScalableRootEditPart, hence the invalid class cast if you copied the sample
code "as is".

But this is only a guess...

PS :
GEF uses the following mechanism to install a mousewheel handler.
Perhaps it's a better way to provide your own one than my previous
suggestion (the code of MouseWheelDelegateHandler can also be found in
org.eclipse.gef.ui.parts.GraphicalViewerImpl.class):

public GraphicalViewerImpl() {
createDefaultRoot();
setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE),
MouseWheelDelegateHandler.SINGLETON); //$NON-NLS-1$
}

"Michele Reynier" <reynier.michele@free.fr> wrote in message
news:15674152.1152533817455.JavaMail.root@cp1.javalobby.org...
> Thanks a lot, I've read the part Zooming of the pdf and tried to make my
> root EditPart a
> ScalableFreeformRootEditPart.
> But when I open the view, I obtain the following exception :
> java.lang.ClassCastException: org.eclipse.draw2d.FreeformLayer
> at
> org.eclipse.gef.editparts.ScalableFreeformRootEditPart.<init >(ScalableFreeformRootEditPart.java:93)
> at
> org.objectweb.proactive.ic2d.monitoring.editparts.WorldEditP art. <init>(WorldEditPart.java:54)
> ..
>
> My root EditPart is WorldEditPart, before it extended
> AbstractGraphicalEditPart.
>
> I think it is because my method createFigure returns a FreeFormLayer but
> I'm not sure. If it's due to that, what is the figure that I must return ?
>
> Thanks
Re: How to zoom using gef? [message #219470 is a reply to message #219218] Thu, 13 July 2006 22:26 Go to previous messageGo to next message
Eclipse UserFriend
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.
>
>
Re: How to zoom using gef? [message #220346 is a reply to message #219202] Sun, 30 July 2006 21:16 Go to previous message
Eclipse UserFriend
Originally posted by: gregzimmerman.in.pine.gmail.com

Take a look at section 4.2.4 (Zooming) in this pdf document.
I have tried it, and zooming works in my application using GEF 3.1

http://www.redbooks.ibm.com/redbooks/pdfs/sg246302.pdf

Greg

"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.
Previous Topic:What's new in 3.2?
Next Topic:Printing GEF Figures
Goto Forum:
  


Current Time: Fri Jan 24 03:40:08 GMT 2025

Powered by FUDForum. Page generated in 0.23135 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top