Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Child drop offset problem
Child drop offset problem [message #221329] Fri, 11 August 2006 15:22 Go to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
When reparenting a child to a new parent using a drag and drop I have a
problem calculating the proper location of the drop.

The request supplies the mouse location of the drop. If you use this
location the child figure's top right corner will jump to this location on
the drop. I need to calculate the offset between the mouse and the child
figure's top right corner. The only way I can think of doing this is to
capture the initial MouseDown Event of the drag and calculate the delta
between the mouse and the child figures bounds; however the dragTracker
deals with this so I don't see how I can get at this information?

Is there any way to get at this information, or is there another way of
doing this?

Thanks in advance.
Re: Child drop offset problem [message #221491 is a reply to message #221329] Tue, 15 August 2006 10:57 Go to previous messageGo to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
Thanks for the answer. Alas, the solution is not that straight forward. I
managed to get this working by following the logic example code :

protected Command getAddCommand(Request generic) {
ChangeBoundsRequest request = (ChangeBoundsRequest)generic;
List editParts = request.getEditParts();
CompoundCommand command = new CompoundCommand();
command.setDebugLabel("Add in ConstrainedLayoutEditPolicy");//$NON-NLS-1$
GraphicalEditPart childPart;
Rectangle r;
Object constraint;

for (int i = 0; i < editParts.size(); i++) {
childPart = (GraphicalEditPart)editParts.get(i);
r = childPart.getFigure().getBounds().getCopy();
//convert r to absolute from childpart figure
childPart.getFigure().translateToAbsolute(r);
r = request.getTransformedRectangle(r);
//convert this figure to relative
getLayoutContainer().translateToRelative(r);
getLayoutContainer().translateFromParent(r);
r.translate(getLayoutOrigin().getNegated());
constraint = getConstraintFor(r);
command.add(createAddCommand(generic, childPart,
translateToModelConstraint(constraint)));
}
return command.unwrap();
}

!!!!

//-------------------------------

Nhu Le wrote:

> Are you sure it's always the top right corner of the child that is
> placed at the mouse's location?. I mean, if it is always the top right,
> you may as well subtract the width of the figure then you get the top
> left!. I don't think the drag tracker cares about the bounds of your
> figure.

> Nhu Le.


> Mark Robinson wrote:
>> When reparenting a child to a new parent using a drag and drop I have a
>> problem calculating the proper location of the drop.
>>
>> The request supplies the mouse location of the drop. If you use this
>> location the child figure's top right corner will jump to this location
>> on the drop. I need to calculate the offset between the mouse and the
>> child figure's top right corner. The only way I can think of doing this
>> is to capture the initial MouseDown Event of the drag and calculate the
>> delta between the mouse and the child figures bounds; however the
>> dragTracker deals with this so I don't see how I can get at this
>> information?
>>
>> Is there any way to get at this information, or is there another way of
>> doing this?
>>
>> Thanks in advance.
>>
Re: Child drop offset problem [message #221499 is a reply to message #221491] Tue, 15 August 2006 11:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

Mark Robinson wrote:

> Thanks for the answer. Alas, the solution is not that straight forward. I
> managed to get this working by following the logic example code :
>
> protected Command getAddCommand(Request generic) {
> ChangeBoundsRequest request = (ChangeBoundsRequest)generic;
> List editParts = request.getEditParts();
> CompoundCommand command = new CompoundCommand();
> command.setDebugLabel("Add in ConstrainedLayoutEditPolicy");//$NON-NLS-1$
> GraphicalEditPart childPart;
> Rectangle r;
> Object constraint;
>
> for (int i = 0; i < editParts.size(); i++) {
> childPart = (GraphicalEditPart)editParts.get(i);
> r = childPart.getFigure().getBounds().getCopy();
> //convert r to absolute from childpart figure
> childPart.getFigure().translateToAbsolute(r);
> r = request.getTransformedRectangle(r);
> //convert this figure to relative
> getLayoutContainer().translateToRelative(r);
> getLayoutContainer().translateFromParent(r);
> r.translate(getLayoutOrigin().getNegated());
> constraint = getConstraintFor(r);
> command.add(createAddCommand(generic, childPart,
> translateToModelConstraint(constraint)));
> }
> return command.unwrap();
> }
>
> !!!!
>
> //-------------------------------
>
> Nhu Le wrote:
>
>> Are you sure it's always the top right corner of the child that is
>> placed at the mouse's location?. I mean, if it is always the top right,
>> you may as well subtract the width of the figure then you get the top
>> left!. I don't think the drag tracker cares about the bounds of your
>> figure.
>
>> Nhu Le.
>
>
>> Mark Robinson wrote:
>>> When reparenting a child to a new parent using a drag and drop I have a
>>> problem calculating the proper location of the drop.
>>>
>>> The request supplies the mouse location of the drop. If you use this
>>> location the child figure's top right corner will jump to this location
>>> on the drop. I need to calculate the offset between the mouse and the
>>> child figure's top right corner. The only way I can think of doing this
>>> is to capture the initial MouseDown Event of the drag and calculate the
>>> delta between the mouse and the child figures bounds; however the
>>> dragTracker deals with this so I don't see how I can get at this
>>> information?
>>>
>>> Is there any way to get at this information, or is there another way of
>>> doing this?
>>>
>>> Thanks in advance.
>>>

That looks pretty good. If it works I would perform two more tests to be
sure.

1. Zoom in.
2. zoom out.
3. Drop the figure while your view is zoomed in.
4. Drop the part while your figure is zoomed out.

These should help you perfect your relative/absolute positioning.


--
Respectfully,

CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into the
sheepfold{}, but climbeth up some other *way, the same is a thief and a
robber."
Re: Child drop offset problem [message #221619 is a reply to message #221491] Wed, 16 August 2006 14:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Why aren't you just overriding createAddCommand()?


"Mark Robinson" <mr@prismtech.com> wrote in message
news:070c32597c57d784fea7837275463cc2$1@www.eclipse.org...
> Thanks for the answer. Alas, the solution is not that straight forward. I
> managed to get this working by following the logic example code :
>
> protected Command getAddCommand(Request generic) {
> ChangeBoundsRequest request = (ChangeBoundsRequest)generic;
> List editParts = request.getEditParts();
> CompoundCommand command = new CompoundCommand();
> command.setDebugLabel("Add in ConstrainedLayoutEditPolicy");//$NON-NLS-1$
> GraphicalEditPart childPart;
> Rectangle r;
> Object constraint;
>
> for (int i = 0; i < editParts.size(); i++) {
> childPart = (GraphicalEditPart)editParts.get(i);
> r = childPart.getFigure().getBounds().getCopy();
> //convert r to absolute from childpart figure
> childPart.getFigure().translateToAbsolute(r);
> r = request.getTransformedRectangle(r);
> //convert this figure to relative
> getLayoutContainer().translateToRelative(r);
> getLayoutContainer().translateFromParent(r);
> r.translate(getLayoutOrigin().getNegated());
> constraint = getConstraintFor(r);
> command.add(createAddCommand(generic, childPart,
> translateToModelConstraint(constraint)));
> }
> return command.unwrap();
> }
>
> !!!!
>
> //-------------------------------
>
> Nhu Le wrote:
>
>> Are you sure it's always the top right corner of the child that is placed
>> at the mouse's location?. I mean, if it is always the top right, you may
>> as well subtract the width of the figure then you get the top left!. I
>> don't think the drag tracker cares about the bounds of your figure.
>
>> Nhu Le.
>
>
>> Mark Robinson wrote:
>>> When reparenting a child to a new parent using a drag and drop I have a
>>> problem calculating the proper location of the drop.
>>>
>>> The request supplies the mouse location of the drop. If you use this
>>> location the child figure's top right corner will jump to this location
>>> on the drop. I need to calculate the offset between the mouse and the
>>> child figure's top right corner. The only way I can think of doing this
>>> is to capture the initial MouseDown Event of the drag and calculate the
>>> delta between the mouse and the child figures bounds; however the
>>> dragTracker deals with this so I don't see how I can get at this
>>> information?
>>>
>>> Is there any way to get at this information, or is there another way of
>>> doing this?
>>>
>>> Thanks in advance.
>>>
>
Re: Child drop offset problem [message #221780 is a reply to message #221619] Fri, 18 August 2006 10:32 Go to previous message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
Randy Hudson wrote:

> Why aren't you just overriding createAddCommand()?

Thanks Randy.

After reading your mail I removed my getAddCommand and 'lo and behold' the
drag and drop is placed correctly! You are correct, all I had to do was
override createAddCommand.

As I'm still learning GEF the only way to get stuff to work is to follow
the examples that are available. I based my code on the Logic example, and
the logic example was using getAddCommand? The Logic example is misleading
here.

After checking ConstrainedLayoutEditPolicy#getAddCommand, it is doing all
the translation calculation for you!

But, thanks; because now I know how do this correctly.











> "Mark Robinson" <mr@prismtech.com> wrote in message
> news:070c32597c57d784fea7837275463cc2$1@www.eclipse.org...
>> Thanks for the answer. Alas, the solution is not that straight forward. I
>> managed to get this working by following the logic example code :
>>
>> protected Command getAddCommand(Request generic) {
>> ChangeBoundsRequest request = (ChangeBoundsRequest)generic;
>> List editParts = request.getEditParts();
>> CompoundCommand command = new CompoundCommand();
>> command.setDebugLabel("Add in ConstrainedLayoutEditPolicy");//$NON-NLS-1$
>> GraphicalEditPart childPart;
>> Rectangle r;
>> Object constraint;
>>
>> for (int i = 0; i < editParts.size(); i++) {
>> childPart = (GraphicalEditPart)editParts.get(i);
>> r = childPart.getFigure().getBounds().getCopy();
>> //convert r to absolute from childpart figure
>> childPart.getFigure().translateToAbsolute(r);
>> r = request.getTransformedRectangle(r);
>> //convert this figure to relative
>> getLayoutContainer().translateToRelative(r);
>> getLayoutContainer().translateFromParent(r);
>> r.translate(getLayoutOrigin().getNegated());
>> constraint = getConstraintFor(r);
>> command.add(createAddCommand(generic, childPart,
>> translateToModelConstraint(constraint)));
>> }
>> return command.unwrap();
>> }
>>
>> !!!!
>>
>> //-------------------------------
>>
>> Nhu Le wrote:
>>
>>> Are you sure it's always the top right corner of the child that is placed
>>> at the mouse's location?. I mean, if it is always the top right, you may
>>> as well subtract the width of the figure then you get the top left!. I
>>> don't think the drag tracker cares about the bounds of your figure.
>>
>>> Nhu Le.
>>
>>
>>> Mark Robinson wrote:
>>>> When reparenting a child to a new parent using a drag and drop I have a
>>>> problem calculating the proper location of the drop.
>>>>
>>>> The request supplies the mouse location of the drop. If you use this
>>>> location the child figure's top right corner will jump to this location
>>>> on the drop. I need to calculate the offset between the mouse and the
>>>> child figure's top right corner. The only way I can think of doing this
>>>> is to capture the initial MouseDown Event of the drag and calculate the
>>>> delta between the mouse and the child figures bounds; however the
>>>> dragTracker deals with this so I don't see how I can get at this
>>>> information?
>>>>
>>>> Is there any way to get at this information, or is there another way of
>>>> doing this?
>>>>
>>>> Thanks in advance.
>>>>
>>
Previous Topic:Problem with Saving
Next Topic:Change the color of the selection frame
Goto Forum:
  


Current Time: Wed Feb 05 07:00:13 GMT 2025

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

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

Back to the top