01: /*
02: * @(#)useEventThread.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package pnuts.awt;
10:
11: import pnuts.lang.*;
12:
13: public class useEventThread extends PnutsFunction {
14:
15: private final static String BACKUP_CONF = "pnuts.awt.conf.backup"
16: .intern();
17: private final static String EVENT_CONF = "pnuts.awt.conf.event"
18: .intern();
19:
20: public useEventThread() {
21: super ("useEventThread");
22: }
23:
24: public boolean defined(int nargs) {
25: return nargs < 2;
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: int nargs = args.length;
30: if (nargs == 0) {
31: if (context.getConfiguration() instanceof EventQueueConfiguration) {
32: return Boolean.TRUE;
33: } else {
34: return Boolean.FALSE;
35: }
36: } else if (nargs == 1) {
37: if (((Boolean) args[0]).booleanValue()) {
38: Configuration c1 = (Configuration) context
39: .get(EVENT_CONF);
40: if (c1 == null) {
41: Configuration c2 = context.getConfiguration();
42: c1 = new EventQueueConfiguration(c2);
43: context.set(EVENT_CONF, c1);
44: context.set(BACKUP_CONF, c2);
45: }
46: context.setConfiguration(c1);
47: } else {
48: Configuration c = (Configuration) context
49: .get(BACKUP_CONF);
50: if (c != null) {
51: context.set(EVENT_CONF, null);
52: context.set(BACKUP_CONF, null);
53: context.setConfiguration(c);
54: }
55: }
56: return null;
57: } else {
58: undefined(args, context);
59: return null;
60: }
61: }
62:
63: public String toString() {
64: return "function useEventThread({boolean})";
65: }
66: }
|