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

126
LINES

< > BotCompany Repo | #1004360 // editJavaXSnippet [Swing] using JTextArea

JavaX fragment (include)

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

Author comment

Began life as a copy of #1003437

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv

No comments. add comment

Snippet ID: #1004360
Snippet name: editJavaXSnippet [Swing] using JTextArea
Eternal ID of this version: #1004360/11
Text MD5: f7a2042f5a79abe4ceb5188348b57b42
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:30:38
Source code size: 3648 bytes / 126 lines
Pitched / IR pitched: No / No
Views / Downloads: 630 / 632
Version history: 10 change(s)
Referenced in: [show references]