Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

73
LINES

< > BotCompany Repo | #280 - ApplicationManagerRunner

Document

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  
}

Author comment

A Java class. Works. (Well, the table has dummy contents.) See http://tinybrain.blog.de/2014/09/03/let-s-program-in-poems-19322169/

download  show line numbers   

Travelled to 8 computer(s): aoiabmzegqzx, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 2548 [visualize]

Snippet ID: #280
Snippet name: ApplicationManagerRunner
Eternal ID of this version: #280/1
Text MD5: c778ab4f6d7eed0f606bf1886c7523ca
Author: stefan
Category:
Type: Document
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2014-09-03 19:59:32
Source code size: 2548 bytes / 73 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 502 / 110
Referenced in: [show references]

Formerly at http://tinybrain.de/280 & http://280.tinybrain.de