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

92
LINES

< > BotCompany Repo | #1001410 // Smart Editor (developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1481L/10K/34K).

!747
!awt {

m {
  static JTextArea textArea;
  static S textLogged;

  static L<S> actions = new LoggingStringList("actions.log");
  
  !include #1001455 // LoggingStringList
  
  p {
    textArea = makeTextArea();
    addAction("new");
    
    makeAndroid3("Smart Editor.");
  }
  
  static void addAction(S s) {
    actions.add(now() + " " + s);
  }

  static JTextArea makeTextArea() {
    new JTextArea textArea;
    makeFrame("Smart Editor", new JScrollPane(textArea));
    return textArea;
  }
  
  static void logText() {
    S text = getText();
    if (!eq(text, textLogged)) {
      textLogged = text;
      addAction(format3("text is *", text));
    }
  }
  
  static synchronized S answer(S s, L<S> history) {
    addAction("? " + s);
    try {
      S a = answer_impl(s, history);
      addAction("! " + a);
      ret a;
    } catch (Throwable e) {
      addAction("!!! " + getStackTrace(e));
      ret "Error. " + e.toString();
    }
  }
    
  static synchronized S answer_impl(S s, L<S> history) {
    new Matches m;
    
    if (match3("load *", s, m)) {
      addAction(s);
      S what = unquote(m.m[0]);
      S text = null;
      if (isURL(what))
        text = loadPage(what);
      else
        text = loadTextFile(what);
      if (text != null)
        setText(text);
      else {
        addAction("huh?");
        ret "huh?";
      }
      logText();
      ret format3("OK, loaded *", what);
    }
    
    if (match3("drop first line", s))
      setText(fromLines(dropFirst(1, toLines(getText()))));
      
    if (match3("save", s)) {
      logText();
      ret "OK.";
    }
      
    !include #1001452 // Apply Translator
    
    ret null;
  }
  
  static S getText() {
    return textArea.getText();
  }
  
  static void setText(final S s) {
    awt { // let's be clear here...
      textArea.setText(s);
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001410
Snippet name: Smart Editor (developing)
Eternal ID of this version: #1001410/1
Text MD5: d788ec0b6472dfc7379a4ab652ea635e
Transpilation MD5: 453cc5e67a3e844f4317c35f5ce28e02
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-16 20:38:11
Source code size: 1940 bytes / 92 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 751 / 1319
Referenced in: [show references]