source: trunk/src/org/expeditee/gio/MiscManager.java@ 1097

Last change on this file since 1097 was 1097, checked in by davidb, 6 years ago

Newly structured files from Corey's work on logic/graphics separation

File size: 1.6 KB
Line 
1package org.expeditee.gio;
2
3import org.expeditee.core.BlockingRunnable;
4
5/** TODO: Comment. cts16 */
6public abstract class MiscManager {
7
8 /**
9 * Causes the machine the interface is running on to make a "beep" sound.
10 */
11 public abstract void beep();
12
13 /** TODO: Comment. cts16 */
14 public abstract boolean browse(String url);
15
16 /** TODO: Comment. cts16 */
17 public abstract String print(String file);
18
19 /** TODO: Comment. cts16 */
20 public abstract String open(String file);
21
22 /**
23 * Runs the given routine on the dedicated GIO event thread, if the GIO system has one.
24 *
25 * @param routine
26 * Should be a BlockingRunnable if this method should block until
27 * the routine has finished, or an ordinary runnable if not.
28 */
29 public void runOnGIOThread(Runnable routine)
30 {
31 // Can't run nothing
32 if (routine == null) return;
33
34 // If given a blocking runnable, don't return until it has executed
35 if (routine instanceof BlockingRunnable) {
36 // If we are the GIO thread, can run now
37 if (isGIOThread()) {
38 routine.run();
39
40 // Otherwise schedule and block
41 } else {
42 scheduleRunnable(routine);
43 ((BlockingRunnable) routine).blockUntilDone();
44 }
45
46 // If not a blocking runnable, just schedule the routine for later and return
47 } else {
48 scheduleRunnable(routine);
49 }
50 }
51
52 /**
53 * Schedules a runnable to be executed at some future time on the GIO thread.
54 */
55 protected abstract void scheduleRunnable(Runnable routine);
56
57 /**
58 * Returns true if the calling thread is the dedicated GIO thread,
59 * or false if any other thread.
60 */
61 protected abstract boolean isGIOThread();
62
63}
Note: See TracBrowser for help on using the repository browser.