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

124
LINES

< > BotCompany Repo | #1010354 // editJavaXSnippet using JTextArea [v2, dev.]

JavaX fragment (include)

1  
static editJavaXSnippet_Editor editJavaXSnippet(fS snippetID) {
2  
  ret swingConstruct(editJavaXSnippet_Editor, snippetID);
3  
}
4  
5  
sclass editJavaXSnippet_Editor {
6  
  S snippetID;
7  
  JTextArea textArea;
8  
  JButton btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload;
9  
  L<JButton> buttons;
10  
  int snippetType;
11  
  JLabel lblStatus;
12  
13  
  *(S _snippetID) {
14  
    snippetID = formatSnippetID(_snippetID);
15  
    showFrame(snippetID,
16  
      centerAndSouth(textArea = typeWriterTextArea(),
17  
        lblStatus = jlabel()));
18  
    frameIcon(textArea, #1004655);
19  
    
20  
    addFrameMenu(textArea, "File",
21  
      "Reload from server", r { reload() },
22  
      "Butter-Reload", r { eleuReload() });
23  
      
24  
    addDirectMenuItem(textArea, "Run!", r { nohupJavax(snippetID) });
25  
    
26  
    thread {
27  
      setFrameTitle(textArea, "E: " + getSnippetTitle(snippetID) + " [" + snippetID + "]");
28  
    }
29  
  
30  
    // Customize text area
31  
    textArea.setTabSize(2);
32  
33  
    lblStatus.setText("Loading...");
34  
    
35  
    btnSave = new JButton("Save on server");
36  
    btnSave.addActionListener(actionListener { saveSnippet(null); });
37  
    
38  
    btnTranspile = new JButton("Save & transpile");
39  
    btnTranspile.addActionListener(actionListener { transpile(false); });
40  
    
41  
    btnMTranspile = new JButton("S & Multi-transpile");
42  
    btnMTranspile.addActionListener(actionListener { transpile(true); });
43  
    
44  
    buttons = ll(btnReload, btnSave, btnTranspile);
45  
    
46  
    jdisable(buttons);
47  
    // XXX cursor bug? textArea.setEditable(false); // still loading
48  
    
49  
    snippetType = getSnippetType(snippetID);
50  
    JScrollPane bottom = new JScrollPane(
51  
        snippetType != 42
52  
          ? jflowRight(btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload)
53  
          : jflowRight(btnSave, btnReload));
54  
    addToWindow(textArea, bottom);
55  
  
56  
    onUpdate(textArea, r {
57  
      jenable(buttons);
58  
    });
59  
  
60  
    reload();    
61  
  }
62  
  
63  
  void saveSnippet(final Runnable next) {
64  
    final S text = textArea.getText();
65  
    jdisable(buttons);
66  
    lblStatus.setText("Saving...");
67  
    thread {
68  
      fS page = editSnippet(snippetID, text);
69  
      
70  
      awt {
71  
        lblStatus.setText("Saved snippet: " + page);
72  
        jenable(buttons);
73  
        callF(next);
74  
      }
75  
    }
76  
  }
77  
  
78  
  void transpile(final bool multi) {
79  
    saveSnippet(r {
80  
      lblStatus.setText("Transpiling...");
81  
      jdisable(btnEleuReload);
82  
      
83  
      thread "Transpiling" {
84  
        try {
85  
          final Pair<Bool, S> p = transpileOnServer(snippetID, multi ? "medium" : "quick");
86  
          awt {
87  
            if (p.a)
88  
              lblStatus.setText("Transpiled OK!");
89  
            else {
90  
              lblStatus.setText("Transpilation error. " + p.b);
91  
              showText("Transpilation Error", p.b);
92  
            }
93  
          }
94  
        } catch e {
95  
          printStackTrace(e);
96  
          lblStatus.setText("Transpilation problem. " + e);
97  
        }
98  
        jenable(btnEleuReload);
99  
      }
100  
    });
101  
  }
102  
  
103  
  void reload() {
104  
    thread "Load Snippet" {
105  
      final S s = loadSnippet(snippetID);
106  
      awt {
107  
        lblStatus.setText("Loaded " + s.length() + " chars.");
108  
        textArea.setText(s);
109  
        //textArea.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
110  
        textArea.setCaretPosition(0);
111  
        jenable(buttons);
112  
        textArea.setEditable(true);
113  
        textArea.requestFocus();
114  
      }
115  
    }
116  
  }
117  
  
118  
  void eleuReload() {
119  
    time {
120  
      butterReload(snippetID);
121  
    }
122  
    infoBox("Reloaded in " + lastTiming_format100ms());
123  
  }
124  
}

Author comment

Began life as a copy of #1004360

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1010354
Snippet name: editJavaXSnippet using JTextArea [v2, dev.]
Eternal ID of this version: #1010354/6
Text MD5: 7e65c6454f4002fda24dc1b4e489cd62
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-02 09:37:19
Source code size: 3577 bytes / 124 lines
Pitched / IR pitched: No / No
Views / Downloads: 427 / 669
Version history: 5 change(s)
Referenced in: [show references]