Skip to main content



      Home
Home » Eclipse Projects » GEF » Finding figure under mouse on drag/drop
Finding figure under mouse on drag/drop [message #125204] Wed, 31 March 2004 19:09 Go to next message
Eclipse UserFriend
Originally posted by: mas.nospam.com

How do I identify the figure that is underneath the mouse for the drag
operation for the following code?

public class DNDTest
{
public static void main(String[] args)
{
Display display= new Display();
final Shell shell = new Shell(display);

shell.setLayout( new GridLayout() );

Composite composite = new Composite( shell, SWT.NONE);
composite.setLayout( new GridLayout() );

final FigureCanvas figureCanvas = new FigureCanvas( composite );
Figure panel = new Figure();
panel.setLayoutManager( new FlowLayout() );
panel.add( new Label("Label1"));
panel.add( new Label("Label2"));
panel.add( new Label("Label3"));
figureCanvas.setContents( panel );

// Allow data to be copied or moved from the drag source
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DragSource canvasSource = new DragSource( figureCanvas,
operations );
canvasSource.addDragListener(new DragSourceListener()
{
public void dragStart(DragSourceEvent event)
{
System.out.println("Drag Started");
IFigure afigure = figureCanvas.getContents().findFigureAt(
event.display.getCursorLocation().x,
event.display.getCursorLocation().y);
System.out.println( afigure );
}
public void dragSetData(DragSourceEvent event) {}
public void dragFinished(DragSourceEvent event){}

});
shell.open();
while (!shell.isDisposed())
while (!display.readAndDispatch())
display.sleep();

}
}

Help is appreciated. MM
Re: Finding figure under mouse on drag/drop [message #125350 is a reply to message #125204] Thu, 01 April 2004 10:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It looks like you already have the code. Except instead of calling
getContents(), which reaches in past the viewport figure, you need to call
getViewport(). Otherwise you will be incorrect when the figures are
scrolled.

"Mas Masoud" <mas@nospam.com> wrote in message
news:c4fmjn$ivm$1@eclipse.org...
> How do I identify the figure that is underneath the mouse for the drag
> operation for the following code?
>
> public class DNDTest
> {
> public static void main(String[] args)
> {
> Display display= new Display();
> final Shell shell = new Shell(display);
>
> shell.setLayout( new GridLayout() );
>
> Composite composite = new Composite( shell, SWT.NONE);
> composite.setLayout( new GridLayout() );
>
> final FigureCanvas figureCanvas = new FigureCanvas( composite );
> Figure panel = new Figure();
> panel.setLayoutManager( new FlowLayout() );
> panel.add( new Label("Label1"));
> panel.add( new Label("Label2"));
> panel.add( new Label("Label3"));
> figureCanvas.setContents( panel );
>
> // Allow data to be copied or moved from the drag source
> int operations = DND.DROP_MOVE | DND.DROP_COPY;
> DragSource canvasSource = new DragSource( figureCanvas,
> operations );
> canvasSource.addDragListener(new DragSourceListener()
> {
> public void dragStart(DragSourceEvent event)
> {
> System.out.println("Drag Started");
> IFigure afigure = figureCanvas.getContents().findFigureAt(
> event.display.getCursorLocation().x,
> event.display.getCursorLocation().y);
> System.out.println( afigure );
> }
> public void dragSetData(DragSourceEvent event) {}
> public void dragFinished(DragSourceEvent event){}
>
> });
> shell.open();
> while (!shell.isDisposed())
> while (!display.readAndDispatch())
> display.sleep();
>
> }
> }
>
> Help is appreciated. MM
>
Re: Finding figure under mouse on drag/drop [message #125389 is a reply to message #125350] Thu, 01 April 2004 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mas.nospam.com

Thanks Randy. After I change it to getViewport(), the figure beneath is
still returning null. I am assuming the reason being the location.

Are these calls the right calls to make to get the mouse location or do
they need to be translated relative to something to get the figure?

event.display.getCursorLocation().x;
event.display.getCursorLocation().y);

I am assuming these return the display location but if figures are based
wrt to the panel they are in, then that could be the problem as the
findFigureAt call looks at non-existent place. Could this be the mistake
and if so, can anyone suggest the correct procedure?

~MMS

Randy Hudson wrote:

> It looks like you already have the code. Except instead of calling
> getContents(), which reaches in past the viewport figure, you need to call
> getViewport(). Otherwise you will be incorrect when the figures are
> scrolled.

> "Mas Masoud" <mas@nospam.com> wrote in message
> news:c4fmjn$ivm$1@eclipse.org...
> > How do I identify the figure that is underneath the mouse for the drag
> > operation for the following code?
> >
> > public class DNDTest
> > {
> > public static void main(String[] args)
> > {
> > Display display= new Display();
> > final Shell shell = new Shell(display);
> >
> > shell.setLayout( new GridLayout() );
> >
> > Composite composite = new Composite( shell, SWT.NONE);
> > composite.setLayout( new GridLayout() );
> >
> > final FigureCanvas figureCanvas = new FigureCanvas( composite );
> > Figure panel = new Figure();
> > panel.setLayoutManager( new FlowLayout() );
> > panel.add( new Label("Label1"));
> > panel.add( new Label("Label2"));
> > panel.add( new Label("Label3"));
> > figureCanvas.setContents( panel );
> >
> > // Allow data to be copied or moved from the drag source
> > int operations = DND.DROP_MOVE | DND.DROP_COPY;
> > DragSource canvasSource = new DragSource( figureCanvas,
> > operations );
> > canvasSource.addDragListener(new DragSourceListener()
> > {
> > public void dragStart(DragSourceEvent event)
> > {
> > System.out.println("Drag Started");
> > IFigure afigure = figureCanvas.getContents().findFigureAt(
> > event.display.getCursorLocation().x,
> > event.display.getCursorLocation().y);
> > System.out.println( afigure );
> > }
> > public void dragSetData(DragSourceEvent event) {}
> > public void dragFinished(DragSourceEvent event){}
> >
> > });
> > shell.open();
> > while (!shell.isDisposed())
> > while (!display.readAndDispatch())
> > display.sleep();
> >
> > }
> > }
> >
> > Help is appreciated. MM
> >
Re: Finding figure under mouse on drag/drop [message #125399 is a reply to message #125389] Thu, 01 April 2004 10:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

My fault. Yes, probably want to hook into MousePressed.
DragStart does not occur until after either:
1) a delay
2) the mouse has moved some amount

In the case of 2), the mouse may no longer be over the original mouse-down
location, and you would get the wrong figure.

"Mas Masoud" <mas@nospam.com> wrote in message
news:c4hdjf$9c1$1@eclipse.org...
> Thanks Randy. After I change it to getViewport(), the figure beneath is
> still returning null. I am assuming the reason being the location.
>
> Are these calls the right calls to make to get the mouse location or do
> they need to be translated relative to something to get the figure?
>
> event.display.getCursorLocation().x;
> event.display.getCursorLocation().y);
>
> I am assuming these return the display location but if figures are based
> wrt to the panel they are in, then that could be the problem as the
> findFigureAt call looks at non-existent place. Could this be the mistake
> and if so, can anyone suggest the correct procedure?
>
> ~MMS
>
> Randy Hudson wrote:
>
> > It looks like you already have the code. Except instead of calling
> > getContents(), which reaches in past the viewport figure, you need to
call
> > getViewport(). Otherwise you will be incorrect when the figures are
> > scrolled.
>
> > "Mas Masoud" <mas@nospam.com> wrote in message
> > news:c4fmjn$ivm$1@eclipse.org...
> > > How do I identify the figure that is underneath the mouse for the drag
> > > operation for the following code?
> > >
> > > public class DNDTest
> > > {
> > > public static void main(String[] args)
> > > {
> > > Display display= new Display();
> > > final Shell shell = new Shell(display);
> > >
> > > shell.setLayout( new GridLayout() );
> > >
> > > Composite composite = new Composite( shell, SWT.NONE);
> > > composite.setLayout( new GridLayout() );
> > >
> > > final FigureCanvas figureCanvas = new FigureCanvas( composite );
> > > Figure panel = new Figure();
> > > panel.setLayoutManager( new FlowLayout() );
> > > panel.add( new Label("Label1"));
> > > panel.add( new Label("Label2"));
> > > panel.add( new Label("Label3"));
> > > figureCanvas.setContents( panel );
> > >
> > > // Allow data to be copied or moved from the drag source
> > > int operations = DND.DROP_MOVE | DND.DROP_COPY;
> > > DragSource canvasSource = new DragSource( figureCanvas,
> > > operations );
> > > canvasSource.addDragListener(new DragSourceListener()
> > > {
> > > public void dragStart(DragSourceEvent event)
> > > {
> > > System.out.println("Drag Started");
> > > IFigure afigure = figureCanvas.getContents().findFigureAt(
> > > event.display.getCursorLocation().x,
> > > event.display.getCursorLocation().y);
> > > System.out.println( afigure );
> > > }
> > > public void dragSetData(DragSourceEvent event) {}
> > > public void dragFinished(DragSourceEvent event){}
> > >
> > > });
> > > shell.open();
> > > while (!shell.isDisposed())
> > > while (!display.readAndDispatch())
> > > display.sleep();
> > >
> > > }
> > > }
> > >
> > > Help is appreciated. MM
> > >
>
>
Re: Finding figure under mouse on drag/drop [message #125412 is a reply to message #125399] Thu, 01 April 2004 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mas.nospam.com

Thanks. That helped me move ahead.

I was able to hook a mouseListener and capture the mouse location in the
mousePressed method. This helped the drag operations.

But, when I tried the same for drop, meaning, try to find the mouse
location in the mouseReleased method, it does not seem to get called. Is
this different?

I tried getting the location in DropTargetEvent using the
event.display.getCursorLocation() callback. Does the explaination

"In the case of 2), the mouse may no longer be over the original mouse-down
location, and you would get the wrong figure"

apply to this drop case as well ? Any suggestions here ?

Thanks much,
MMS
Re: Finding figure under mouse on drag/drop [message #125425 is a reply to message #125412] Thu, 01 April 2004 13:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Mouse released does not get called if a native drag starts.
What are you trying to do? You can get the figure under the mouse on
mousedown, and use it whe nthe drag starts.
For DropTargetEvent, the mouse location is provided in the event, so its a
non issue.

"Mas Masoud" <mas@nospam.com> wrote in message
news:c4hhaf$em9$1@eclipse.org...
> Thanks. That helped me move ahead.
>
> I was able to hook a mouseListener and capture the mouse location in the
> mousePressed method. This helped the drag operations.
>
> But, when I tried the same for drop, meaning, try to find the mouse
> location in the mouseReleased method, it does not seem to get called. Is
> this different?
>
> I tried getting the location in DropTargetEvent using the
> event.display.getCursorLocation() callback. Does the explaination
>
> "In the case of 2), the mouse may no longer be over the original
mouse-down
> location, and you would get the wrong figure"
>
> apply to this drop case as well ? Any suggestions here ?
>
> Thanks much,
> MMS
>
>
>
>
Re: Finding figure under mouse on drag/drop [message #125437 is a reply to message #125425] Thu, 01 April 2004 16:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mas.nospam.com

I have a panel of figures that can be arranged by drag/drop means into
slots. Now that I can get hold of figure while the drag is occuring via
the mouseListener mechanism, I have no problems.

With respect to drop, if I drop text onto one of these figures, their
contents should get updated. I am not able to identify the figure on which
the drop happened. Once I can identify that, then it is just a matter of
replacing that figure with a new one at the same location.

My problem is when I get the point via mousePressed event, then I get
something like (24,41) but if I check the same point via DropTargetEvent's
event.x, event.y, the values are something like (246,291) which are not
with in my panel. So, findFigureAt returns null.

Is there a different call that I need to make to get the coordinates where
the drop occured?

Randy Hudson wrote:

> Mouse released does not get called if a native drag starts.
> What are you trying to do? You can get the figure under the mouse on
> mousedown, and use it whe nthe drag starts.
> For DropTargetEvent, the mouse location is provided in the event, so its a
> non issue.

> "Mas Masoud" <mas@nospam.com> wrote in message
> news:c4hhaf$em9$1@eclipse.org...
> > Thanks. That helped me move ahead.
> >
> > I was able to hook a mouseListener and capture the mouse location in the
> > mousePressed method. This helped the drag operations.
> >
> > But, when I tried the same for drop, meaning, try to find the mouse
> > location in the mouseReleased method, it does not seem to get called. Is
> > this different?
> >
> > I tried getting the location in DropTargetEvent using the
> > event.display.getCursorLocation() callback. Does the explaination
> >
> > "In the case of 2), the mouse may no longer be over the original
> mouse-down
> > location, and you would get the wrong figure"
> >
> > apply to this drop case as well ? Any suggestions here ?
> >
> > Thanks much,
> > MMS
> >
> >
> >
> >
Re: Finding figure under mouse on drag/drop [message #125574 is a reply to message #125437] Fri, 02 April 2004 10:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Drop events contain display-relative coordinates. See
control.fromDisplay(point).
You may not be using GEF, but you can find your answers to these problem in
the GEF code.
Specifically, AbstractTransferDropTargetAdapter.

"Mas Masoud " <mas@nospam.com> wrote in message
news:c4i0q1$31e$1@eclipse.org...
> I have a panel of figures that can be arranged by drag/drop means into
> slots. Now that I can get hold of figure while the drag is occuring via
> the mouseListener mechanism, I have no problems.
>
> With respect to drop, if I drop text onto one of these figures, their
> contents should get updated. I am not able to identify the figure on which
> the drop happened. Once I can identify that, then it is just a matter of
> replacing that figure with a new one at the same location.
>
> My problem is when I get the point via mousePressed event, then I get
> something like (24,41) but if I check the same point via DropTargetEvent's
> event.x, event.y, the values are something like (246,291) which are not
> with in my panel. So, findFigureAt returns null.
>
> Is there a different call that I need to make to get the coordinates where
> the drop occured?
>
> Randy Hudson wrote:
>
> > Mouse released does not get called if a native drag starts.
> > What are you trying to do? You can get the figure under the mouse on
> > mousedown, and use it whe nthe drag starts.
> > For DropTargetEvent, the mouse location is provided in the event, so its
a
> > non issue.
>
> > "Mas Masoud" <mas@nospam.com> wrote in message
> > news:c4hhaf$em9$1@eclipse.org...
> > > Thanks. That helped me move ahead.
> > >
> > > I was able to hook a mouseListener and capture the mouse location in
the
> > > mousePressed method. This helped the drag operations.
> > >
> > > But, when I tried the same for drop, meaning, try to find the mouse
> > > location in the mouseReleased method, it does not seem to get called.
Is
> > > this different?
> > >
> > > I tried getting the location in DropTargetEvent using the
> > > event.display.getCursorLocation() callback. Does the explaination
> > >
> > > "In the case of 2), the mouse may no longer be over the original
> > mouse-down
> > > location, and you would get the wrong figure"
> > >
> > > apply to this drop case as well ? Any suggestions here ?
> > >
> > > Thanks much,
> > > MMS
> > >
> > >
> > >
> > >
>
>
Re: Finding figure under mouse on drag/drop [message #125611 is a reply to message #125574] Fri, 02 April 2004 11:44 Go to previous message
Eclipse UserFriend
Originally posted by: mas.nospam.com

Thanks Randy. Suggestions helped quite a bit.

Off to the next steps..

Randy Hudson wrote:

> Drop events contain display-relative coordinates. See
> control.fromDisplay(point).
> You may not be using GEF, but you can find your answers to these problem in
> the GEF code.
> Specifically, AbstractTransferDropTargetAdapter.

> "Mas Masoud " <mas@nospam.com> wrote in message
> news:c4i0q1$31e$1@eclipse.org...
> > I have a panel of figures that can be arranged by drag/drop means into
> > slots. Now that I can get hold of figure while the drag is occuring via
> > the mouseListener mechanism, I have no problems.
> >
> > With respect to drop, if I drop text onto one of these figures, their
> > contents should get updated. I am not able to identify the figure on which
> > the drop happened. Once I can identify that, then it is just a matter of
> > replacing that figure with a new one at the same location.
> >
> > My problem is when I get the point via mousePressed event, then I get
> > something like (24,41) but if I check the same point via DropTargetEvent's
> > event.x, event.y, the values are something like (246,291) which are not
> > with in my panel. So, findFigureAt returns null.
> >
> > Is there a different call that I need to make to get the coordinates where
> > the drop occured?
> >
> > Randy Hudson wrote:
> >
> > > Mouse released does not get called if a native drag starts.
> > > What are you trying to do? You can get the figure under the mouse on
> > > mousedown, and use it whe nthe drag starts.
> > > For DropTargetEvent, the mouse location is provided in the event, so its
> a
> > > non issue.
> >
> > > "Mas Masoud" <mas@nospam.com> wrote in message
> > > news:c4hhaf$em9$1@eclipse.org...
> > > > Thanks. That helped me move ahead.
> > > >
> > > > I was able to hook a mouseListener and capture the mouse location in
> the
> > > > mousePressed method. This helped the drag operations.
> > > >
> > > > But, when I tried the same for drop, meaning, try to find the mouse
> > > > location in the mouseReleased method, it does not seem to get called.
> Is
> > > > this different?
> > > >
> > > > I tried getting the location in DropTargetEvent using the
> > > > event.display.getCursorLocation() callback. Does the explaination
> > > >
> > > > "In the case of 2), the mouse may no longer be over the original
> > > mouse-down
> > > > location, and you would get the wrong figure"
> > > >
> > > > apply to this drop case as well ? Any suggestions here ?
> > > >
> > > > Thanks much,
> > > > MMS
> > > >
> > > >
> > > >
> > > >
> >
> >
Previous Topic:GEF Install
Next Topic:Subpixel antialiasing in vertical text of Logic Demo
Goto Forum:
  


Current Time: Thu May 08 09:53:06 EDT 2025

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

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

Back to the top