scope componentPopupMenu. static ThreadLocal<MouseEvent> #mouseEvent; svoid componentPopupMenu_init { swing { if (mouseEvent == null) mouseEvent = (ThreadLocal<MouseEvent>) vm_generalMap_get('mouseEvent); if (mouseEvent == null) vm_generalMap_put(componentPopupMenu_mouseEvent := mouseEvent = new ThreadLocal); } } // menuMaker = voidfunc(JPopupMenu) static void componentPopupMenu(final JComponent component, fO menuMaker) { componentPopupMenu_init(); if (component != null && menuMaker != null) swing { O adapter = findComponentPopupMenuListener_gen(component); if (adapter == null) component.addMouseListener(adapter = new componentPopupMenu_Adapter); } ((L) get(adapter, 'maker)).add(menuMaker); } } sclass componentPopupMenu_Adapter extends MouseAdapter { new L maker; // list of "menu makers" that fill the menu (IVF1<JPopupMenu>) public void mousePressed(MouseEvent e) { displayMenu(e); } public void mouseReleased(MouseEvent e) { displayMenu(e); } void displayMenu(MouseEvent e) { if (e.getSource() instanceof JInternalFrame) ret; if (e.isPopupTrigger()) displayMenu2(e); } void displayMenu2(MouseEvent e) { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); temp tempSetTL(mouseEvent, e); for (O menuMaker : maker) pcallF(menuMaker, menu); vmBus_send('showingPopupMenu, e.getComponent(), menu); // show menu if any items in it if (menu.getComponentCount() != emptyCount) menu.show(e.getComponent(), e.getX(), e.getY()); } } end scope
Began life as a copy of #1005719
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1021794 | 
| Snippet name: | componentPopupMenu - adds to the popup menu of any JComponent - v2 without the weak map | 
| Eternal ID of this version: | #1021794/3 | 
| Text MD5: | 7f6a653c3ec24e2c592f5b34db1e1abb | 
| Author: | stefan | 
| Category: | javax / gui | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2021-08-14 00:54:59 | 
| Source code size: | 1652 bytes / 53 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 496 / 528 | 
| Version history: | 2 change(s) | 
| Referenced in: | [show references] |