Example usage for javafx.scene.control ContextMenu setHideOnEscape

List of usage examples for javafx.scene.control ContextMenu setHideOnEscape

Introduction

In this page you can find the example usage for javafx.scene.control ContextMenu setHideOnEscape.

Prototype

public final void setHideOnEscape(boolean value) 

Source Link

Usage

From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java

private void initialiseAutoCompletion() {

    EventStream<Integer> changesEventStream = xpathExpressionArea.plainTextChanges().map(characterChanges -> {
        if (characterChanges.getRemoved().length() > 0) {
            return characterChanges.getRemovalEnd() - 1;
        }/*www.j a va 2s.co  m*/
        return characterChanges.getInsertionEnd();
    });

    EventStream<Integer> keyCombo = EventStreams.eventsOf(xpathExpressionArea, KeyEvent.KEY_PRESSED)
            .filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE))
            .map(searchPoint -> xpathExpressionArea.getCaretPosition());

    // captured in the closure
    final ContextMenu autoCompletePopup = new ContextMenuWithNoArrows();
    autoCompletePopup.setId("xpathAutocomplete");
    autoCompletePopup.setHideOnEscape(true);

    EventStreams.merge(keyCombo, changesEventStream).map(searchPoint -> {
        int indexOfSlash = xpathExpressionArea.getText().lastIndexOf("/", searchPoint - 1) + 1;
        String input = xpathExpressionArea.getText();
        if (searchPoint > input.length()) {
            searchPoint = input.length();
        }
        input = input.substring(indexOfSlash, searchPoint);

        return Tuples.t(indexOfSlash, input);
    }).filter(t -> StringUtils.isAlpha(t._2)).subscribe(s -> autoComplete(s._1, s._2, autoCompletePopup));

}