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).

abstract sclass DynTextArea extends DynModule {
  S text;
  bool noGrab; // noGrab = don't save what user types 
  transient bool enableUndo = true;
  transient JTextArea textArea;
  transient double grabInterval = 10.0; // how often text is grabbed from text area
  
  visualize {
    textArea = typeWriterTextArea(text);
    if (enableUndo) jEnableUndoRedo(textArea);
    ret awtEvery(textArea, grabInterval, r swingToData);
  }
  
  void swingToData {
    if (textArea != null && !noGrab)
      setText(main.getText(textArea));
  }
  
  void unvisualize {
    swingToData();
    super.unvisualize();
  }
  
  // API
  
  void setText(S text) enter {
    if (eq(this.text, text)) ret;
    setField(+text);
    setTextKeepCaret(textArea, text);
  }
  
  void setText_big(S text) enter {
    if (eq(this.text, text)) ret;
    temp tempSetOpt(module(), noGrab := true);
    setField(+text);
    long time = sysNow();
    Document doc = defaultStyledDocumentFromString(text);
    done2_always(time, "Make StyledDocument for " + nChars(text));
    time = sysNow();
    setDocument(textArea, doc);
    done2_always(time, "Apply StyledDocument");
  }
  
  S getText() { swingToData(); ret text; }
  
  void clearText() { setText(""); }
  
  void printToText(O o) {
    setText(getText() + str(o) + "\n");
    moveCaretToEnd(textArea);
  }
}

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: 452 / 1113
Version history: 19 change(s)
Referenced in: [show references]