import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import java.util.function.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import javax.imageio.*; import java.math.*; class main { static class PopupMenuHelper extends MouseAdapter { JPopupMenu menu; Point point; /** override me */ transient Runnable fillMenu; void fillMenu() { if (fillMenu != null) fillMenu.run(); else fillMenu_base(); } final void fillMenu_fallback(Runnable _f) { if (_f != null) _f.run(); else fillMenu_base(); } void fillMenu_base() { } public void mousePressed(MouseEvent e) { displayMenu(e); } public void mouseReleased(MouseEvent e) { displayMenu(e); } private void displayMenu(MouseEvent e) { boolean popupTrigger = e.isPopupTrigger(); if (popupTrigger) { JPopupMenu menu = new JPopupMenu(); int count = menu.getComponentCount(); this.menu = menu; this.point = e.getPoint(); fillMenu(); this.menu = null; if (menu.getComponentCount() != count) menu.show(e.getComponent(), e.getX(), e.getY()); } } public void install(JComponent component) { component.addMouseListener(this); } }}