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

sclass JChatConvo extends SingleComponentPanel {
  JLabel label;
  L<Post> posts = synchroList();
  
  // params = contents, right, contents, right, ...
  *(O... params) {
    for (int i = 0; i+1 < l(params); i += 2)
      addPost(strUnnull(params[i]), isTrue(params[i+1])); // TODO: update only once

    setComponent(withMargin(label = jTopLabel()));
    onResize(label, r update);
  }
  
  srecord Post(S html, bool right) {}
  
  selfType addPost(S html, bool right) {
    swing {
      posts.add(new Post(html, right));
      updateAndScrollDown();
    }
    this;
  }
  
  void clearPosts {
    posts.clear();
    update();
  }
  
  void usePostsList(L<Post> posts) {
    this.posts = assertNotNull(posts);
    updateAndScrollDown();
  }
  
  void update swing {
    if (label == null) ret;
    setText(label, hhtml(htmlForJLabel_chatConvo_table(
      cloneMap(posts, p -> pair(p.html, p.right)), label.getWidth())));
  }

  void updateAndScrollDown {
    update();
    scrollDown();
  }
  
  void scrollDown {
    scrollAllTheWayDown(JChatConvo.this);
  }
  
  L<Post> posts() { ret cloneList(posts); }
}

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: 300 / 775
Version history: 19 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)