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

52
LINES

< > BotCompany Repo | #1016435 // DynTextArea

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10343L/71K).

1  
abstract sclass DynTextArea extends DynModule {
2  
  S text;
3  
  bool noGrab; // noGrab = don't save what user types 
4  
  transient bool enableUndo = true;
5  
  transient JTextArea textArea;
6  
  transient double grabInterval = 10.0; // how often text is grabbed from text area
7  
  
8  
  visualize {
9  
    textArea = typeWriterTextArea(text);
10  
    if (enableUndo) jEnableUndoRedo(textArea);
11  
    ret awtEvery(textArea, grabInterval, r swingToData);
12  
  }
13  
  
14  
  void swingToData {
15  
    if (textArea != null && !noGrab)
16  
      setText(main.getText(textArea));
17  
  }
18  
  
19  
  void unvisualize {
20  
    swingToData();
21  
    super.unvisualize();
22  
  }
23  
  
24  
  // API
25  
  
26  
  void setText(S text) enter {
27  
    if (eq(this.text, text)) ret;
28  
    setField(+text);
29  
    setTextKeepCaret(textArea, text);
30  
  }
31  
  
32  
  void setText_big(S text) enter {
33  
    if (eq(this.text, text)) ret;
34  
    temp tempSetOpt(module(), noGrab := true);
35  
    setField(+text);
36  
    long time = sysNow();
37  
    Document doc = defaultStyledDocumentFromString(text);
38  
    done2_always(time, "Make StyledDocument for " + nChars(text));
39  
    time = sysNow();
40  
    setDocument(textArea, doc);
41  
    done2_always(time, "Apply StyledDocument");
42  
  }
43  
  
44  
  S getText() { swingToData(); ret text; }
45  
  
46  
  void clearText() { setText(""); }
47  
  
48  
  void printToText(O o) {
49  
    setText(getText() + str(o) + "\n");
50  
    moveCaretToEnd(textArea);
51  
  }
52  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016435
Snippet name: DynTextArea
Eternal ID of this version: #1016435/20
Text MD5: 8f159e7cfbae0e8e44c18f3a454717f5
Transpilation MD5: 095c3e56052a6cb1d4c3013e404f2dcd
Author: stefan
Category: javax / modules
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-19 15:03:43
Source code size: 1386 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 454 / 1116
Version history: 19 change(s)
Referenced in: [show references]