Libraryless. Click here for Pure Java version (11928L/85K).
1 | asclass DynConvoPopup > DynModule {
|
2 | L<Post> posts = dm_synchroList(this); |
3 | int windowWidth = 400, windowHeight = 400; |
4 | S userInput; |
5 | S text; bool right; // for form |
6 | bool popupVisible; |
7 | Rect popupPosition; |
8 | |
9 | transient JChatConvo view; |
10 | |
11 | srecord Post(S html, bool right) {}
|
12 | |
13 | start {
|
14 | componentFieldsToKeep = litset('view); // we clean it up ourselves
|
15 | if (popupVisible) |
16 | openPopup(); |
17 | } |
18 | |
19 | visual |
20 | withCenteredButtons(withMargin(jvstack( |
21 | centerAndEastWithMargin(dm_textField text(), |
22 | jline(dm_checkBox right(), |
23 | jbutton("Add post", rEnter { addPost(text, right) }))))),
|
24 | "Show popup", rEnter openPopup, |
25 | "Clear posts", rEnter clearPosts); |
26 | |
27 | void cleanMeUp {
|
28 | JComponent v = view; |
29 | view = null; |
30 | disposeFrame(v); |
31 | } |
32 | |
33 | void sendInput {
|
34 | S s = trim(userInput); |
35 | if (nempty(s)) {
|
36 | addPost(htmlEncode2(s), false); |
37 | vmBus_send chatUserInput(module(), s); |
38 | setField(userInput := ""); |
39 | } |
40 | } |
41 | |
42 | JComponent makeConvoView() {
|
43 | view = new JChatConvo; |
44 | for (Post p : cloneList(posts)) |
45 | view.addPost(p.html, p.right); |
46 | ret centerAndSouth( |
47 | jscroll_trackWidth(view), |
48 | withMargin(dm_textFieldAndSubmit userInput('sendInput, buttonText := "Send")));
|
49 | } |
50 | |
51 | // API |
52 | |
53 | void openPopup swing {
|
54 | if (view == null) {
|
55 | setField(popupVisible := true); |
56 | JComponent content = makeConvoView(); |
57 | JFrame frame = showFrameInBottomRightCorner(content, windowWidth, windowHeight); |
58 | setBounds(frame, popupPosition); |
59 | moveWindowIntoScreen(frame); |
60 | alwaysOnTop(frame); |
61 | onFrameClosing(content, r { if (view != null) setField(popupVisible := false) });
|
62 | onBoundsChange(frame, r { setField(popupPosition := boundsRect(frame)) });
|
63 | } else |
64 | activateFrame(view); |
65 | } |
66 | |
67 | void closePopup swing {
|
68 | disposeFrame(view); |
69 | } |
70 | |
71 | void addPost(S html, bool right) swing {
|
72 | posts.add(new Post(html, right)); |
73 | view?.addPost(html, right); |
74 | } |
75 | |
76 | void clearPosts swing { posts.clear(); view?.clearPosts(); }
|
77 | |
78 | void reply(S s) {
|
79 | if (empty(s = trim(s))) ret; |
80 | addPost(htmlEncode2(s), true); |
81 | } |
82 | |
83 | bool isMainChat() { true; }
|
84 | } |
Began life as a copy of #1026600
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1027445 |
| Snippet name: | DynConvoPopup |
| Eternal ID of this version: | #1027445/2 |
| Text MD5: | 765fbe2e7b67090481c7542ba7c6e074 |
| Transpilation MD5: | 374482543d7b47fcba42fb13cdf9690a |
| Author: | stefan |
| Category: | javax / stefan's os |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-03-20 18:34:49 |
| Source code size: | 2272 bytes / 84 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 429 / 803 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |