Example usage for javafx.scene.input ContextMenuEvent getX

List of usage examples for javafx.scene.input ContextMenuEvent getX

Introduction

In this page you can find the example usage for javafx.scene.input ContextMenuEvent getX.

Prototype

public final double getX() 

Source Link

Document

Horizontal position of the event relative to the origin of the ContextMenuEvent's source.

Usage

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleContextMenuShowing(ContextMenuEvent event) {

    // Calculate the m/z value of the clicked point
    final double clickedX = event.getX();
    XYPlot plot = chartNode.getChart().getXYPlot();
    Rectangle2D chartArea = chartNode.getRenderingInfo().getPlotInfo().getDataArea();
    RectangleEdge axisEdge = plot.getDomainAxisEdge();
    ValueAxis domainAxis = plot.getDomainAxis();
    final double clickedMz = domainAxis.java2DToValue(clickedX, chartArea, axisEdge);
    final double clickedMzWithShift = Math.abs(clickedMz - mzShift.get());

    // Update the m/z shift menu item
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    setToMenuItem.setText("Set to " + mzFormat.format(clickedMz) + " m/z");
    setToMenuItem.setUserData(clickedMz);

    // Update the Show XIC menu item
    showXICMenuItem.setText("Show XIC of " + mzFormat.format(clickedMzWithShift) + " m/z");
    showXICMenuItem.setUserData(clickedMzWithShift);

    // Update the MS/MS menu
    findMSMSMenu.setText("Find MS/MS of " + mzFormat.format(clickedMzWithShift) + " m/z");
    final ObservableList<MenuItem> msmsItems = findMSMSMenu.getItems();
    msmsItems.clear();/*from  w w w .ja v  a2  s . c  om*/
    MZmineProject project = MZmineCore.getCurrentProject();
    for (RawDataFile file : project.getRawDataFiles()) {
        scans: for (MsScan scan : file.getScans()) {
            if (scan.getMsFunction().getMsLevel() == 1)
                continue;
            for (IsolationInfo isolation : scan.getIsolations()) {
                if (!isolation.getIsolationMzRange().contains(clickedMzWithShift))
                    continue;
                String menuLabel = MsScanUtils.createSingleLineMsScanDescription(scan, isolation);
                MenuItem msmsItem = new MenuItem(menuLabel);
                msmsItem.setOnAction(e -> MsSpectrumPlotModule.showNewSpectrumWindow(scan));
                msmsItems.add(msmsItem);
                continue scans;
            }
        }
    }
    if (msmsItems.isEmpty()) {
        MenuItem noneItem = new MenuItem("None");
        noneItem.setDisable(true);
        msmsItems.add(noneItem);
    }

    // Update the Remove... menu
    final ObservableList<MenuItem> rmItems = removeDatasetMenu.getItems();
    rmItems.clear();
    for (MsSpectrumDataSet dataset : datasets) {
        MenuItem msmsItem = new MenuItem(dataset.getName());
        msmsItem.setOnAction(e -> datasets.remove(dataset));
        rmItems.add(msmsItem);
    }
    removeDatasetMenu.setDisable(rmItems.isEmpty());

}