|
|
|
Re: Invoking action after period of inactivity [message #661388 is a reply to message #660069] |
Thu, 24 March 2011 13:47 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
FWIW using Display.timerExec() may be a bit lighter-weight, demonstrated
below:
public class Main {
public static void main(String[] args) {
final int TIMEOUT = 5000;
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
new Text(shell, SWT.MULTI);
final Runnable runnable = new Runnable() {
public void run() {
System.out.println("no activity for " + TIMEOUT + " ms");
display.timerExec(TIMEOUT, this);
}
};
Listener listener = new Listener() {
public void handleEvent(Event event) {
display.timerExec(-1, runnable); // cancel
display.timerExec(TIMEOUT, runnable);
}
};
display.addFilter(SWT.MouseDown, listener);
display.addFilter(SWT.MouseUp, listener);
display.addFilter(SWT.MouseMove, listener);
display.addFilter(SWT.MouseWheel, listener);
display.addFilter(SWT.KeyDown, listener);
display.addFilter(SWT.KeyUp, listener);
display.timerExec(TIMEOUT, runnable);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"Tom Quarendon" <tomq@teamwpc.co.uk> wrote in message
news:ilqsrs$nrm$1@news.eclipse.org...
> Yes, that's the pattern I came up with in the end. The key is being able
> to cancel and reschedule the Job, so that it only goes off after there
> really has been the required delay.
>
|
|
|
Powered by
FUDForum. Page generated in 0.03698 seconds