* button click, preventing the default menu from appearing. It propagates the mouse
* click further so other elements will respond appropriately.
*
* TODO this should be refactored once the API is updated.
*/
final EventDispatcher initial = textArea.getEventDispatcher();
textArea.setEventDispatcher(new EventDispatcher() {
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent)event;
if (mouseEvent.getButton() == MouseButton.SECONDARY ||
(mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.isControlDown())) {
event.consume();
}
}
return initial.dispatchEvent(event, tail);
}
});
// make the new context menu including the clear option
MenuItem copySelected = new MenuItem("Copy");