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) svoid componentPopupMenu(final JComponent component, fO menuMaker) { if (component == null || menuMaker == null) ret; swing { O adapter = componentPopupMenu_initForComponent(component); ((L) _get(adapter, 'maker)).add(menuMaker); } } sO componentPopupMenu_initForComponent(final JComponent component) { ret component == null ? null : swing(func { componentPopupMenu_init(); O adapter = findComponentPopupMenuListener_gen(component); if (adapter == null) { new componentPopupMenu_Adapter a; //addMouseListener_inFront(component, a); component.addMouseListener(a); adapter = a; } ret adapter; }); } sclass componentPopupMenu_Adapter extends MouseAdapter { new L maker; bool internalFrameLeftButtonMagic; bool allowScrolling = true; Point pressedAt; public void mousePressed(MouseEvent e) { displayMenu(e); pressedAt = internalFrameLeftButtonMagic && e.getClickCount() == 1 && internalFrameActive(e.getComponent()) ? e.getLocationOnScreen() : null; } public void mouseReleased(MouseEvent e) { // TODO: show a little less often on left mouse click if (internalFrameLeftButtonMagic && eq(pressedAt, e.getLocationOnScreen())) displayMenu2(e); else displayMenu(e); } void displayMenu(MouseEvent e) { if (e.getSource() instanceof JInternalFrame) ret; if (e.isPopupTrigger()) displayMenu2(e); } void populate(JPopupMenu menu, MouseEvent e) { temp tempSetTL(mouseEvent, e); for (O menuMaker : maker) pcallF(menuMaker, menu); vmBus_send('showingPopupMenu, e.getComponent(), menu); } void displayMenu2(MouseEvent e) { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); populate(menu, e); if (menu.getComponentCount() == emptyCount) ret; if (allowScrolling) { menu = new JPopupMenu; JMenuScroller scroller = JMenuScroller.setScrollerFor(menu); scroller.fillMenu = voidfunc(JPopupMenu m) { populate(m, e) }; } 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 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034571 |
Snippet name: | componentPopupMenu - backup |
Eternal ID of this version: | #1034571/1 |
Text MD5: | 7f1ef023c2ea42d4bb97dc64aa9d0f14 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-16 01:37:08 |
Source code size: | 2563 bytes / 86 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 130 / 141 |
Referenced in: | -