1 | sclass listPopupMenu_Maker { |
2 | new L menuMakers; |
3 | } |
4 | |
5 | static Map<JList, listPopupMenu_Maker> listPopupMenu_map = new WeakHashMap; |
6 | |
7 | static new ThreadLocal<MouseEvent> listPopupMenu_mouseEvent; |
8 | static new ThreadLocal<Bool> listPopupMenu_first; |
9 | |
10 | // menuMaker = voidfunc(JPopupMenu, S item) |
11 | static void listPopupMenu(final JList list, fO menuMaker) { |
12 | final bool first = isTrue(getAndClearThreadLocal(listPopupMenu_first)); |
13 | awtIfNecessary { |
14 | listPopupMenu_Maker maker = listPopupMenu_map.get(list); |
15 | if (maker == null) { |
16 | listPopupMenu_map.put(list, maker = new listPopupMenu_Maker); |
17 | final listPopupMenu_Maker _maker = maker; |
18 | list.addMouseListener(new MouseAdapter { |
19 | public void mousePressed(MouseEvent e) { displayMenu(e); } |
20 | public void mouseReleased(MouseEvent e) { displayMenu(e); } |
21 | |
22 | void displayMenu(MouseEvent e) { |
23 | if (e.isPopupTrigger()) { |
24 | new JPopupMenu menu; |
25 | |
26 | int idx = list.locationToIndex(e.getPoint()); |
27 | O item = list.getModel().getElementAt(idx); |
28 | list.setSelectedIndex(idx); |
29 | int emptyCount = menu.getComponentCount(); |
30 | |
31 | listPopupMenu_mouseEvent.set(e); |
32 | for (O menuMaker : _maker.menuMakers) |
33 | pcallF(menuMaker, menu, item); |
34 | |
35 | // show menu if any items in it |
36 | if (menu.getComponentCount() == emptyCount) ret; |
37 | |
38 | vmBus_send('showingPopupMenu, list, menu); |
39 | menu.show(e.getComponent(), e.getX(), e.getY()); |
40 | } |
41 | } |
42 | }); |
43 | } |
44 | if (first) |
45 | maker.menuMakers.add(0, menuMaker); |
46 | else |
47 | maker.menuMakers.add(menuMaker); |
48 | } |
49 | } |
Began life as a copy of #1004446
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009960 |
Snippet name: | listPopupMenu - adds to the menu if it already exists |
Eternal ID of this version: | #1009960/5 |
Text MD5: | 98bcc64f78ab64a7be82459bf96ab901 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-01-02 17:09:14 |
Source code size: | 1757 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 625 / 619 |
Version history: | 4 change(s) |
Referenced in: | [show references] |