1 | // instantiate only once per component! |
2 | sclass InstantNeverHideToolTip > MouseAdapter { |
3 | JComponent component; |
4 | JToolTip toolTip; |
5 | Popup popup; |
6 | int x, y; |
7 | S text; |
8 | IF0<S> calculateText; |
9 | |
10 | *(IF0<S> *calculateText, JComponent component) { this(component); } |
11 | *(S *text, JComponent component) { this(component); } |
12 | |
13 | *(JComponent *component) { |
14 | swing { |
15 | component.addMouseListener(InstantNeverHideToolTip.this); |
16 | toolTip = component.createToolTip(); |
17 | |
18 | // Hide also when component is removed from hierarchy |
19 | bindToComponent(component, null, l0 hideToolTip); |
20 | } |
21 | } |
22 | |
23 | @Override public void mouseEntered(MouseEvent e) { |
24 | x = e.getXOnScreen()+2; |
25 | y = e.getYOnScreen()+2; |
26 | showToolTip(); |
27 | } |
28 | |
29 | void updateText() swing { |
30 | if (calculateText != null) |
31 | setText(calculateText!); |
32 | } |
33 | |
34 | public void showToolTip() { |
35 | updateText(); |
36 | if (empty(text)) ret; |
37 | toolTip.setTipText(text); |
38 | popup = PopupFactory.getSharedInstance().getPopup(component, toolTip, x, y); |
39 | popup.show(); |
40 | } |
41 | |
42 | public void mouseExited(MouseEvent e) { |
43 | hideToolTip(); |
44 | } |
45 | |
46 | bool toolTipShowing() { ret popup != null; } |
47 | |
48 | void hideToolTip() { |
49 | if (popup != null) { |
50 | popup.hide(); |
51 | popup = null; |
52 | } |
53 | } |
54 | |
55 | S getText() { ret text; } |
56 | |
57 | void setText(S text) swing { |
58 | if (eq(text, getText())) ret; |
59 | InstantNeverHideToolTip.this.text = text; |
60 | if (toolTipShowing()) { |
61 | hideToolTip(); |
62 | showToolTip(); |
63 | } |
64 | } |
65 | } |
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: | 115 / 123 |
Referenced in: | [show references] |