1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| InputMap inputMap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = this.getActionMap();
Action actionPopup = new AbstractAction()
{
private static final long serialVersionUID = 0L;
public void actionPerformed(ActionEvent event)
{
JComponent component = CGUtilities.getFocusOwner();
if (component == null) return;
PointerInfo pointer = MouseInfo.getPointerInfo();
Point compPosition = component.getLocationOnScreen();
Point mouseLocation = pointer.getLocation();
int x = mouseLocation.x - compPosition.x;
int y = mouseLocation.y - compPosition.y;
MouseEvent popupEvent1 = new MouseEvent(component, MouseEvent.MOUSE_PRESSED, 0, 0, x, y, 1, true);
MouseEvent popupEvent2 = new MouseEvent(component, MouseEvent.MOUSE_RELEASED, 0, 0, x, y, 1, true);
component.dispatchEvent(popupEvent1);
component.dispatchEvent(popupEvent2);
}
};
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.SHIFT_DOWN_MASK), "doShowPopup");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), "doShowPopup");
actionMap.put("doShowPopup", actionPopup); |
Partager