Overview

It is often useful for background tasks to be triggered when there has been a perion of inactivity in the (Swing) UI. This class makes use of IdleMonitorEventQueue, which keeps track of the last activity in the UI.

The IdleMonitor is created with the amount of idle time to trigger the action, and the (Runnable) action to be taken. It creates a separate background thread to monitor activity and take the action. The additional parameter used to create it is the name of this (daemon) thread.

Example

        Runnable notifier = new Runnable() {
            public void run() {
                System.out.println("No recent UI activity.");
            }
        };
        IdleMonitor monitor = new IdleMonitor("Notifier", 60000, notifier);

This would begin running immediately. It will awaken roughly every one minute, and will check if there has been any UI activity in the last minute. If not, it will execute the runnable (which just prints output).

It is also possible to manually trigger it:

        monitor.manualTrigger();

This will interrupt the thread and force it to execute the runnable.

It is also possible to "touch" the UI activity flag, to make it appear that there was recent activity (so a separate background task can force another wait cycle):

        IdleMonitorEventQueue.touch();

Project Overview