[java-gnome-hackers] API proposal: org.gnu.gdk.Timer
Brought to you by:
afcowie
From: Tom B. <Tom...@Su...> - 2003-02-21 07:07:44
|
Although there isn't an equivalent class in GNOME, I'd like to propose adding a timer class to Java-GNOME. There is a timeout facility in GObject, but it involves several API that aren't implemented and IMHO doesn't easily map to Java concepts. Timers are really useful for various UI metaphors; in my case, I need one to report status in a system monitoring app. Instead, attached is a proposed Timer class which seems to belong in org.gnu.gdk. To use, a developer subclasses it, implements its "run()" method, and specifies a time interval. This method is executed when the interval elapses as if it were an event -- same GLib Main event loop, same thread, etc. It should therefore be safe to execute any valid GNOME code within the run method without thread safety or other worries. Here's a simple clock label class, which an application might use in its status line: import org.gnu.gtk.Label; import org.gnu.gdk.Timer; import java.text.DateFormat; import java.util.Date; public class Clock extends Timer { private Label clockPane; public Clock(Label pane) { super(1000); // 1 second timer interval clockPane = pane; start(); } public void run() { String dateStr = DateFormat.getDateInstance().format(new Date()); clockPane.setText(dateStr); } } Please review the attached, and bring up any problems or improvements you can think of. Once the idea is accepted and the API agreed upon, I'll go ahead and implement the native methods. Tom |