Example usage for javafx.scene.input ContextMenuEvent getScreenX

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

Introduction

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

Prototype

public final double getScreenX() 

Source Link

Document

Returns absolute horizontal position of the event.

Usage

From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java

public void addFormatIcons() {
    colFormats.setCellFactory(/*from www.ja  va2 s. c  om*/
            new Callback<TableColumn<ReportRow, ObservableMap<String, String>>, TableCell<ReportRow, ObservableMap<String, String>>>() {
                @Override
                public TableCell<ReportRow, ObservableMap<String, String>> call(
                        TableColumn<ReportRow, ObservableMap<String, String>> param) {
                    TableCell<ReportRow, ObservableMap<String, String>> cell = new TableCell<ReportRow, ObservableMap<String, String>>() {
                        @Override
                        public void updateItem(ObservableMap<String, String> item, boolean empty) {
                            super.updateItem(item, empty);
                            if (!empty && item != null) {

                                HBox box = new HBox();
                                box.setSpacing(3);
                                box.setAlignment(Pos.CENTER_LEFT);

                                for (String i : item.keySet()) {
                                    ImageView icon = new ImageView();
                                    icon.setId("but" + i);
                                    icon.setFitHeight(20);
                                    icon.setFitWidth(20);
                                    icon.setImage(new Image("images/formats/" + i + ".png"));
                                    icon.setCursor(Cursor.HAND);

                                    String type = i;
                                    String path = item.get(i);
                                    icon.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                        @Override
                                        public void handle(MouseEvent event) {
                                            ArrayMessage am = new ArrayMessage();
                                            am.add(GuiConfig.PERSPECTIVE_SHOW, new UiMessage());
                                            am.add(GuiConfig.PERSPECTIVE_SHOW + "." + GuiConfig.COMPONENT_SHOW,
                                                    new ShowMessage(type, path));
                                            getContext().send(GuiConfig.PERSPECTIVE_SHOW, am);
                                        }
                                    });

                                    ContextMenu contextMenu = new ContextMenu();
                                    javafx.scene.control.MenuItem download = new javafx.scene.control.MenuItem(
                                            "Download report");
                                    contextMenu.getItems().add(download);
                                    icon.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                                        public void handle(ContextMenuEvent e) {
                                            contextMenu.show(icon, e.getScreenX(), e.getScreenY());
                                        }
                                    });
                                    box.getChildren().add(icon);
                                }

                                setGraphic(box);
                            } else {
                                setGraphic(null);
                            }
                        }
                    };
                    return cell;
                }
            });
}