org.gnu.glib

Class Idle

public final class Idle extends Object

Idle: an object that executes a Fireable target object's fire method at the next available time. Similar to Swing's invokeLater functionality.

For example, here's how an application clock might be implemented, where the application passes in an {@link org.gnu.gtk.Label} object as its pane:

 private Idle later = new Idle(100,
         new Fireable() {
             public boolean fire() {
                 String dateStr = DateFormat.getDateInstance()
                         .format(new Date());
                 System.out.println("Invoked later!" + dateStr);
                 return true; // continue firing
             }
         });
 later.start();
 

Note: an Idle generates events on the application's GUI event queue. It also should only be used to directly fire short/fast methods. Longer methods need to be executed in a separate thread.

See Also: Fireable Timer

Constructor Summary
Idle(int priority, Fireable target)
Create a new Idle object.
Idle(Fireable target)
Create a new Idle object.
Method Summary
intgetPriority()
Returns the execution priority for this Idle.
booleanisRunning()
Returns whether this idle is running.
voidsetPriority(int priority)
Set the execution priority for this Idle.
voidstart()
Start this Idle object; that is, begin executing its fire method at the available execution slot in the mainloop.
voidstop()
Stop this idle object; that is, stop executing its fire method at its specified interval.

Constructor Detail

Idle

public Idle(int priority, Fireable target)
Create a new Idle object.

Parameters: priority The execution priority of the object, from 0 (highest priority) to Integer.MAX_VALUE (lowest priority). target the object whose fire() method gets called after the specified time period elapses.

Throws: IllegalArgumentException if less than zero.

Idle

public Idle(Fireable target)
Create a new Idle object.

Parameters: target the object whose fire() method gets called after the specified time period elapses.

Throws: IllegalArgumentException if less than zero.

Method Detail

getPriority

public final int getPriority()
Returns the execution priority for this Idle.

Returns: the priority of this Idle, from 0 (highest priority) to Integer.MAX_VALUE (lowest priority)

isRunning

public final boolean isRunning()
Returns whether this idle is running.

Returns: true if this idle is currently running.

setPriority

public final void setPriority(int priority)
Set the execution priority for this Idle.

Parameters: priority The execution priority of the object, from 0 (highest priority) to Integer.MAX_VALUE (lowest priority).

Throws: IllegalArgumentException if less than zero.

start

public final void start()
Start this Idle object; that is, begin executing its fire method at the available execution slot in the mainloop.

stop

public final void stop()
Stop this idle object; that is, stop executing its fire method at its specified interval. This method does not need to be called if the fire method returned false.