scope componentPopupMenu. // TODO: get rid of map (just look for adapter in listeners) static Map componentPopupMenu_map; static ThreadLocal #mouseEvent; svoid componentPopupMenu_init { swing { if (componentPopupMenu_map == null) componentPopupMenu_map = (Map) vm_generalMap_get('componentPopupMenu_map); if (componentPopupMenu_map == null) vm_generalMap_put(componentPopupMenu_map := componentPopupMenu_map = newWeakHashMap()); //componentPopupMenu_map = or((Map) getOpt(creator(), 'componentPopupMenu_map), (Map) (Map) newWeakHashMap()); if (mouseEvent == null) //mouseEvent = or((ThreadLocal) getOpt(creator(), 'componentPopupMenu_mouseEvent), new ThreadLocal); 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 { L maker = componentPopupMenu_map.get(component); if (maker == null) { componentPopupMenu_map.put(component, maker = new L); if (!component instanceof JInternalFrame) // lil' hack component.addMouseListener(new componentPopupMenu_Adapter(maker)); } maker.add(menuMaker); } } sclass componentPopupMenu_Adapter extends MouseAdapter { L maker; *(L *maker) {} public void mousePressed(MouseEvent e) { displayMenu(e); } public void mouseReleased(MouseEvent e) { displayMenu(e); } void displayMenu(MouseEvent e) { 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