scope componentPopupMenu. static ThreadLocal #mouseEvent; svoid componentPopupMenu_init { swing { if (mouseEvent == null) mouseEvent = (ThreadLocal) 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) 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