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

82
LINES

< > BotCompany Repo | #1026600 - Convo Popup [used by dm_contactUserInPopup]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 794K of libraries. Click here for Pure Java version (10513L/54K).

!7

cmodule ConvoPopup {
  L<Post> posts = dm_synchroList(this);
  int windowWidth = 400, windowHeight = 400;
  S userInput;
  S text; bool right; // for form
  bool popupVisible;
  Rect popupPosition;
  
  transient JChatConvo view;
  
  srecord Post(S html, bool right) {}
  
  start {
    componentFieldsToKeep = litset('view); // we clean it up ourselves
    if (popupVisible)
      openPopup();
  }
  
  visual
    withCenteredButtons(withMargin(jvstack(
      centerAndEastWithMargin(dm_textField text(),
        jline(dm_checkBox right(),
          jbutton("Add post", rEnter { addPost(text, right) }))))),
      "Show popup", rEnter openPopup,
      "Clear posts", rEnter clearPosts);
      
  void cleanMeUp {
    JComponent v = view;
    view = null;
    disposeFrame(v);
  }
  
  void sendInput {
    S s = trim(userInput);
    if (nempty(s)) {
      addPost(htmlEncode2(s), false);
      vmBus_send chatUserInput(module(), s);
      setField(userInput := "");
    }
  }
  
  // API
  
  void openPopup swing {
    if (view == null) {
      setField(popupVisible := true);
      view = new JChatConvo;
      for (Post p : cloneList(posts))
        view.addPost(p.html, p.right);
      JComponent content = centerAndSouth(
        jscroll_trackWidth(view),
        withMargin(dm_textFieldAndSubmit userInput('sendInput, buttonText := "Send")));
      JFrame frame = showFrameInBottomRightCorner(content, windowWidth, windowHeight);
      setBounds(frame, popupPosition);
      moveWindowIntoScreen(frame);
      alwaysOnTop(frame);
      onFrameClosing(content, r { if (view != null) setField(popupVisible := false) });
      onBoundsChange(frame, r { setField(popupPosition := boundsRect(frame)) });
    } else
      activateFrame(view);
  }
  
  void closePopup swing {
    disposeFrame(view);
  }
  
  void addPost(S html, bool right) swing {
    posts.add(new Post(html, right));
    view?.addPost(html, right);
  }
  
  void clearPosts swing { posts.clear(); view?.clearPosts(); }
  
  void reply(S s) {
    if (empty(s = trim(s))) ret;
    addPost(htmlEncode2(s), true);
  }
  
  bool isMainChat() { true; }
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): mqqgnosmbjvj, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026600
Snippet name: Convo Popup [used by dm_contactUserInPopup]
Eternal ID of this version: #1026600/28
Text MD5: 8579992fdec72362fbd9da28c48e3fcd
Transpilation MD5: 84abd114068b120ff69d6ca2b4fbaa74
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-23 16:18:46
Source code size: 2206 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 75 / 1388
Version history: 27 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1026600 & http://1026600.tinybrain.de