|
Re: is it possible to calculate a list index from a mouse point [message #731056 is a reply to message #731046] |
Thu, 29 September 2011 19:22 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Here's a utility method we use in EMF that might help get you
started:<br>
<small><br>
/**<br>
* This returns the location of the mouse in the vertical
direction, relative<br>
* to the item widget, from 0 (top) to 1 (bottom).<br>
*/<br>
protected float getLocation(DropTargetEvent event) <br>
{<br>
if (event.item instanceof TreeItem)<br>
{<br>
TreeItem treeItem = (TreeItem)event.item;<br>
Control control = treeItem.getParent();<br>
Point point = control.toControl(new Point(event.x,
event.y));<br>
Rectangle bounds = treeItem.getBounds();<br>
return (float)(point.y - bounds.y) / (float)bounds.height;<br>
}<br>
else if (event.item instanceof TableItem)<br>
{<br>
TableItem tableItem = (TableItem)event.item;<br>
Control control = tableItem.getParent();<br>
Point point = control.toControl(new Point(event.x,
event.y));<br>
Rectangle bounds = tableItem.getBounds(0);<br>
return (float)(point.y - bounds.y) / (float)bounds.height;<br>
}<br>
else<br>
{<br>
return 0.0F;<br>
}<br>
}</small><br>
<br>
I forget how we deal with list views in EMF. You can always use a
table with a single column...<br>
<br>
<br>
On 29/09/2011 11:52 AM, mfishm1 wrote:
<blockquote cite="mid:j62e2r$j13$1@news.eclipse.org" type="cite">I
have a List component and am trying to implement a capability
where a user can click on a selected item and drags it up and down
in the list using the mouse. I also need to support if someone
drags from another list into this one. I think that I have a
handle on most of the problem but I don't see an easy way to
figure out the index in the list that I am over when the user does
the drop. Does anyone have any suggestions?
<br>
<br>
Thanks.
<br>
</blockquote>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04799 seconds