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

73
LINES

< > BotCompany Repo | #280 // ApplicationManagerRunner

Document

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<String, Object> objects = new HashMap<String, Object>();

  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<String> 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<String> toLines(String def) {
    return StringUtil.toLines(def);
  }
}

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 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

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: 726 / 191
Referenced in: [show references]