Example usage for javafx.scene.input KeyCombination SHIFT_DOWN

List of usage examples for javafx.scene.input KeyCombination SHIFT_DOWN

Introduction

In this page you can find the example usage for javafx.scene.input KeyCombination SHIFT_DOWN.

Prototype

Modifier SHIFT_DOWN

To view the source code for javafx.scene.input KeyCombination SHIFT_DOWN.

Click Source Link

Document

Modifier which specifies that the shift key must be down.

Usage

From source file:jviewmda.JViewMda.java

@Override
public void start(Stage primaryStage) {
    m_stage = primaryStage;/*from w  w  w.jav  a2  s .c  o  m*/

    String array_path = "";
    Parameters params = getParameters();
    List<String> unnamed_params = params.getUnnamed();
    if (unnamed_params.size() > 0) {
        array_path = unnamed_params.get(0);
    }
    // FOR DEBUGING PURPOSES
    if (array_path.length() == 0) {
        //String debug_path = "/home/magland/wisdm/www/wisdmfileserver/files/fetalmri/sessions/SESSION1/crops/FNP001A-coronal.crop.mda";
        String debug_path = "/home/magland/data/LesionProbe/Images/ID001_FLAIR.nii";
        if ((new File(debug_path)).exists()) {
            array_path = debug_path;
        }
    }

    Menu menu;
    MenuItem item;

    MenuBar menubar = new MenuBar();

    //file menu
    menu = new Menu("File");
    menubar.getMenus().add(menu);
    item = new MenuItem("Open...");
    item.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_open());
    menu.getItems().add(item);
    item = new MenuItem("Save As...");
    item.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_saveas());
    menu.getItems().add(item);
    menu.getItems().add(new SeparatorMenuItem()); /////////////////////////////////////////////
    item = new MenuItem("Exit");
    item.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_exit());
    menu.getItems().add(item);

    //view menu
    menu = new Menu("View");
    menubar.getMenus().add(menu);
    item = new MenuItem("Zoom In");
    item.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_zoom_in());
    menu.getItems().add(item);
    item = new MenuItem("Zoom Out");
    item.setAccelerator(
            new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
    item.setOnAction(e -> on_zoom_out());
    menu.getItems().add(item);
    menu.getItems().add(new SeparatorMenuItem()); /////////////////////////////////////////////
    {
        CheckMenuItem item0 = new CheckMenuItem("Top Controls");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setTopControlsVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Bottom Controls");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setBottomControlsVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Brightness/Contrast");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setBrightnessContrastVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Slice Slider");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setSliceSliderVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }

    //selection menu
    menu = new Menu("Selection");
    menubar.getMenus().add(menu);
    Map<String, CheckMenuItem> mode_items = new HashMap<>();
    m_selection_mode_items = mode_items;
    mode_items.put("rectangle", new CheckMenuItem("Rectangle"));
    mode_items.put("ellipse", new CheckMenuItem("Ellipse"));
    Set<String> keys = mode_items.keySet();
    for (String key : keys) {
        CheckMenuItem item0 = mode_items.get(key);
        menu.getItems().add(item0);
        item0.setOnAction(evt -> {
            on_selection_mode_changed(key);
        });

    }
    mode_items.get("rectangle").setSelected(true);

    VBox root = new VBox();
    root.getChildren().addAll(menubar, m_widget);

    Scene scene = new Scene(root, 500, 450);

    primaryStage.setTitle("JViewMda");
    primaryStage.setScene(scene);
    primaryStage.show();

    if (array_path.length() > 0) {
        open_file(array_path);
    }

    m_prefs = Preferences.userNodeForPackage(this.getClass());

}

From source file:org.beryx.viewreka.fxapp.codearea.SimpleCodeArea.java

public SimpleCodeArea(String text) {
    super(text);//from  w w w . java 2  s. c  om

    putStyleGroup("KEYWORD", "keyword", NEVER_MATCHING);
    putStyleGroup("PAREN", "paren", PAREN_PATTERN);
    putStyleGroup("BRACE", "brace", BRACE_PATTERN);
    putStyleGroup("BRACKET", "bracket", BRACKET_PATTERN);
    putStyleGroup("SEMICOLON", "semicolon", SEMICOLON_PATTERN);
    putStyleGroup("STRING", "string", STRING_PATTERN);
    putStyleGroup("STRING2", "string", STRING2_PATTERN);
    putStyleGroup("COMMENT", "comment", COMMENT_PATTERN);

    String cssName = SimpleCodeArea.class.getSimpleName() + ".css";
    getStylesheets().add(SimpleCodeArea.class.getResource(cssName).toExternalForm());

    setParagraphGraphicFactory(LineNumberFactory.get(this));
    richChanges().subscribe(change -> {
        setStyleSpans(0, computeHighlighting(getText()));
    });
    EventHandler<? super KeyEvent> tabHandler = EventHandlerHelper.on(EventPattern.keyPressed(KeyCode.ENTER))
            .act(event -> applyEnter()).on(EventPattern.keyPressed(KeyCode.TAB)).act(event -> applyTab())
            .on(EventPattern.keyPressed(KeyCode.TAB, KeyCombination.SHIFT_DOWN)).act(event -> applyShiftTab())
            .create();
    EventHandlerHelper.install(onKeyPressedProperty(), tabHandler);
}

From source file:com.cdd.bao.editor.EditSchema.java

private void createMenuItems() {
    final KeyCombination.Modifier cmd = KeyCombination.SHORTCUT_DOWN, shift = KeyCombination.SHIFT_DOWN,
            alt = KeyCombination.ALT_DOWN;

    addMenu(menuFile, "_New", new KeyCharacterCombination("N", cmd)).setOnAction(event -> actionFileNew());
    addMenu(menuFile, "_Open", new KeyCharacterCombination("O", cmd)).setOnAction(event -> actionFileOpen());
    addMenu(menuFile, "_Save", new KeyCharacterCombination("S", cmd))
            .setOnAction(event -> actionFileSave(false));
    addMenu(menuFile, "Save _As", new KeyCharacterCombination("S", cmd, shift))
            .setOnAction(event -> actionFileSave(true));
    addMenu(menuFile, "_Export Dump", new KeyCharacterCombination("E", cmd))
            .setOnAction(event -> actionFileExportDump());
    addMenu(menuFile, "_Merge", null).setOnAction(event -> actionFileMerge());
    menuFile.getItems().add(new SeparatorMenuItem());
    addMenu(menuFile, "Confi_gure", new KeyCharacterCombination(",", cmd))
            .setOnAction(event -> actionFileConfigure());
    addMenu(menuFile, "_Browse Endpoint", new KeyCharacterCombination("B", cmd, shift))
            .setOnAction(event -> actionFileBrowse());
    if (false) {//from   w  w w.j  a v a  2  s .  c o m
        addMenu(menuFile, "_Upload Endpoint", new KeyCharacterCombination("U", cmd, shift))
                .setOnAction(event -> actionFileUpload());
    }
    Menu menuFileGraphics = new Menu("Graphics");
    addMenu(menuFileGraphics, "_Template", null).setOnAction(event -> actionFileGraphicsTemplate());
    addMenu(menuFileGraphics, "_Assay", null).setOnAction(event -> actionFileGraphicsAssay());
    addMenu(menuFileGraphics, "_Properties", null).setOnAction(event -> actionFileGraphicsProperties());
    addMenu(menuFileGraphics, "_Values", null).setOnAction(event -> actionFileGraphicsValues());
    menuFile.getItems().add(menuFileGraphics);
    addMenu(menuFile, "Assay Stats", null).setOnAction(event -> actionFileAssayStats());
    menuFile.getItems().add(new SeparatorMenuItem());
    addMenu(menuFile, "_Close", new KeyCharacterCombination("W", cmd)).setOnAction(event -> actionFileClose());
    addMenu(menuFile, "_Quit", new KeyCharacterCombination("Q", cmd)).setOnAction(event -> actionFileQuit());

    addMenu(menuEdit, "Add _Group", new KeyCharacterCombination("G", cmd, shift))
            .setOnAction(event -> actionGroupAdd());
    addMenu(menuEdit, "Add _Assignment", new KeyCharacterCombination("A", cmd, shift))
            .setOnAction(event -> actionAssignmentAdd());
    addMenu(menuEdit, "Add Assa_y", new KeyCharacterCombination("Y", cmd, shift))
            .setOnAction(event -> actionAssayAdd());
    menuEdit.getItems().add(new SeparatorMenuItem());
    addMenu(menuEdit, "Cu_t", new KeyCharacterCombination("X", cmd)).setOnAction(event -> actionEditCopy(true));
    addMenu(menuEdit, "_Copy", new KeyCharacterCombination("C", cmd))
            .setOnAction(event -> actionEditCopy(false));
    Menu menuCopyAs = new Menu("Copy As");
    menuEdit.getItems().add(menuCopyAs);
    addMenu(menuEdit, "_Paste", new KeyCharacterCombination("V", cmd)).setOnAction(event -> actionEditPaste());
    menuEdit.getItems().add(new SeparatorMenuItem());
    addMenu(menuEdit, "_Delete", new KeyCodeCombination(KeyCode.DELETE, cmd, shift))
            .setOnAction(event -> actionEditDelete());
    addMenu(menuEdit, "_Undo", new KeyCharacterCombination("Z", cmd, shift))
            .setOnAction(event -> actionEditUndo());
    addMenu(menuEdit, "_Redo", new KeyCharacterCombination("Z", cmd, shift, alt))
            .setOnAction(event -> actionEditRedo());
    menuEdit.getItems().add(new SeparatorMenuItem());
    addMenu(menuEdit, "Move _Up", new KeyCharacterCombination("[", cmd))
            .setOnAction(event -> actionEditMove(-1));
    addMenu(menuEdit, "Move _Down", new KeyCharacterCombination("]", cmd))
            .setOnAction(event -> actionEditMove(1));

    addMenu(menuCopyAs, "Layout Tab-Separated", null).setOnAction(event -> actionEditCopyLayoutTSV());

    addMenu(menuValue, "_Add Value", new KeyCharacterCombination("V", cmd, shift))
            .setOnAction(event -> detail.actionValueAdd());
    addMenu(menuValue, "Add _Multiple Values", new KeyCharacterCombination("M", cmd, shift))
            .setOnAction(event -> detail.actionValueMultiAdd());
    addMenu(menuValue, "_Delete Value", new KeyCodeCombination(KeyCode.DELETE, cmd))
            .setOnAction(event -> detail.actionValueDelete());
    addMenu(menuValue, "Move _Up", new KeyCodeCombination(KeyCode.UP, cmd))
            .setOnAction(event -> detail.actionValueMove(-1));
    addMenu(menuValue, "Move _Down", new KeyCodeCombination(KeyCode.DOWN, cmd))
            .setOnAction(event -> detail.actionValueMove(1));
    menuValue.getItems().add(new SeparatorMenuItem());
    addMenu(menuValue, "_Lookup URI", new KeyCharacterCombination("U", cmd))
            .setOnAction(event -> detail.actionLookupURI());
    addMenu(menuValue, "Lookup _Name", new KeyCharacterCombination("L", cmd))
            .setOnAction(event -> detail.actionLookupName());
    menuValue.getItems().add(new SeparatorMenuItem());
    addMenu(menuValue, "_Sort Values", null).setOnAction(event -> actionValueSort());
    addMenu(menuValue, "_Remove Duplicates", null).setOnAction(event -> actionValueDuplicates());
    addMenu(menuValue, "Cleanup Values", null).setOnAction(event -> actionValueCleanup());

    (menuViewSummary = addCheckMenu(menuView, "_Summary Values", new KeyCharacterCombination("-", cmd)))
            .setOnAction(event -> actionViewToggleSummary());
    addMenu(menuView, "_Template", new KeyCharacterCombination("1", cmd))
            .setOnAction(event -> actionViewTemplate());
    addMenu(menuView, "_Assays", new KeyCharacterCombination("2", cmd))
            .setOnAction(event -> actionViewAssays());
    addMenu(menuView, "_Derived Tree", new KeyCharacterCombination("3", cmd))
            .setOnAction(event -> detail.actionShowTree());
}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

private void initialize() {

    model = new TMATableModel();

    groupByIDProperty.addListener((v, o, n) -> refreshTableData());

    MenuBar menuBar = new MenuBar();
    Menu menuFile = new Menu("File");
    MenuItem miOpen = new MenuItem("Open...");
    miOpen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    miOpen.setOnAction(e -> {//from w  w w.j av  a2 s. co  m
        File file = QuPathGUI.getDialogHelper(stage).promptForFile(null, null, "TMA data files",
                new String[] { "qptma" });
        if (file == null)
            return;
        setInputFile(file);
    });

    MenuItem miSave = new MenuItem("Save As...");
    miSave.setAccelerator(
            new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    miSave.setOnAction(
            e -> SummaryMeasurementTableCommand.saveTableModel(model, null, Collections.emptyList()));

    MenuItem miImportFromImage = new MenuItem("Import from current image...");
    miImportFromImage.setAccelerator(
            new KeyCodeCombination(KeyCode.I, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    miImportFromImage.setOnAction(e -> setTMAEntriesFromOpenImage());

    MenuItem miImportFromProject = new MenuItem("Import from current project... (experimental)");
    miImportFromProject.setAccelerator(
            new KeyCodeCombination(KeyCode.P, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    miImportFromProject.setOnAction(e -> setTMAEntriesFromOpenProject());

    MenuItem miImportClipboard = new MenuItem("Import from clipboard...");
    miImportClipboard.setOnAction(e -> {
        String text = Clipboard.getSystemClipboard().getString();
        if (text == null) {
            DisplayHelpers.showErrorMessage("Import scores", "Clipboard is empty!");
            return;
        }
        int n = importScores(text);
        if (n > 0) {
            setTMAEntries(new ArrayList<>(entriesBase));
        }
        DisplayHelpers.showMessageDialog("Import scores", "Number of scores imported: " + n);
    });

    Menu menuEdit = new Menu("Edit");
    MenuItem miCopy = new MenuItem("Copy table to clipboard");
    miCopy.setOnAction(e -> {
        SummaryMeasurementTableCommand.copyTableContentsToClipboard(model, Collections.emptyList());
    });

    combinedPredicate.addListener((v, o, n) -> {
        // We want any other changes triggered by this to have happened, 
        // so that the data has already been updated
        Platform.runLater(() -> handleTableContentChange());
    });

    // Reset the scores for missing cores - this ensures they will be NaN and not influence subsequent results
    MenuItem miResetMissingScores = new MenuItem("Reset scores for missing cores");
    miResetMissingScores.setOnAction(e -> {
        int changes = 0;
        for (TMAEntry entry : entriesBase) {
            if (!entry.isMissing())
                continue;
            boolean changed = false;
            for (String m : entry.getMeasurementNames().toArray(new String[0])) {
                if (!TMASummaryEntry.isSurvivalColumn(m) && !Double.isNaN(entry.getMeasurementAsDouble(m))) {
                    entry.putMeasurement(m, null);
                    changed = true;
                }
            }
            if (changed)
                changes++;
        }
        if (changes == 0) {
            logger.info("No changes made when resetting scores for missing cores!");
            return;
        }
        logger.info("{} change(s) made when resetting scores for missing cores!", changes);
        table.refresh();
        updateSurvivalCurves();
        if (scatterPane != null)
            scatterPane.updateChart();
        if (histogramDisplay != null)
            histogramDisplay.refreshHistogram();
    });
    menuEdit.getItems().add(miResetMissingScores);

    QuPathGUI.addMenuItems(menuFile, miOpen, miSave, null, miImportClipboard, null, miImportFromImage,
            miImportFromProject);
    menuBar.getMenus().add(menuFile);
    menuEdit.getItems().add(miCopy);
    menuBar.getMenus().add(menuEdit);

    menuFile.setOnShowing(e -> {
        boolean imageDataAvailable = QuPathGUI.getInstance() != null
                && QuPathGUI.getInstance().getImageData() != null
                && QuPathGUI.getInstance().getImageData().getHierarchy().getTMAGrid() != null;
        miImportFromImage.setDisable(!imageDataAvailable);
        boolean projectAvailable = QuPathGUI.getInstance() != null
                && QuPathGUI.getInstance().getProject() != null
                && !QuPathGUI.getInstance().getProject().getImageList().isEmpty();
        miImportFromProject.setDisable(!projectAvailable);
    });

    // Double-clicking previously used for comments... but conflicts with tree table expansion
    //      table.setOnMouseClicked(e -> {
    //         if (!e.isPopupTrigger() && e.getClickCount() > 1)
    //            promptForComment();
    //      });

    table.setPlaceholder(new Text("Drag TMA data folder onto window, or choose File -> Open"));
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    BorderPane pane = new BorderPane();
    pane.setTop(menuBar);
    menuBar.setUseSystemMenuBar(true);

    // Create options
    ToolBar toolbar = new ToolBar();
    Label labelMeasurementMethod = new Label("Combination method");
    labelMeasurementMethod.setLabelFor(comboMeasurementMethod);
    labelMeasurementMethod
            .setTooltip(new Tooltip("Method whereby measurements for multiple cores with the same "
                    + TMACoreObject.KEY_UNIQUE_ID + " will be combined"));

    CheckBox cbHidePane = new CheckBox("Hide pane");
    cbHidePane.setSelected(hidePaneProperty.get());
    cbHidePane.selectedProperty().bindBidirectional(hidePaneProperty);

    CheckBox cbGroupByID = new CheckBox("Group by ID");
    entriesBase.addListener((Change<? extends TMAEntry> event) -> {
        if (!event.getList().stream().anyMatch(e -> e.getMetadataValue(TMACoreObject.KEY_UNIQUE_ID) != null)) {
            cbGroupByID.setSelected(false);
            cbGroupByID.setDisable(true);
        } else {
            cbGroupByID.setDisable(false);
        }
    });
    cbGroupByID.setSelected(groupByIDProperty.get());
    cbGroupByID.selectedProperty().bindBidirectional(groupByIDProperty);

    CheckBox cbUseSelected = new CheckBox("Use selection only");
    cbUseSelected.selectedProperty().bindBidirectional(useSelectedProperty);

    CheckBox cbSkipMissing = new CheckBox("Hide missing cores");
    cbSkipMissing.selectedProperty().bindBidirectional(skipMissingCoresProperty);
    skipMissingCoresProperty.addListener((v, o, n) -> {
        table.refresh();
        updateSurvivalCurves();
        if (histogramDisplay != null)
            histogramDisplay.refreshHistogram();
        updateSurvivalCurves();
        if (scatterPane != null)
            scatterPane.updateChart();
    });

    toolbar.getItems().addAll(labelMeasurementMethod, comboMeasurementMethod,
            new Separator(Orientation.VERTICAL), cbHidePane, new Separator(Orientation.VERTICAL), cbGroupByID,
            new Separator(Orientation.VERTICAL), cbUseSelected, new Separator(Orientation.VERTICAL),
            cbSkipMissing);
    comboMeasurementMethod.getItems().addAll(MeasurementCombinationMethod.values());
    comboMeasurementMethod.getSelectionModel().select(MeasurementCombinationMethod.MEDIAN);
    selectedMeasurementCombinationProperty.addListener((v, o, n) -> table.refresh());

    ContextMenu popup = new ContextMenu();
    MenuItem miSetMissing = new MenuItem("Set missing");
    miSetMissing.setOnAction(e -> setSelectedMissingStatus(true));

    MenuItem miSetAvailable = new MenuItem("Set available");
    miSetAvailable.setOnAction(e -> setSelectedMissingStatus(false));

    MenuItem miExpand = new MenuItem("Expand all");
    miExpand.setOnAction(e -> {
        if (table.getRoot() == null)
            return;
        for (TreeItem<?> item : table.getRoot().getChildren()) {
            item.setExpanded(true);
        }
    });
    MenuItem miCollapse = new MenuItem("Collapse all");
    miCollapse.setOnAction(e -> {
        if (table.getRoot() == null)
            return;
        for (TreeItem<?> item : table.getRoot().getChildren()) {
            item.setExpanded(false);
        }
    });
    popup.getItems().addAll(miSetMissing, miSetAvailable, new SeparatorMenuItem(), miExpand, miCollapse);
    table.setContextMenu(popup);

    table.setRowFactory(e -> {
        TreeTableRow<TMAEntry> row = new TreeTableRow<>();

        //         // Make rows invisible if they don't pass the predicate
        //         row.visibleProperty().bind(Bindings.createBooleanBinding(() -> {
        //               TMAEntry entry = row.getItem();
        //               if (entry == null || (entry.isMissing() && skipMissingCoresProperty.get()))
        //                     return false;
        //               return entries.getPredicate() == null || entries.getPredicate().test(entry);
        //               },
        //               skipMissingCoresProperty,
        //               entries.predicateProperty()));

        // Style rows according to what they contain
        row.styleProperty().bind(Bindings.createStringBinding(() -> {
            if (row.isSelected())
                return "";
            TMAEntry entry = row.getItem();
            if (entry == null || entry instanceof TMASummaryEntry)
                return "";
            else if (entry.isMissing())
                return "-fx-background-color:rgb(225,225,232)";
            else
                return "-fx-background-color:rgb(240,240,245)";
        }, row.itemProperty(), row.selectedProperty()));
        //         row.itemProperty().addListener((v, o, n) -> {
        //            if (n == null || n instanceof TMASummaryEntry || row.isSelected())
        //               row.setStyle("");
        //            else if (n.isMissing())
        //               row.setStyle("-fx-background-color:rgb(225,225,232)");            
        //            else
        //               row.setStyle("-fx-background-color:rgb(240,240,245)");            
        //         });
        return row;
    });

    BorderPane paneTable = new BorderPane();
    paneTable.setTop(toolbar);
    paneTable.setCenter(table);

    MasterDetailPane mdTablePane = new MasterDetailPane(Side.RIGHT, paneTable, createSidePane(), true);

    mdTablePane.showDetailNodeProperty().bind(Bindings.createBooleanBinding(
            () -> !hidePaneProperty.get() && !entriesBase.isEmpty(), hidePaneProperty, entriesBase));
    mdTablePane.setDividerPosition(2.0 / 3.0);

    pane.setCenter(mdTablePane);

    model.getEntries().addListener(new ListChangeListener<TMAEntry>() {
        @Override
        public void onChanged(ListChangeListener.Change<? extends TMAEntry> c) {
            if (histogramDisplay != null)
                histogramDisplay.refreshHistogram();
            updateSurvivalCurves();
            if (scatterPane != null)
                scatterPane.updateChart();
        }
    });

    Label labelPredicate = new Label();
    labelPredicate.setPadding(new Insets(5, 5, 5, 5));
    labelPredicate.setAlignment(Pos.CENTER);
    //      labelPredicate.setStyle("-fx-background-color: rgba(20, 120, 20, 0.15);");
    labelPredicate.setStyle("-fx-background-color: rgba(120, 20, 20, 0.15);");

    labelPredicate.textProperty().addListener((v, o, n) -> {
        if (n.trim().length() > 0)
            pane.setBottom(labelPredicate);
        else
            pane.setBottom(null);
    });
    labelPredicate.setMaxWidth(Double.MAX_VALUE);
    labelPredicate.setMaxHeight(labelPredicate.getPrefHeight());
    labelPredicate.setTextAlignment(TextAlignment.CENTER);
    predicateMeasurements.addListener((v, o, n) -> {
        if (n == null)
            labelPredicate.setText("");
        else if (n instanceof TablePredicate) {
            TablePredicate tp = (TablePredicate) n;
            if (tp.getOriginalCommand().trim().isEmpty())
                labelPredicate.setText("");
            else
                labelPredicate.setText("Predicate: " + tp.getOriginalCommand());
        } else
            labelPredicate.setText("Predicate: " + n.toString());
    });
    //      predicate.set(new TablePredicate("\"Tumor\" > 100"));

    scene = new Scene(pane);

    scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        KeyCode code = e.getCode();
        if ((code == KeyCode.SPACE || code == KeyCode.ENTER) && entrySelected != null) {
            promptForComment();
            return;
        }
    });

}

From source file:snpviewer.SnpViewer.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    labelSplitPane.setDividerPositions();
    chromSplitPane.setDividerPositions();
    Pane lpane = (Pane) horizontalSplit.getItems().get(0);
    SplitPane.setResizableWithParent(lpane, false);
    //mnemonics/shortcuts for menus        
    mainMenu.useSystemMenuBarProperty().set(true);
    fileMenu.setMnemonicParsing(true);/*from w ww  .  ja  v  a  2 s .c  om*/
    sampleMenu.setMnemonicParsing(true);
    goMenu.setMnemonicParsing(true);
    helpMenu.setMnemonicParsing(true);
    newProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN));
    loadProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN));
    addAffSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.A, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    addUnSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.U, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    nextChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.EQUALS, KeyCombination.SHORTCUT_DOWN));
    prevChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, KeyCombination.SHORTCUT_DOWN));
    firstChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN));
    lastChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.SHORTCUT_DOWN));
    redrawMenu.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN));
    cacheChromsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    saveToPngMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    autoFindRegions.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN));
    //need to disable hideSavedRegionsMenu accelerator for linux - doesn't work for check menus
    hideSavedRegionsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    clearSavedRegionsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.X, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    displaySavedsRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN));
    outputSavedRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    removeSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    //set radio menu item toggle group
    ArrayList<RadioMenuItem> callQualityRadios = new ArrayList<>(
            Arrays.asList(noFilteringRadio, filter99, filter95, filter90, filter85));
    ToggleGroup callQualityToggle = new ToggleGroup();
    for (RadioMenuItem r : callQualityRadios) {
        r.setToggleGroup(callQualityToggle);
    }
    noFilteringRadio.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(null);
        }
    });

    filter99.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.01);
        }
    });

    filter95.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.05);
        }
    });

    filter90.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.10);
        }
    });

    filter85.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.15);
        }
    });

    nextChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            selectNextChromosome(true);
        }
    });

    prevChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            selectNextChromosome(false);
        }
    });

    firstChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            if (!cancelButton.isDisabled()) {
                cancelButton.fire();
            }
            if (!chromosomeSelector.isDisabled()) {

                chromosomeSelector.getSelectionModel().selectFirst();
            }
        }
    });

    lastChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            if (!cancelButton.isDisabled()) {
                cancelButton.fire();
            }
            if (!chromosomeSelector.isDisabled()) {
                chromosomeSelector.getSelectionModel().selectLast();
            }
        }
    });

    hideSavedRegionsMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            showHideSavedRegions();
        }
    });

    colorComp.addAll(Arrays.asList(colorComponants));

    //selection context menu
    final ContextMenu scm = new ContextMenu();
    final MenuItem scmItem1 = new MenuItem("Display Flanking SNP IDs");
    scmItem1.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * flanking snp ids and coordinates
             */
            displayFlankingSnpIDs(dragSelectRectangle);

        }
    });
    final MenuItem scmItem2 = new MenuItem("Write Selected Region to File");
    scmItem2.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    writeRegionToFile(dragSelectRectangle);
                }
            });
        }
    });
    final MenuItem scmItem3 = new MenuItem("Add To Saved Regions");
    scmItem3.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * write SNPs in region to file
             */
            saveSelection();
        }
    });
    final MenuItem scmItem4 = new MenuItem("Show/Hide Saved Regions");
    scmItem4.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * write SNPs in region to file
             */
            hideSavedRegionsMenu.selectedProperty().setValue(!hideSavedRegionsMenu.isSelected());
            hideSavedRegionsMenu.fire();
        }
    });
    final MenuItem scmItem5 = new MenuItem("Zoom Region");
    scmItem5.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    zoomRegion(dragSelectRectangle);
                }
            });
        }
    });
    final MenuItem scmItem6 = new MenuItem("Write Saved Regions to File");
    scmItem6.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    writeSavedRegionsToFile();
                }
            });
        }
    });

    scm.getItems().add(scmItem1);
    scm.getItems().add(scmItem2);
    scm.getItems().add(scmItem3);
    scm.getItems().add(scmItem4);
    scm.getItems().add(scmItem5);
    scm.getItems().add(scmItem6);
    //overlayPane context menu
    ocm = new ContextMenu();
    final MenuItem ocmItem1 = new MenuItem("Save Image to File");
    ocmItem1.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    drawPaneToPng();
                }
            });
        }
    });

    ocm.getItems().add(ocmItem1);
    ocm.getItems().add(scmItem4);
    ocm.getItems().add(scmItem6);

    //color selections
    colorComponantSelector.getItems().clear();
    colorComponantSelector.getItems().add("AA");
    colorComponantSelector.getItems().add("BB");
    colorComponantSelector.getItems().add("AB");
    colorComponantSelector.getItems().add("Selection Outline");
    colorComponantSelector.getItems().add("Selection Fill");
    colorComponantSelector.getItems().add("Saved Region Outline");
    colorComponantSelector.getItems().add("Saved Region Fill");
    colorComponantSelector.getSelectionModel().selectFirst();
    colorPicker.setValue(colorComponants[0]);
    colorComponantSelector.getSelectionModel().selectedIndexProperty()
            .addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue ov, Number value, Number new_value) {
                    colorPicker.setValue(colorComp.get(new_value.intValue()));
                    colorPicker.fireEvent(new ActionEvent());
                }
            });
    colorPicker.setOnAction(new EventHandler() {
        @Override
        public void handle(Event t) {
            if (!colorComp.get(colorComponantSelector.getSelectionModel().getSelectedIndex())
                    .equals(colorPicker.getValue())) {
                colorComp.set(colorComponantSelector.getSelectionModel().getSelectedIndex(),
                        colorPicker.getValue());
                saveProject();
                //colorComponants[colorComponantSelector.getSelectionModel().getSelectedIndex()] = colorPicker.getValue();
                if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.fill.value) {
                    dragSelectRectangle.setFill(colorPicker.getValue());
                } else if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.line.value) {
                    dragSelectRectangle.setStroke(colorPicker.getValue());
                } else if (colorComponantSelector.getSelectionModel()
                        .getSelectedIndex() == Colors.saveLine.value) {
                    for (Rectangle r : savedRegionsDisplay) {
                        r.setStroke(colorPicker.getValue());
                    }
                } else if (colorComponantSelector.getSelectionModel()
                        .getSelectedIndex() == Colors.saveFill.value) {
                    for (Rectangle r : savedRegionsDisplay) {
                        r.setFill(colorPicker.getValue());
                    }
                } else {
                    removeSavedChromosomeImages();
                    if (redrawCheckBox.isSelected()) {
                        refreshView(null, true);
                    }
                }
            }
        }
    });

    /*perform appropriate action when user selects a chromosome
     * from the chromosome choice box
     */
    chromosomeSelector.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue ov, Number value, Number new_value) {
            chromosomeBoxList = chromosomeSelector.getItems().toArray();

            if (new_value.intValue() > -1) {
                chromosomeSelected((String) chromosomeBoxList[new_value.intValue()]);
            }
        }
    });

    chromosomeSelector.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.UP) {
                ke.consume();
                chromosomeSelector.show();
            }
        }
    });

    selectionOverlayPane.heightProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            windowResized(new ActionEvent());

        }
    });

    selectionOverlayPane.widthProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            windowResized(new ActionEvent());
        }
    });

    /*upon addition of a new affected file adjust components accordingly
     * i.e. ensure appropriate chromosomes are in the choice box
     * adjust the split panes to fit all files and redisplay
     */

    affObserve.addListener(new ListChangeListener() {
        @Override
        public void onChanged(ListChangeListener.Change change) {
            change.next();/*from the javadoc 
                          * 'Go to the next change. In initial state is invalid a require 
                          * a call to next() before calling other methods. The first 
                          * next() call will make this object represent the first change.
                          */
            if (change.getRemovedSize() > 0) {
                List<SnpFile> both = new ArrayList<>(unFiles);
                both.addAll(affFiles);
                recheckChromosomeSelector(both);//need to check all files again, not just affFiles
            } else if (change.getAddedSize() > 0) {
                addToChromosomeSelector(affFiles);
            }
        }
    });

    /*as above 
     * but for unaffected files
     */
    unObserve.addListener(new ListChangeListener() {
        @Override
        public void onChanged(ListChangeListener.Change change) {
            change.next();
            if (change.getRemovedSize() > 0) {
                List<SnpFile> both = new ArrayList<>(unFiles);
                both.addAll(affFiles);
                recheckChromosomeSelector(both);//need to check all files again, not just unFiles
            } else if (change.getAddedSize() > 0) {
                addToChromosomeSelector(unFiles);
            }

        }
    });

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1) {
                try {
                    ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
                    String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                            .getSelectedIndex()];
                    double coordinate = chromLength.getLength(currentChrom) / chromSplitPane.getWidth()
                            * e.getX();
                    positionIndicator.setText(nf.format(coordinate));

                } catch (Exception ex) {
                    positionIndicator.setText("Build Error!");
                }

            }
        }
    });
    /*handle mouse dragging and effect on dragSelectRectangle
     * 
     */
    dragSelectRectangle.widthProperty().bind(dragSelectRectX.subtract(dragSelectRectInitX));
    dragSelectRectangle.heightProperty().bind(selectionOverlayPane.heightProperty());
    //dragSelectRectangle.strokeProperty().set(colorComponants[Colors.line.value]);
    dragSelectRectangle.setStrokeWidth(4.0);

    //dragSelectRectangle.setBlendMode(BlendMode.SCREEN);
    dragSelectRectangle.setOpacity(0.45);
    dragSelectRectangle.setVisible(false);
    selectionOverlayPane.getChildren().add(dragSelectRectangle);

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (scm.isShowing()) {
                scm.hide();
            }
            if (!e.isPrimaryButtonDown()) {
                if (e.isSecondaryButtonDown()) {
                    //check we're not overlapping selection
                    if (e.getX() >= dragSelectRectangle.getX()
                            && e.getX() <= (dragSelectRectangle.getX() + dragSelectRectangle.getWidth())) {
                        return;
                    }
                    //check we're not overlapping saved regions
                    for (Rectangle r : savedRegionsDisplay) {
                        if (r.isVisible() && e.getX() >= r.getX() && e.getX() <= r.getX() + r.getWidth()) {
                            return;
                        }
                    }
                    if (chromosomeSelector.getSelectionModel().isEmpty()) {
                        ocmItem1.setDisable(true);
                    } else {
                        ocmItem1.setDisable(false);
                    }
                    ocm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY());

                    return;
                }
            }
            if (ocm.isShowing()) {
                ocm.hide();
            }

            dragSelectRectangle.strokeProperty().set(colorComp.get(Colors.line.value));
            dragSelectRectangle.fillProperty().set(colorComp.get(Colors.fill.value));
            dragSelectRectX.set(0);
            dragSelectRectangle.setVisible(true);
            dragSelectRectangle.setX(e.getX());
            dragSelectRectangle.setY(0);
            dragSelectRectInitX.set(e.getX());
            anchorInitX.set(e.getX());

        }
    });
    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (!e.isPrimaryButtonDown()) {
                return;
            }
            dragSelectRectangle.setVisible(true);
            if (e.getX() > anchorInitX.doubleValue()) {//dragging to the right
                if (e.getX() <= selectionOverlayPane.getLayoutX() + selectionOverlayPane.getWidth()) {
                    //mouse is before the edge of the pane
                    dragSelectRectInitX.set(anchorInitX.doubleValue());
                    dragSelectRectX.set(e.getX());
                } else {
                    //mouse is over the edge
                    dragSelectRectX.set(selectionOverlayPane.getWidth());
                }
            } else {
                if (e.getX() > selectionOverlayPane.getLayoutX()) {
                    dragSelectRectInitX.set(e.getX());
                    dragSelectRectangle.setX(e.getX());
                    dragSelectRectX.set(anchorInitX.doubleValue());
                } else {
                    dragSelectRectInitX.set(0);
                    dragSelectRectangle.setX(0);
                    /* the two lines below are just to trigger 
                    * dragSelectRectangle.widthProperty listener 
                    * so that start coordinate changes to 1
                    */
                    dragSelectRectX.set(anchorInitX.doubleValue() + 1);
                    dragSelectRectX.set(anchorInitX.doubleValue() + 1);

                }
            }
        }
    });

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            //dragSelectRectX.set(e.getX());
            if (!e.isPrimaryButtonDown()) {
                return;
            }
            dragSelectRectangle.setVisible(true);
            if (dragSelectRectangle.getWidth() == 0) {
                clearDragSelectRectangle();
            }
        }
    });

    dragSelectRectangle.widthProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observableValue, Object oldValue, Object newRectWidth) {
            if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1
                    && dragSelectRectangle.getWidth() > 0) {
                try {
                    ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
                    String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                            .getSelectedIndex()];
                    double startCoordinate = chromLength.getLength(currentChrom)
                            / selectionOverlayPane.getWidth() * dragSelectRectangle.getX();
                    double selectionWidth = chromLength.getLength(currentChrom)
                            / selectionOverlayPane.getWidth() * dragSelectRectangle.getWidth();
                    if (dragSelectRectangle.getX() == 0) {
                        startCoordinate = 1;
                    }
                    selectionIndicator.setText("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-"
                            + nf.format(startCoordinate + selectionWidth));
                } catch (Exception ex) {
                    selectionIndicator.setText("Build Error!");
                }
            } else {
                selectionIndicator.setText("");
            }

        }
    });

    dragSelectRectangle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (e.getButton() == MouseButton.SECONDARY) {
                if (chromosomeSelector.getSelectionModel().isEmpty()) {
                    scmItem1.setDisable(true);
                    scmItem2.setDisable(true);
                } else {
                    scmItem1.setDisable(false);
                    scmItem2.setDisable(false);
                }
                if (ocm.isShowing()) {
                    ocm.hide();
                }

                scm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY());
            }
        }
    });

}