Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to translate absolute mouse coordinates to relative coordinates in an editor
icon5.gif  How to translate absolute mouse coordinates to relative coordinates in an editor [message #483335] Tue, 01 September 2009 08:25 Go to next message
Arnaud Dieumegard is currently offline Arnaud DieumegardFriend
Messages: 2
Registered: September 2009
Junior Member
Hi all,

I'm creating a little plug-in to drop requirements in a Sysml editor.
I want to make automatic to add a Satisfy link between the droped requirement and the class behind the mouse during the drop.
For that I have make a class implementing DropActionAdapter and in the handleDrop(Modeler modeler, Transfer transfer, EditPart editPart) method I want to get the editPart behind the mouse.

public void handleDrop(Modeler modeler, Transfer transfer, EditPart editPart) {
    //I get the inputEvent in an other method
    mouseLocation = new Point(inputEvent.x, inputEvent.y);
    //The edit part is the root editPart on the editor
    IFigure fig = ((GraphicalEditPart)editPart).getFigure();
    fig.translateToRelative(mouseLocation);
    EditPart part = editPart.getViewer().findObjectAt(mouseLocation);
    //[...]
}


My problem is that the mouse location is not translated to relative and so the new EditPart (part) is the root EditPart
Is there something wrong in my code ?

Any help is welcome !!

Arnaud
icon10.gif  Re: How to translate absolute mouse coordinates to relative coordinates in an editor [message #484088 is a reply to message #483335] Fri, 04 September 2009 09:14 Go to previous message
Arnaud Dieumegard is currently offline Arnaud DieumegardFriend
Messages: 2
Registered: September 2009
Junior Member
I have found a solution Surprised

setMouseLocation(new Point(getInputEvent().x, getInputEvent().y));
DropTarget target = (DropTarget)getInputEvent().widget;

org.eclipse.swt.graphics.Point relativePoint = target.getControl().toControl(new org.eclipse.swt.graphics.Point(getInputEvent().x,getInputEvent().y));

getMouseLocation().setLocation(relativePoint.x, relativePoint.y);
EditPart part = editPart.getViewer().findObjectAt(getMouseLocation());


If it could be useful Razz

Arnaud
Previous Topic:change default rectangle bounds in zest SpringLayoutAlgorithm
Next Topic:Cannot change the link line from straight line to another path.
Goto Forum:
  


Current Time: Fri Mar 29 14:31:54 GMT 2024

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

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

Back to the top