[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: can i get the 'absolute' shell relative x and y values of a MouseEvent?
|
- From: evansac@xxxxxxxxxxx (Alun)
- Date: Thu, 17 Apr 2003 22:35:12 +0000 (UTC)
- Newsgroups: eclipse.tools
- Organization: http://www.eclipse.org
- User-agent: NewsPortal 0.23
Hi Moritz,
Is this what you want? I've used canvases instead of tables as
they're easier to create, but if you click on the red canvas and
drag and drop (ie. release the mouse) on the blue canvas then
it will print out the mouse coordinates relative to the blue
canvas. Goes the other way too.
Cheers,
Alun
PS. Check out the new SWT newsgroup.
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
GridLayout gridLayout = new GridLayout(2, true);
shell.setLayout(gridLayout);
final Canvas c1 = new Canvas(shell, SWT.NONE);
c1.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
c1.setLayoutData(new GridData(GridData.FILL_BOTH));
final Canvas c2 = new Canvas(shell, SWT.NONE);
c2.setBackground(display.getSystemColor(SWT.COLOR_RED));
c2.setLayoutData(new GridData(GridData.FILL_BOTH));
c1.addListener(SWT.MouseUp, new Listener()
{
public void handleEvent(Event e)
{
if(display.getCursorControl() == c2)
{
System.out.println(c2.toControl(c1.toDisplay(e.x, e.y)));
}
}
});
c2.addListener(SWT.MouseUp, new Listener()
{
public void handleEvent(Event e)
{
if(display.getCursorControl() == c1)
{
System.out.println(c1.toControl(c2.toDisplay(e.x, e.y)));
}
}
});
shell.setSize(400, 300);
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
Moritz Angermann wrote:
> i have the following problem:
> i have two tables beneath each other in a sash.
> now i want to 'fake' drang'n'drop one item form the one table into the
> other table.
> ( but i actually just want to get the item from table1 and from table2 )
> so i can work with them.
> thus it's no real drag n drop.
> i tryed to get this done with the event's X/Y position when the mouse is
> pressed and released.
> but it looks like if i press the mousebutton on table1 and release it on
> table2, table1 gets the release event. thus i can't deal with the x/y
> values of the element, since they are relative to table1 not table2.
> thanks in advance!
> reg.
> moritz