Digging out some facts:
- contextMenuEvent is created and run in
scene.processMenuEvent(...) - for events triggered by the keyboard, the method calculates the coordinates of the scene / screen relative to somewhere in the middle of the node target (which is the current focus owner)
- (/) :
event.copyFor(...) .
, , . A () - EventDispatcher. (: , , !). contextMenuEvent , EventDispatcher. (, f.i. ListViewSkin) EventDispatchChain.
private static class ContextMenuEventDispatcher implements EventDispatcher {
private EventDispatcher delegate;
private Cell<?> targetCell;
public ContextMenuEventDispatcher(EventDispatcher delegate) {
this.delegate = delegate;
}
public void setTargetCell(Cell<?> cell) {
this.targetCell = cell;
}
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
event = handleContextMenuEvent(event);
return delegate.dispatchEvent(event, tail);
}
private Event handleContextMenuEvent(Event event) {
if (!(event instanceof ContextMenuEvent) || targetCell == null) return event;
ContextMenuEvent cme = (ContextMenuEvent) event;
if (!cme.isKeyboardTrigger()) return event;
final Bounds bounds = targetCell.localToScreen(
targetCell.getBoundsInLocal());
double x2 = bounds.getMinX() + bounds.getWidth() / 4;
double y2 = bounds.getMinY() + bounds.getHeight() / 2;
ContextMenuEvent toCell = new ContextMenuEvent(ContextMenuEvent.CONTEXT_MENU_REQUESTED,
0, 0, x2, y2, true, null);
return toCell;
}
}
private static class ListViewCSkin<T> extends ListViewSkin<T> implements
EventTarget {
private ContextMenuEventDispatcher contextHandler =
new ContextMenuEventDispatcher(new EventHandlerManager(this));
@Override
public EventDispatchChain buildEventDispatchChain(
EventDispatchChain tail) {
int focused = getSkinnable().getFocusModel().getFocusedIndex();
Cell cell = null;
if (focused > -1) {
cell = flow.getCell(focused);
tail = cell.buildEventDispatchChain(tail);
}
contextHandler.setTargetCell(cell);
return tail.prepend(contextHandler);
}
public ListViewCSkin(ListView<T> listView) {
super(listView);
}
}
Edit
(?) , contextMenu listView , Menu . , , , - (?) .