1 | package ai.d.ai01;
|
2 |
|
3 | import drjava.util.GUIUtil;
|
4 | import drjava.util.StringUtil;
|
5 | import prophecy.common.gui.ProphecyFrame;
|
6 | import structcom.sc03.ParserMatch;
|
7 | import structcom.sc03.StdGrammar;
|
8 |
|
9 | import javax.swing.*;
|
10 | import java.util.HashMap;
|
11 | import java.util.List;
|
12 | import java.util.Map;
|
13 |
|
14 | public class ApplicationManagerRunner {
|
15 | private static Map<String, Object> objects = new HashMap<String, Object>();
|
16 |
|
17 | public static void main(String[] args) {
|
18 | String def = "a table of applications.\n" +
|
19 | "a window with the table in it.\n" +
|
20 | "the window is called \"Application Manager\".\n";
|
21 | List<String> lines = toLines(def);
|
22 | for (String line : lines) {
|
23 | // Note: this might mismatch on "a tablecloth" etc., but we don't have that in the target language, so it's ok.
|
24 | if (StdGrammar.matchesFull("\"a table\" optspace rest@any", line)) {
|
25 | store("table", new JScrollPane(new DummyTable()));
|
26 | System.out.println("table made");
|
27 | continue;
|
28 | }
|
29 |
|
30 | if (StdGrammar.matchesFull("\"a window.\"", line)) {
|
31 | store("window", new ProphecyFrame());
|
32 | System.out.println("window made");
|
33 | continue;
|
34 | }
|
35 |
|
36 | ParserMatch match = StdGrammar.matchFullSilent("\"a window with the \" thing@word \" in it.\"", line);
|
37 | if (match != null) {
|
38 | String thing = match.getLabeledString("thing");
|
39 | JComponent component = (JComponent) objects.get(thing);
|
40 | ProphecyFrame window = new ProphecyFrame();
|
41 | window.getContentPane().add(component);
|
42 | store("window", window);
|
43 | System.out.println("window made with " + component);
|
44 | continue;
|
45 | }
|
46 |
|
47 | match = StdGrammar.matchFullSilent("\"the window is called\" space name@stringlit \".\"", line);
|
48 | if (match != null) {
|
49 | ProphecyFrame window = (ProphecyFrame) objects.get("window");
|
50 | String name = StdGrammar.unquote(match.getLabeledString("name"));
|
51 | window.setTitle(name);
|
52 | System.out.println("window is now labeled: " + name);
|
53 | continue;
|
54 | }
|
55 |
|
56 | throw new RuntimeException("huch: " + line);
|
57 | }
|
58 |
|
59 | ProphecyFrame window = (ProphecyFrame) objects.get("window");
|
60 | if (window != null)
|
61 | GUIUtil.showFrame(window);
|
62 | else
|
63 | System.out.println("No window defined, exiting...");
|
64 | }
|
65 |
|
66 | private static void store(String name, Object object) {
|
67 | objects.put(name, object);
|
68 | }
|
69 |
|
70 | private static List<String> toLines(String def) {
|
71 | return StringUtil.toLines(def);
|
72 | }
|
73 | }
|