return null;
} });
- new Thread() { public void run() { Scheduler.singleton.run(); } }.start();
+ new Thread() { public void run() { Scheduler.init(); } }.start();
Platform.running();
}
/** Implements cooperative multitasking */
public class Scheduler {
- public static final Scheduler singleton = Platform.getScheduler();
- protected Scheduler() { }
+ // Public API Exposed to org.xwt /////////////////////////////////////////////////
public static abstract class Task { public abstract void perform(); }
+ public static void add(Task t) { singleton.runnable.append(t); }
+ public static void init() { singleton.run(); }
+
+
+ // API which must be supported by subclasses /////////////////////////////////////
+
+ protected Scheduler() { }
+
+ /**
+ * INVARIANT: all scheduler implementations MUST invoke
+ * Surface.renderAll() after performing a Task if no tasks remain
+ * in the queue. A scheduler may choose to invoke
+ * Surface.renderAll() more often than that if it so chooses.
+ */
+ public void run() { defaultRun(); }
+
+
+ // Default Implementation /////////////////////////////////////
protected static Queue runnable = new Queue(50);
- public static void add(Task t) { singleton.runnable.append(t); }
- public void run() {
+ private static final Scheduler singleton = Platform.getScheduler();
+ public void defaultRun() {
while(true) {
Task t = (Task)runnable.remove(true);
try {
t.perform();
// FIXME: be smarter about this
- for(int i=0; i<Surface.allSurfaces.size(); i++)
- ((Surface)Surface.allSurfaces.elementAt(i)).render();
+ Surface.renderAll();
} catch (Exception e) {
Log.log(Scheduler.class, "Task threw an exception: " + e);
Log.log(Scheduler.class, e);
protected final void Focused(boolean b) { new SimpleMessage("Focused", b ? Boolean.TRUE : Boolean.FALSE, root); }
public static void Refresh() {
Scheduler.add(new Scheduler.Task() { public void perform() {
- for(int i=0; i<allSurfaces.size(); i++)
- ((Surface)allSurfaces.elementAt(i)).render();
+ renderAll();
}}); }
+ public static void renderAll() {
+ for(int i=0; i<allSurfaces.size(); i++)
+ ((Surface)allSurfaces.elementAt(i)).render();
+ }
+
public final void setMaximized(boolean b) { if (b != maximized) _setMaximized(maximized = b); }
public final void setMinimized(boolean b) { if (b != minimized) _setMinimized(minimized = b); }
/** A sensible implementation of the abstract methods in the JS class */
public static class Obj extends JS {
+
+ // FIXME: move these to an interface so they're optional
// this gets around a wierd fluke in the Java type checking rules for ?..:
public static final Object T = Boolean.TRUE;
public static final Object F = Boolean.FALSE;
+
+ // FIXME: be smart here; perhaps intern
+ public static final Number N(int i) { return new Integer(i); }
+ public static final Number N(long l) { return new Long(l); }
+ public static final Number N(double d) { return new Double(d); }
+
+ public static final Boolean B(boolean b) { return b ? Boolean.TRUE : Boolean.FALSE; }
+
private Hash entries = null;
private boolean sealed = false;
public Obj() { this(false); }