Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Decide between single and double click
Decide between single and double click [message #503711] Tue, 15 December 2009 12:43 Go to next message
Catalin Tileaga is currently offline Catalin TileagaFriend
Messages: 6
Registered: December 2009
Junior Member
In a table I need an action for single click and another action for double click. I use this code:
thisMouseListener = new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("Double click");
}

@Override
public void mouseDown(MouseEvent e) {
System.out.println("Single click");
}
}

The problem is that in RWT there is no MouseEvent.count attribute (like in SWT) and for an double click, I'll receive 2 single click events and 1 double click event. But I do not one to execute the 2 single code events in the case of a double click. Does anyone has an idea how can I decide between them?

Thanks in advance,
Catalin
Re: Decide between single and double click [message #504051 is a reply to message #503711] Wed, 16 December 2009 22:51 Go to previous messageGo to next message
Austin Riddle is currently offline Austin RiddleFriend
Messages: 128
Registered: July 2009
Senior Member
Hello Catalin,

As it stands now, it depends on your platform, the browser, and how fast you click.

On my Windows 7 machine, You cannot avoid at least receiving 1 single click event with a double click event. And the order that these occur in depends on the browser:

(normal double clicking)
IE 8.0 - Single, Double, Single
FF 3.5 - Single, Double, Single
Chrome 3.3 - Single, Double, Single

(ultra fast double clicking)
IE 8.0 - Single, Double, Single
FF 3.5 - Double, Single, Single
Chrome 3.0 - Double, Single, Single

To eliminate the second single click event you can use this or similar code:

boolean doubleClick = false;
@Override
public void mouseDoubleClick(MouseEvent e)
{
System.out.println("Double Click "+e.time);
doubleClick = true;
}
@Override
public void mouseUp(MouseEvent e)
{
if (!doubleClick) {
System.out.println("Single Click "+e.time);
}
else {
doubleClick = false;
}
}

Another way is to use the time field of the MouseEvent.

Hope this helps.
Re: Decide between single and double click [message #504140 is a reply to message #503711] Thu, 17 December 2009 07:16 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Is using a SelectionListener an option for you? Its
widgetDefaultSelected() method is called if an item was selected by
double-clicking it.

HTH
Rüdiger

On 15.12.2009 13:43, Catalin Tileaga wrote:
> In a table I need an action for single click and another action for
> double click. I use this code:
> thisMouseListener = new MouseAdapter() {
> @Override
> public void mouseDoubleClick(MouseEvent e) {
> System.out.println("Double click");
> }
>
> @Override
> public void mouseDown(MouseEvent e) {
> System.out.println("Single click");
> }
> }
>
> The problem is that in RWT there is no MouseEvent.count attribute (like
> in SWT) and for an double click, I'll receive 2 single click events and
> 1 double click event. But I do not one to execute the 2 single code
> events in the case of a double click. Does anyone has an idea how can I
> decide between them?
>
> Thanks in advance,
> Catalin
>
Re: Decide between single and double click [message #504151 is a reply to message #503711] Thu, 17 December 2009 08:31 Go to previous message
Catalin Tileaga is currently offline Catalin TileagaFriend
Messages: 6
Registered: December 2009
Junior Member
Hi,

thank you first for the answers. At the end I found a solution. It's a combination between your ideas.

Here is my solution in case that some is also interested:

selectionListener = new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
// double click behavior
System.out.println("Double-click");
}

public void widgetSelected(final SelectionEvent e) {
// single click behavior
Display display = Display.getDefault();
display.timerExec(display.getDoubleClickTime(), new Runnable() {
public void run() {
if (mouseDoubleClick) {
return;
}
System.out.println("Single-click");
});
}
}

Regards,
Catalin
Previous Topic:StackOverflowError in ViewStackPresentation (Business, Fancy)
Next Topic:TypeError: $0 is null
Goto Forum:
  


Current Time: Thu Apr 25 23:02:36 GMT 2024

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

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

Back to the top