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

93
LINES

< > BotCompany Repo | #1020205 // DynRecordingTextArea [Text is persistent in session & has its own log file]

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

Libraryless. Click here for Pure Java version (17834L/112K).

1  
abstract sclass DynRecordingTextArea extends DynModule {
2  
  S text;
3  
  switchable S title;
4  
  switchable bool wordWrap;
5  
  S globalID = aGlobalID();
6  
7  
  transient JTextArea ta;
8  
  transient EditRecorder recorder;
9  
  transient ReliableSingleThread rstPersistText = rstWithDelay(1000, r persistText);
10  
  transient JButton popDownButton;
11  
  
12  
  // We have auto-save of deleted modules
13  
  //bool warnOnDelete() { ret nempty(text); }
14  
  
15  
  File logFile() { ret javaxDataDir("Text Area Logs/" + globalID); }
16  
  
17  
  start {
18  
    dm_watchFieldAndNow title(r { setModuleName(title) });
19  
    dm_watchField wordWrap(r {
20  
      enableWordWrapForTextArea(ta, wordWrap);
21  
      if (ta != null && wordWrap) dm_reloadModule();
22  
    });
23  
    
24  
    
25  
    dm_vmBus_onMessages_q(ll("modulePoppedOut", "modulePoppedIn"), (m, myFrame) -> {
26  
      if (dm_isMe(m))
27  
        adjustUIForPoppedOutWindow();
28  
    });
29  
  }
30  
  
31  
  visualize {
32  
    ta = jenableUndoRedo(typeWriterTextArea(text));
33  
    enableWordWrapForTextArea(ta, wordWrap);
34  
    logQuoted(logFile(), "text: " + text);
35  
    recorder = new EditRecorder(voidfunc(EREvent e) {
36  
      logStructure(logFile(), e);
37  
    });
38  
    recorder.text = text;
39  
    main.onChange(ta, rstPersistText);
40  
    ret jscroll(setOpaqueBackground(Color.white, withMargin(ta)));
41  
  }
42  
  
43  
  void persistText enter {
44  
    if (ta == null) ret;
45  
    Pair<S, Int> p = textAndCaretPosition(ta);
46  
    recorder.update(p.a);
47  
    recorder.updateCaret(p.b);
48  
    print("persistText " + now());
49  
    setField(text := getText(ta));
50  
  }
51  
  
52  
  void unvisualize {
53  
    persistText();
54  
    super.unvisualize();
55  
  }
56  
  
57  
  void setText(S text) { main.setText(ta, text); }
58  
  S text() { ret or(main.getText(ta), text); }
59  
  
60  
  S _modifyStructForDuplication(S struct) {
61  
    // TODO: could fail if module gets more complex
62  
    ret jreplace_first(struct, "globalID=*", "globalID=" + quote(aGlobalID()));
63  
  }
64  
  
65  
  enhanceFrame {
66  
    internalFrameMenuItem(f, "Global ID: " + globalID, null);
67  
  }
68  
  
69  
  void adjustUIForPoppedOutWindow swing {
70  
    if ((popDownButton != null) != dm_moduleIsPoppedOut(me())) {
71  
      if (popDownButton != null) {
72  
        removeFromParent(getParent(popDownButton));
73  
        popDownButton = null;
74  
        ret;
75  
      }
76  
      
77  
      Window window = cast getWindow(dm_vis());
78  
79  
      var popBackInButton = findButton(window, "Pop Back In");
80  
      var parent = getParent(popBackInButton);
81  
      print(+parent);
82  
      
83  
      removeFromParent(parent); // hide controls
84  
      
85  
      popDownButton = jPopDownButton_noText(
86  
        "Pop Back In", r { dm_popInModule(me()) },
87  
        jCheckBoxMenuItem("Always On Top", isAlwaysOnTop(window),
88  
          rEnter dm_toggleAlwaysOnTop),
89  
      );
90  
      replaceComponent(ta, -> centerAndEastWithMargin(ta, vstackWithSpacing(popDownButton)));
91  
    }
92  
  }
93  
}

Author comment

Began life as a copy of #1016122

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020205
Snippet name: DynRecordingTextArea [Text is persistent in session & has its own log file]
Eternal ID of this version: #1020205/10
Text MD5: d8cfc71d0bfb13c632bf5a70347b1812
Transpilation MD5: fddc77addcd775e1b4519612901c84c0
Author: stefan
Category: javax / stefan's os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-25 19:54:57
Source code size: 2839 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 370 / 1002
Version history: 9 change(s)
Referenced in: [show references]