Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » "Relative to display" To "Relative to TableItem"
"Relative to display" To "Relative to TableItem" [message #465177] Thu, 08 December 2005 00:35 Go to next message
Eclipse UserFriend
Originally posted by: dank.webreachinc.com

Hello,

To make a long story short, I've got coordinates that are relative to the
display. I want to find out which TableItem in a table this coordinate is
refering to.

Here's the long story: I've implemented some drag and drop functionality
between two tables on my UI. You can drag a row from one table and drop
it into the other table. When you drop it, I need to figure out where the
mouse was when the user released the mouse's button. This is how I will
figure out *where* to insert the item that was dragged. I tried adding a
mouse adapter on the target, but mouseup() doesn't get triggered from a
(drag and) drop.

The DropTargetEvent does come with a .x and a .y that are filled with
coordinates but they are relative to the display. I can go through every
tableitem and use getBounds to get it's coordinates but these coordinates
will be relative to the table, not the display.

It seems insanely hard/impossible to accomplish this. How do i convert
"Relative to Display" coordinates into "Relative to some-part-of-the-UI"
coordinates and/or vice versa?

Thanks for the help,
Dan
Re: "Relative to display" To "Relative to TableItem" [message #465190 is a reply to message #465177] Thu, 08 December 2005 01:48 Go to previous message
Eclipse UserFriend
Originally posted by: dank.webreachinc.com

I found the answer and I feel i should give back by explaining it. This
is what you do:

private int getIndexToInsertFrom(DropTargetEvent event) {

Point p = table.getDisplay().map(null, table, event.x, event.y);

TableItem [] items = table.getItems();

for (int i = 0; i < items.length; ++i) {
TableItem itemAtPoint = table.getItem(p);
TableItem item = items[i];
if (item.equals(itemAtPoint)) {
return i;
}
}
return -1;
}
Previous Topic:test
Next Topic:Running SWT application outside Eclipse
Goto Forum:
  


Current Time: Mon Dec 09 08:36:14 GMT 2024

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

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

Back to the top