Example usage for javafx.scene.input MouseButton SECONDARY

List of usage examples for javafx.scene.input MouseButton SECONDARY

Introduction

In this page you can find the example usage for javafx.scene.input MouseButton SECONDARY.

Prototype

MouseButton SECONDARY

To view the source code for javafx.scene.input MouseButton SECONDARY.

Click Source Link

Document

Represents seconday (button 3, usually the right) mouse button.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);
    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(fileMenu(), cameraMenu(), alarmMenu());
    root.setTop(menuBar);//from w w w .  j  ava2s . co  m
    ContextMenu contextFileMenu = new ContextMenu(exitMenuItem());

    primaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent me) -> {
        if (me.getButton() == MouseButton.SECONDARY || me.isControlDown()) {
            contextFileMenu.show(root, me.getScreenX(), me.getScreenY());
        } else {
            contextFileMenu.hide();
        }
    });
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:de.pixida.logtest.designer.automaton.Graph.java

public void onMouseClicked(final BaseObject baseObject, final MouseEvent event) {
    Validate.notNull(baseObject);/*from   www .ja va 2  s  . c o  m*/

    this.contextMenu.hide();

    if (event.getButton() == MouseButton.PRIMARY) {
        if (this.connectorSourceNode != null) {
            Validate.notNull(this.connector);
            if (baseObject == this.currentConnectorTargetNode) {
                this.connector.attach(this.connectorSourceNode, this.currentConnectorTargetNode);

                this.connector = null;
                this.connectorSourceNode = null;
                this.currentConnectorTargetNode = null;

                this.handleChange();
            }
        }
        event.consume();
    } else if (event.getButton() == MouseButton.SECONDARY) {
        final ContextMenu objectContextMenu = baseObject.createContextMenu();
        if (objectContextMenu != null) {
            Node contextMenuOwner = baseObject.getActionHandler();
            if (contextMenuOwner == null) {
                contextMenuOwner = this.pane;
            }
            objectContextMenu.show(contextMenuOwner, event.getScreenX(), event.getScreenY());
            event.consume();
        }
    }
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

public ChartViewer(String title, int width, int height, int maxChartNumberInARow) {

    stage = new Stage();
    stage.setTitle(title);// www  .ja v  a2s .  co  m
    stage.setWidth(width);
    stage.setHeight(height);

    this.maxChartNumberInARow = maxChartNumberInARow;

    this.setContextMenu(createContextMenu());

    vBoxPane = new VBox();
    scrollPane = new ScrollPane();
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setFitToHeight(true);
    scrollPane.setFitToWidth(true);
    scrollPane.setPannable(true);

    scrollPane.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            MouseButton button = event.getButton();
            if (button == MouseButton.SECONDARY) {
                menu.show(stage, event.getScreenX(), event.getScreenY());
            }
        }
    });

    scrollPane.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            refreshChartPositionAndSize();
        }
    });

    scrollPane.heightProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            refreshChartPositionAndSize();
        }
    });

    vBoxPane.getChildren().add(new HBox());
    scrollPane.setContent(vBoxPane);

    chartCanvasList = new ArrayList<>();
    stage.setScene(new Scene(scrollPane));

}

From source file:de.pixida.logtest.designer.automaton.Graph.java

private void mouseClickedOnPane(final MouseEvent event) {
    this.contextMenu.hide();
    if (event.getButton() == MouseButton.PRIMARY) {
        if (this.connectorSourceNode != null) {
            Validate.notNull(this.connector);
            this.cancelDrawingConnector();
        } else {//from  www. java 2  s  .c  o m
            this.automatonEditor.showDefaultConfigFrame();
        }
    } else if (event.getButton() == MouseButton.SECONDARY) {
        this.contextMenu.show(this.pane, event.getScreenX(), event.getScreenY());
    }
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Menu Sample");
    Scene scene = new Scene(new VBox(), 400, 350);
    scene.setFill(Color.OLDLACE);

    name.setFont(new Font("Verdana Bold", 22));
    binName.setFont(new Font("Arial Italic", 10));
    pic.setFitHeight(150);/*from   www .j  a  v  a2  s.c om*/
    pic.setPreserveRatio(true);
    description.setWrapText(true);
    description.setTextAlignment(TextAlignment.JUSTIFY);

    shuffle();

    MenuBar menuBar = new MenuBar();

    // --- Graphical elements
    final VBox vbox = new VBox();
    vbox.setAlignment(Pos.CENTER);
    vbox.setSpacing(10);
    vbox.setPadding(new Insets(0, 10, 0, 10));
    vbox.getChildren().addAll(name, binName, pic, description);

    // --- Menu File
    Menu menuFile = new Menu("File");
    MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png")));
    add.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            shuffle();
            vbox.setVisible(true);
        }
    });

    MenuItem clear = new MenuItem("Clear");
    clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X"));
    clear.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            vbox.setVisible(false);
        }
    });

    MenuItem exit = new MenuItem("Exit");
    exit.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            System.exit(0);
        }
    });

    menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit);

    // --- Menu Edit
    Menu menuEdit = new Menu("Edit");
    Menu menuEffect = new Menu("Picture Effect");

    final ToggleGroup groupEffect = new ToggleGroup();
    for (Entry effect : effects) {
        RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey());
        itemEffect.setUserData(effect.getValue());
        itemEffect.setToggleGroup(groupEffect);
        menuEffect.getItems().add(itemEffect);
    }

    final MenuItem noEffects = new MenuItem("No Effects");
    noEffects.setDisable(true);
    noEffects.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            pic.setEffect(null);
            groupEffect.getSelectedToggle().setSelected(false);
            noEffects.setDisable(true);
        }
    });

    groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) {
            if (groupEffect.getSelectedToggle() != null) {
                Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData();
                pic.setEffect(effect);
                noEffects.setDisable(false);
            } else {
                noEffects.setDisable(true);
            }
        }
    });

    menuEdit.getItems().addAll(menuEffect, noEffects);

    // --- Menu View
    Menu menuView = new Menu("View");
    CheckMenuItem titleView = createMenuItem("Title", name);
    CheckMenuItem binNameView = createMenuItem("Binomial name", binName);
    CheckMenuItem picView = createMenuItem("Picture", pic);
    CheckMenuItem descriptionView = createMenuItem("Decsription", description);

    menuView.getItems().addAll(titleView, binNameView, picView, descriptionView);
    menuBar.getMenus().addAll(menuFile, menuEdit, menuView);

    // --- Context Menu
    final ContextMenu cm = new ContextMenu();
    MenuItem cmItem1 = new MenuItem("Copy Image");
    cmItem1.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Clipboard clipboard = Clipboard.getSystemClipboard();
            ClipboardContent content = new ClipboardContent();
            content.putImage(pic.getImage());
            clipboard.setContent(content);
        }
    });

    cm.getItems().add(cmItem1);
    pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (e.getButton() == MouseButton.SECONDARY)
                cm.show(pic, e.getScreenX(), e.getScreenY());
        }
    });

    ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:be.makercafe.apps.makerbench.Main.java

/**
 * Creates the viewer control/* w  ww  .  jav  a 2s .c  o  m*/
 *
 * @return
 */
private TreeView<String> createViewer() {
    TreeView<String> viewer = new TreeView<String>(setRootFolder(new File(this.pathMakerbenchHome)));
    viewer.setMinWidth(200.0);
    viewer.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    viewer.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {

            if (mouseEvent.getClickCount() == 2) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                //               System.out.println("Selected Text : " + item.getValue());

                createEditor(item.getValue(), item.getPath(), null);
            } else if (mouseEvent.getButton() == MouseButton.SECONDARY) {
                ResourceTreeItem<String> item = (ResourceTreeItem<String>) viewer.getSelectionModel()
                        .getSelectedItem();
                if (item.getPath().toFile().isFile()) {
                    viewer.getContextMenu().getItems().get(0).setDisable(true);
                    viewer.getContextMenu().getItems().get(1).setDisable(true);
                    viewer.getContextMenu().getItems().get(2).setDisable(true);
                } else {
                    viewer.getContextMenu().getItems().get(0).setDisable(false);
                    viewer.getContextMenu().getItems().get(1).setDisable(false);
                    viewer.getContextMenu().getItems().get(2).setDisable(false);
                }
            }

        }
    });
    viewer.setContextMenu(rootContextMenu);
    viewer.setEditable(false);
    viewer.setShowRoot(false);

    return viewer;
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Handle table row click event/* w w w .j a v  a2  s .c  om*/
 *
 * @param event
 */
public void handleTableRowClick(MouseEvent event) {
    streamPacketTableView.setContextMenu(null);
    if (event.getClickCount() == 2 && streamPacketTableView.getSelectionModel().getSelectedItem() != null) {
        openStreamDialog(StreamBuilderType.EDIT_STREAM);
    } else if (event.getButton() == MouseButton.SECONDARY
            && streamPacketTableView.getSelectionModel().getSelectedItem() != null) {
        streamPacketTableView.setContextMenu(rightClickMenu);
    }
}

From source file:com.github.drbookings.ui.controller.MainController.java

private void initTableViewContextMenus() {
    final ContextMenu menu = new ContextMenu();
    final MenuItem mi1 = new MenuItem("Delete");
    final MenuItem mi2 = new MenuItem("Add");
    final MenuItem mi3 = new MenuItem("Modify");
    mi1.setOnAction(event -> {//  w ww.  java2s .co  m
        Platform.runLater(() -> deleteSelected());
    });
    mi2.setOnAction(event -> {
        Platform.runLater(() -> addBooking());
    });
    mi3.setOnAction(event -> {
        Platform.runLater(() -> showModifyBookingDialog());
    });
    menu.getItems().addAll(mi2, mi1, mi3);

    tableView.setContextMenu(menu);
    tableView.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> {
        if (t.getButton() == MouseButton.SECONDARY) {
            menu.show(tableView, t.getScreenX(), t.getScreenY());
        }
    });
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void gereSourisPanoramique(MouseEvent me) {
    if (me.getButton() == MouseButton.SECONDARY) {
        if (me.isShiftDown()) {
            panoChoixNord(me.getSceneX() - imagePanoramique.getLayoutX());
            me.consume();// w  ww.ja v a2 s  .  co  m
        } else if (me.isControlDown()) {
        } else {
            panoChoixRegard(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
            me.consume();
        }
    }
    if (me.getButton() == MouseButton.PRIMARY) {
        if (me.isShiftDown()) {
            if (!me.isControlDown()) {
                if (!dragDrop) {
                    panoAjouteImage(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
                } else {
                    dragDrop = false;
                }
            } else {

            }
        } else if (!(me.isControlDown()) && estCharge) {
            if (!dragDrop) {
                panoMouseClic(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
            } else {
                dragDrop = false;
            }
        }
    }
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param mouseEvent/*from w w  w . ja v  a  2s .c  o m*/
 */
private static void gereSourisPanoramique(MouseEvent mouseEvent) {
    if (mouseEvent.getButton() == MouseButton.SECONDARY) {
        if (mouseEvent.isShiftDown()) {
            panoChoixNord(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX());
            mouseEvent.consume();
        } else if (mouseEvent.isControlDown()) {
        } else {
            panoChoixRegard(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                    mouseEvent.getSceneY() - getiDecalageMac());
            mouseEvent.consume();
        }
    }
    if (mouseEvent.getButton() == MouseButton.PRIMARY) {
        if (!(mouseEvent.isControlDown()) && bEstCharge) {
            if (!bDragDrop) {
                panePanoramique.setCursor(Cursor.DEFAULT);
                panePanoramique.setOnMouseClicked((me) -> {
                });
                Circle c1 = new Circle(mouseEvent.getSceneX(),
                        mouseEvent.getSceneY() - panePanoramique.getLayoutY() - 130 - getiDecalageMac(), 3);
                panePanoramique.getChildren().add(c1);
                ListView<String> lvMenuChoixTypeHotspot = new ListView<>();
                double tailleFenetre = 70;
                if (getiNombrePanoramiques() > 1) {
                    lvMenuChoixTypeHotspot.getItems().add("Panoramique");
                    tailleFenetre += 20;
                }
                lvMenuChoixTypeHotspot.getItems().add("Image");
                if (getiNombreDiapo() > 0) {
                    lvMenuChoixTypeHotspot.getItems().add("Diaporama");
                    tailleFenetre += 20;
                }
                lvMenuChoixTypeHotspot.getItems().add("HTML");
                lvMenuChoixTypeHotspot.getItems().add("Annuler");
                lvMenuChoixTypeHotspot.setMaxHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setPrefHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setMinHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setPrefWidth(120);
                lvMenuChoixTypeHotspot.setCursor(Cursor.DEFAULT);
                lvMenuChoixTypeHotspot.setLayoutX(mouseEvent.getSceneX());
                lvMenuChoixTypeHotspot.setLayoutY(
                        mouseEvent.getSceneY() - panePanoramique.getLayoutY() - 104 - getiDecalageMac());
                panePanoramique.getChildren().add(lvMenuChoixTypeHotspot);
                lvMenuChoixTypeHotspot.getSelectionModel().selectedItemProperty()
                        .addListener((ov, ancValeur, nouvValeur) -> {
                            panePanoramique.getChildren().remove(lvMenuChoixTypeHotspot);
                            panePanoramique.getChildren().remove(c1);

                            switch (nouvValeur) {
                            case "Panoramique":
                                panoMouseClic(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Image":
                                panoAjouteImage(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "HTML":
                                panoAjouteHTML(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Diaporama":
                                panoAjouteDiaporama(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Annuler":
                                break;

                            }
                            panePanoramique.setCursor(Cursor.CROSSHAIR);
                            panePanoramique.setOnMouseClicked((me) -> {
                                gereSourisPanoramique(me);
                            });

                        });

            } else {
                bDragDrop = false;
            }
        }
    }
}