Search code examples
javaswtdraw2d

How to detect triple-click on Draw2D figure in SWT UI?


I want to detect a triple-click on a Draw2D figure.

This will allow the first click to select the Draw2D figure, the second to expand the selection, and the third to expand it further.

SWT provides the click count in its MouseEvent. However, Draw2D has its own MouseEvent, that does not expose the click count. [See Eclipse bug 516272. ]

I can detect the third mouse click as an independent event, and determine if it happened soon enough after the last double-click.

I would like to respect the OS settings for multi-click speed. In AWT/Swing, I can get the maximum interval with Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval"). But I would like to avoid coupling to an AWT class in an SWT application.

Is there a way to get the multi-click interval via the the SWT or Draw2D APIs?


Solution

  • SWT's Display class provides a method getDoubleClickTime():

    public int getDoubleClickTime()

    Returns the longest duration, in milliseconds, between two mouse button clicks that will be considered a double click by the underlying operating system.getDoubleClickTime():

    For example:

        int doubleClickTime = Display.getDefault().getDoubleClickTime();
    

    One can track the time since the double-click, and on the next candidate mouse click, see if it's less than the that value.