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).

1  
!747
2  
!awt {
3  
4  
m {
5  
  static JTextArea textArea;
6  
  static S textLogged;
7  
8  
  static L<S> actions = new LoggingStringList("actions.log");
9  
  
10  
  !include #1001455 // LoggingStringList
11  
  
12  
  p {
13  
    textArea = makeTextArea();
14  
    addAction("new");
15  
    
16  
    makeAndroid3("Smart Editor.");
17  
  }
18  
  
19  
  static void addAction(S s) {
20  
    actions.add(now() + " " + s);
21  
  }
22  
23  
  static JTextArea makeTextArea() {
24  
    new JTextArea textArea;
25  
    makeFrame("Smart Editor", new JScrollPane(textArea));
26  
    return textArea;
27  
  }
28  
  
29  
  static void logText() {
30  
    S text = getText();
31  
    if (!eq(text, textLogged)) {
32  
      textLogged = text;
33  
      addAction(format3("text is *", text));
34  
    }
35  
  }
36  
  
37  
  static synchronized S answer(S s, L<S> history) {
38  
    addAction("? " + s);
39  
    try {
40  
      S a = answer_impl(s, history);
41  
      addAction("! " + a);
42  
      ret a;
43  
    } catch (Throwable e) {
44  
      addAction("!!! " + getStackTrace(e));
45  
      ret "Error. " + e.toString();
46  
    }
47  
  }
48  
    
49  
  static synchronized S answer_impl(S s, L<S> history) {
50  
    new Matches m;
51  
    
52  
    if (match3("load *", s, m)) {
53  
      addAction(s);
54  
      S what = unquote(m.m[0]);
55  
      S text = null;
56  
      if (isURL(what))
57  
        text = loadPage(what);
58  
      else
59  
        text = loadTextFile(what);
60  
      if (text != null)
61  
        setText(text);
62  
      else {
63  
        addAction("huh?");
64  
        ret "huh?";
65  
      }
66  
      logText();
67  
      ret format3("OK, loaded *", what);
68  
    }
69  
    
70  
    if (match3("drop first line", s))
71  
      setText(fromLines(dropFirst(1, toLines(getText()))));
72  
      
73  
    if (match3("save", s)) {
74  
      logText();
75  
      ret "OK.";
76  
    }
77  
      
78  
    !include #1001452 // Apply Translator
79  
    
80  
    ret null;
81  
  }
82  
  
83  
  static S getText() {
84  
    return textArea.getText();
85  
  }
86  
  
87  
  static void setText(final S s) {
88  
    awt { // let's be clear here...
89  
      textArea.setText(s);
90  
    }
91  
  }
92  
}

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