/* Author: Jeff Dalton * Updated: Fri Nov 24 16:27:32 2000 by Jeff Dalton * Copyright: (c) 2000, AIAI, University of Edinburgh */ package ix.examples; import java.util.*; import ix.util.*; import ix.util.lisp.*; /** * A simple example using an I-X framework. This example shows how * to define and use new Controller and IssueHandler subclasses.

* * It also shows how to use PicoIX by defining a PicoIX subclass * that contains the application. */ public class PicoIXTest2 extends PicoIX { /** * Main program. */ public static void main(String[] argv) { IX_System example = new IX_System(new TestController(), null); example.addIssueHandlers(makeTestIssueHandlers()); example.setListener(new IX_SystemListener()); example.start(); example.newEvent (new Issue("twice", new Issue("return", "hello"))); example.newEvent (new Issue("stop")); } /** * A Controller that supports pushIssue(). */ static class TestController extends Controller { TestController() {} protected void pushIssue(Issue i) { // move to subclass /\/ Debug.noteln("Pushing", i); issues.pushElement(i); } } /** * IssueHandlers that can use pushIssue(). */ static abstract class TestIssueHandler extends IssueHandler { TestIssueHandler(Object verb) { super(verb); } void pushIssue(Issue i) { ((TestController)system.controller).pushIssue(i); } } /** * Create issue handlers as "instant" subclasses of TestIssueHandler. */ static Object[] makeTestIssueHandlers() { return new Object[] { // Post an issue twice. new TestIssueHandler("twice") { void handleIssue(Issue i) { pushIssue((Issue)i.object); pushIssue((Issue)i.object); } }, // Send something to the listener. new TestIssueHandler("return") { void handleIssue(Issue i) { system.notifyListener(i.object); } }, // Stop the system. new TestIssueHandler("stop") { void handleIssue(Issue i) { system.stop(); } } }; } }