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

65
LINES

< > BotCompany Repo | #1036083 // InstantNeverHideToolTip backup

JavaX fragment (include)

// instantiate only once per component!
sclass InstantNeverHideToolTip > MouseAdapter {
  JComponent component;
  JToolTip toolTip;
  Popup popup;
  int x, y;
  S text;
  IF0<S> calculateText;
  
  *(IF0<S> *calculateText, JComponent component) { this(component); }
  *(S *text, JComponent component) { this(component); }
  
  *(JComponent *component) {
    swing {
      component.addMouseListener(InstantNeverHideToolTip.this);
      toolTip = component.createToolTip();
      
      // Hide also when component is removed from hierarchy
      bindToComponent(component, null, l0 hideToolTip);
    }
  }
  
  @Override public void mouseEntered(MouseEvent e) {
    x = e.getXOnScreen()+2;
    y = e.getYOnScreen()+2;
    showToolTip();
  }
  
  void updateText() swing {
    if (calculateText != null)
      setText(calculateText!);
  }
  
  public void showToolTip() {
    updateText();
    if (empty(text)) ret;
    toolTip.setTipText(text);
    popup = PopupFactory.getSharedInstance().getPopup(component, toolTip, x, y);
    popup.show();
  }

  public void mouseExited(MouseEvent e) {
    hideToolTip();
  }
  
  bool toolTipShowing() { ret popup != null; }
  
  void hideToolTip() {
    if (popup != null) {
      popup.hide();
      popup = null;
    }
  }
  
  S getText() { ret text; }
  
  void setText(S text) swing {
    if (eq(text, getText())) ret;
    InstantNeverHideToolTip.this.text = text;
    if (toolTipShowing()) {
      hideToolTip();
      showToolTip();
    }
  }
}

Author comment

Began life as a copy of #1034548

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

-
Snippet ID: #1036083
Snippet name: InstantNeverHideToolTip backup
Eternal ID of this version: #1036083/1
Text MD5: 7054dc04b27741bc1562ec85243dbb59
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-07 03:53:25
Source code size: 1555 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 114 / 122
Referenced in: