package ai.d.ai01; import drjava.util.GUIUtil; import drjava.util.StringUtil; import prophecy.common.gui.ProphecyFrame; import structcom.sc03.ParserMatch; import structcom.sc03.StdGrammar; import javax.swing.*; import java.util.HashMap; import java.util.List; import java.util.Map; public class ApplicationManagerRunner { private static Map objects = new HashMap(); public static void main(String[] args) { String def = "a table of applications.\n" + "a window with the table in it.\n" + "the window is called \"Application Manager\".\n"; List lines = toLines(def); for (String line : lines) { // Note: this might mismatch on "a tablecloth" etc., but we don't have that in the target language, so it's ok. if (StdGrammar.matchesFull("\"a table\" optspace rest@any", line)) { store("table", new JScrollPane(new DummyTable())); System.out.println("table made"); continue; } if (StdGrammar.matchesFull("\"a window.\"", line)) { store("window", new ProphecyFrame()); System.out.println("window made"); continue; } ParserMatch match = StdGrammar.matchFullSilent("\"a window with the \" thing@word \" in it.\"", line); if (match != null) { String thing = match.getLabeledString("thing"); JComponent component = (JComponent) objects.get(thing); ProphecyFrame window = new ProphecyFrame(); window.getContentPane().add(component); store("window", window); System.out.println("window made with " + component); continue; } match = StdGrammar.matchFullSilent("\"the window is called\" space name@stringlit \".\"", line); if (match != null) { ProphecyFrame window = (ProphecyFrame) objects.get("window"); String name = StdGrammar.unquote(match.getLabeledString("name")); window.setTitle(name); System.out.println("window is now labeled: " + name); continue; } throw new RuntimeException("huch: " + line); } ProphecyFrame window = (ProphecyFrame) objects.get("window"); if (window != null) GUIUtil.showFrame(window); else System.out.println("No window defined, exiting..."); } private static void store(String name, Object object) { objects.put(name, object); } private static List toLines(String def) { return StringUtil.toLines(def); } }