Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » SWT Widget inside Figure
SWT Widget inside Figure [message #240147] Tue, 04 December 2007 18:59
Eclipse UserFriend
Originally posted by: christoph.nenning.netallied.de

Hi,

I have some trouble with my GEF editor. It's a 2D editor with nodes and
connections
but each node is represented by a 3D file. To load and display the 3D
files we use the
3D rendering engine ogre4j. ogre4j needs a SWT Canvas embedded into a
draw2d Figure
to be able to render into that Figure.

My first problem was to get a reference to the editor's FigureCanvas.
I need it as the parent for all my SWT Canvas.

To accomplish this I copied SWTGraphics and added a getter for it's
FigureCanvas
(the field "control"). Furthermore I copied NativeGraphicsSource and
changed it
to use my own Graphics class. Finally I put that new GraphicsSource into
the
UpdateManager during configureGraphicalViewer() in my editor:

protected void configureGraphicalViewer() {
super.configureGraphicalViewer();

// put OGRE into GEF
final FigureCanvas figCanvas = (FigureCanvas)
getGraphicalViewer().getControl();
LightweightSystem lws = figCanvas.getLightweightSystem();
lws.getUpdateManager().setGraphicsSource(new
MyGraphicsSource(figCanvas));

...
}

That way the Figure can obtain the SWT parent for it's Canvas during
paintFigure(Graphics)

First question: Can I do this in a different way so that I don't have to
copy and change
Framework classes? (I cannot subclass them because NativeGraphicsSource is
final and
SWTGraphics's "control" field is private.)

Second problem I got with zooming. It is pretty cool that zooming works in
GEF without Figures
to know about it, but exactly this is a problem with my SWT Canvas. I have
to resize/reposition
it according current zoom level. During resize/reposition events I can get
current zoom but
I need some zoom events to resize/reposition the Canvas directly when
zooming occurs.

private double getScale() {
if (ogreComposite != null) {
List vpChildren =
((FigureCanvas)ogreComposite.getParent()).getViewport().getC hildren();
List paneChildren =
((FreeformLayeredPane)vpChildren.get(0)).getChildren();
for (Object i : paneChildren) {
if (i instanceof ScalableFreeformLayeredPane) {
ScalableFreeformLayeredPane pane =
(ScalableFreeformLayeredPane)i;
return pane.getScale();
}
}
}
return 1.0;
}


Third and last question belongs to input events. I need GEF specific mouse
listeners to handle
selection, moving, resizing, ... of Figures and I need SWT events on my
Canvas to allow moving
the 3D camera. Currently I disable the Canvas after creation and enable it
when the Figure
is selected but that causes some strange behavior. I also tried to
register as a MouseMotionListener
and work with mouseEntered and mouseExited but when I enable/disable my
Canvas I get these
events all the time. Is there a best practice to solve this?
Previous Topic:Questions and thought about Shared editing domain
Next Topic:Node name validation at creation time. Lock focus on an editpart?
Goto Forum:
  


Current Time: Thu Apr 25 15:20:50 GMT 2024

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

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

Back to the top