简体   繁体   English

如何在SWT UI中检测Draw2D图形上的三击?

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

I want to detect a triple-click on a Draw2D figure. 我想检测Draw2D图形上的三次单击。

This will allow the first click to select the Draw2D figure, the second to expand the selection, and the third to expand it further. 这将允许第一单击以选择Draw2D图形,第二单击以扩展选择,第三单击以进一步扩展选择。

SWT provides the click count in its MouseEvent. SWT在其MouseEvent中提供了点击计数。 However, Draw2D has its own MouseEvent, that does not expose the click count. 但是,Draw2D具有其自己的MouseEvent,它不会公开单击计数。 [See Eclipse bug 516272 . [请参阅Eclipse错误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. 我想尊重OS设置的多次点击速度。 In AWT/Swing, I can get the maximum interval with Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval") . 在AWT / Swing中,我可以使用Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")获得最大间隔。 But I would like to avoid coupling to an AWT class in an SWT application. 但我想避免耦合到SWT应用程序中的AWT类。

Is there a way to get the multi-click interval via the the SWT or Draw2D APIs? 是否可以通过SWT或Draw2D API获得多次单击间隔?

SWT's Display class provides a method getDoubleClickTime() : SWT的Display类提供一种方法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(): 返回两次鼠标单击之间的最长持续时间(以毫秒为单位),这将被基础操作系统视为两次双击。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. 可以跟踪自双击以来的时间,然后在下一次候选鼠标单击上,查看它是否小于该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM