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

50
LINES

< > BotCompany Repo | #1026597 // JChatConvo

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

Libraryless. Click here for Pure Java version (4186L/27K).

1  
sclass JChatConvo extends SingleComponentPanel {
2  
  JLabel label;
3  
  L<Post> posts = synchroList();
4  
  
5  
  // params = contents, right, contents, right, ...
6  
  *(O... params) {
7  
    for (int i = 0; i+1 < l(params); i += 2)
8  
      addPost(strUnnull(params[i]), isTrue(params[i+1])); // TODO: update only once
9  
10  
    setComponent(withMargin(label = jTopLabel()));
11  
    onResize(label, r update);
12  
  }
13  
  
14  
  srecord Post(S html, bool right) {}
15  
  
16  
  selfType addPost(S html, bool right) {
17  
    swing {
18  
      posts.add(new Post(html, right));
19  
      updateAndScrollDown();
20  
    }
21  
    this;
22  
  }
23  
  
24  
  void clearPosts {
25  
    posts.clear();
26  
    update();
27  
  }
28  
  
29  
  void usePostsList(L<Post> posts) {
30  
    this.posts = assertNotNull(posts);
31  
    updateAndScrollDown();
32  
  }
33  
  
34  
  void update swing {
35  
    if (label == null) ret;
36  
    setText(label, hhtml(htmlForJLabel_chatConvo_table(
37  
      cloneMap(posts, p -> pair(p.html, p.right)), label.getWidth())));
38  
  }
39  
40  
  void updateAndScrollDown {
41  
    update();
42  
    scrollDown();
43  
  }
44  
  
45  
  void scrollDown {
46  
    scrollAllTheWayDown(JChatConvo.this);
47  
  }
48  
  
49  
  L<Post> posts() { ret cloneList(posts); }
50  
}

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: #1026597
Snippet name: JChatConvo
Eternal ID of this version: #1026597/20
Text MD5: 3c0978347004cea0608dc0eb9d1031a7
Transpilation MD5: 721f17ba9bb4f61a207322a98e8e1b8d
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-20 17:35:35
Source code size: 1161 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 301 / 777
Version history: 19 change(s)
Referenced in: [show references]