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)

static editJavaXSnippet_Editor editJavaXSnippet(fS snippetID) {
  ret (editJavaXSnippet_Editor) swingAndWait(func {
    new editJavaXSnippet_Editor(snippetID)
  });
}

sclass editJavaXSnippet_Editor {
  S snippetID;
  JTextArea textArea;
  JButton btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload;
  L<JButton> buttons;
  int snippetType;
  JLabel lblStatus;

  *(S _snippetID) {
    snippetID = formatSnippetID(_snippetID);
    showFrame(snippetID,
      centerAndSouth(textArea = typeWriterTextArea(),
        lblStatus = jlabel()));
    frameIcon(textArea, #1004655);
    
    thread {
      setFrameTitle(textArea, "E: " + getSnippetTitle(snippetID) + " [" + snippetID + "]");
    }
  
    // Customize text area
    textArea.setTabSize(2);

    lblStatus.setText("Loading...");
    
    btnSave = new JButton("Save on server");
    btnSave.addActionListener(actionListener { saveSnippet(null); });
    
    btnTranspile = new JButton("Save & transpile");
    btnTranspile.addActionListener(actionListener { transpile(false); });
    
    btnMTranspile = new JButton("S & Multi-transpile");
    btnMTranspile.addActionListener(actionListener { transpile(true); });
    
    btnReload = new JButton("Reload");
    btnReload.addActionListener(actionListener { reload(); });
    
    btnEleuReload = new JButton("Eleu-Reload");
    btnEleuReload.addActionListener(actionListener { eleuReload(); });
    
    buttons = ll(btnReload, btnSave, btnTranspile);
    
    jdisable(buttons);
    // XXX cursor bug? textArea.setEditable(false); // still loading
    
    snippetType = getSnippetType(snippetID);
    JScrollPane bottom = new JScrollPane(
        snippetType != 42
          ? jflowRight(btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload)
          : jflowRight(btnSave, btnReload));
    addToWindow(textArea, bottom);
  
    onUpdate(textArea, r {
      jenable(buttons);
    });
  
    reload();    
  }
  
  void saveSnippet(final Runnable next) {
    final S text = textArea.getText();
    jdisable(buttons);
    lblStatus.setText("Saving...");
    thread {
      fS page = editSnippet(snippetID, text);
      
      awt {
        lblStatus.setText("Saved snippet: " + page);
        jenable(buttons);
        callF(next);
      }
    }
  }
  
  void transpile(final bool multi) {
    saveSnippet(r {
      lblStatus.setText("Transpiling...");
      jdisable(btnEleuReload);
      
      thread "Transpiling" {
        try {
          final Pair<Bool, S> p = transpileOnServer(snippetID, multi ? "medium" : "quick");
          awt {
            if (p.a)
              lblStatus.setText("Transpiled OK!");
            else {
              lblStatus.setText("Transpilation error. " + p.b);
              showText("Transpilation Error", p.b);
            }
          }
        } catch e {
          printStackTrace(e);
          lblStatus.setText("Transpilation problem. " + e);
        }
        jenable(btnEleuReload);
      }
    });
  }
  
  void reload() {
    thread "Load Snippet" {
      final S s = loadSnippet(snippetID);
      awt {
        lblStatus.setText("Loaded " + s.length() + " chars.");
        textArea.setText(s);
        //textArea.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
        textArea.setCaretPosition(0);
        jenable(buttons);
        textArea.setEditable(true);
        textArea.requestFocus();
      }
    }
  }
  
  void eleuReload() {
    time {
      butterReload(snippetID);
    }
    infoBox("Reloaded in " + lastTiming_format100ms());
  }
}

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: 631 / 633
Version history: 10 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1009480 - editJavaXSnippet [Swing] using RSyntaxTextArea
#1010354 - editJavaXSnippet using JTextArea [v2, dev.]