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

72
LINES

< > BotCompany Repo | #1000894 // Swing: Edit text snippet

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

Libraryless. Click here for Pure Java version (1502L/10K/36K).

1  
!752
2  
3  
static S snippetID = "#636";
4  
5  
static JTextArea textArea;
6  
static JLabel status;
7  
static JButton btnSave;
8  
9  
p {
10  
  if (args.length != 0) snippetID = args[0];
11  
  
12  
  snippetID = formatSnippetID(snippetID);
13  
  JFrame frame = new JFrame(snippetID + " - Edit");
14  
  JPanel panel = new JPanel(new BorderLayout());
15  
  
16  
  textArea = newTypeWriterTextArea();
17  
  panel.add(BorderLayout.CENTER, new JScrollPane(textArea));
18  
  
19  
  status = new JLabel("Loading...");
20  
  btnSave = new JButton("Save " + snippetID);
21  
  btnSave.setEnabled(false);
22  
  textArea.setEditable(false); // still loading
23  
  
24  
  btnSave.addActionListener(actionListener {
25  
    saveSnippet();
26  
  });
27  
  
28  
  JPanel bottom = new JPanel(new BorderLayout);
29  
  bottom.add(BorderLayout.CENTER, status);
30  
  bottom.add(BorderLayout.EAST, btnSave);
31  
 
32  
  panel.add(BorderLayout.SOUTH, bottom);
33  
  
34  
  onUpdate(textArea, r {
35  
    btnSave.setEnabled(true);
36  
  });
37  
38  
  thread {
39  
    final S s = loadSnippet(snippetID);
40  
    awt {
41  
      status.setText("Loaded " + s.length() + " chars.");
42  
      textArea.setText(s);
43  
      //textArea.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
44  
      textArea.setCaretPosition(0);
45  
      btnSave.setEnabled(false);
46  
      textArea.setEditable(true);
47  
      textArea.requestFocus();
48  
    }
49  
  }
50  
  
51  
  frame.add(panel);
52  
  frame.setBounds(100, 100, 500, 400);
53  
  frame.setVisible(true);
54  
  exitOnFrameClose(frame);
55  
}
56  
57  
static void saveSnippet() {
58  
  final S text = textArea.getText();
59  
  btnSave.setEnabled(false);
60  
  status.setText("Saving...");
61  
  thread {
62  
    final S url = "http://tinybrain.de:8080/tb-int/update_snippet_text.php";
63  
    S user = loadTextFile(new File(userHome(), ".tinybrain/username").getPath(), null);
64  
    S pass = loadTextFile(new File(userHome(), ".tinybrain/userpass").getPath(), null);
65  
    S query = "id=" + parseSnippetID(snippetID) + "&text=" + urlencode(text) + "&_user=" + urlencode(user) + "&_pass=" + urlencode(pass);
66  
    final S page = doPost(query, url);
67  
    
68  
    awt {
69  
      status.setText("Saved snippet: " + page);
70  
    }
71  
  }
72  
}

Author comment

Began life as a copy of #1000881

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000894
Snippet name: Swing: Edit text snippet
Eternal ID of this version: #1000894/1
Text MD5: dfa14818ccc77c8ddd79be0fbb760a93
Transpilation MD5: 534b01e473d81bc558a6c4f95ac3f888
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-03 15:48:20
Source code size: 2073 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 778 / 825
Referenced in: [show references]