|
|
Re: Child drop offset problem [message #221499 is a reply to message #221491] |
Tue, 15 August 2006 11:03 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Mark Robinson 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.
>>>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.03160 seconds