Example usage for javafx.scene.input MouseEvent getButton

List of usage examples for javafx.scene.input MouseEvent getButton

Introduction

In this page you can find the example usage for javafx.scene.input MouseEvent getButton.

Prototype

public final MouseButton getButton() 

Source Link

Document

Which, if any, of the mouse buttons is responsible for this event.

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  www.j  a  va 2s  . c om
    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:account.management.controller.ViewPOVoucherController.java

/**
 * Initializes the controller class.//w w  w.  j a  v  a 2  s.c  o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    this.no.setCellValueFactory(new PropertyValueFactory("id"));
    this.date.setCellValueFactory(new PropertyValueFactory("date"));
    this.name.setCellValueFactory(new PropertyValueFactory("name"));
    this.address.setCellValueFactory(new PropertyValueFactory("address"));
    this.total_amount.setCellValueFactory(new PropertyValueFactory("total_amount"));
    this.opening.setCellValueFactory(new PropertyValueFactory("opening"));
    this.total.setCellValueFactory(new PropertyValueFactory("total"));
    this.cash.setCellValueFactory(new PropertyValueFactory("cash"));
    this.balance.setCellValueFactory(new PropertyValueFactory("balance"));

    this.table.setOnMouseClicked((MouseEvent mouseEvent) -> {
        if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
            if (mouseEvent.getClickCount() == 2) {
                POVoucher po = this.table.getSelectionModel().getSelectedItem();
                try {
                    showReport(po.getId(), po.getName(), po.getAddress(), po.getDate(), po.getContent(),
                            po.getTotal_amount(), po.getOpening(), po.getTotal(), po.getCash(),
                            po.getBalance());
                } catch (ParseException ex) {
                    Logger.getLogger(ViewPOVoucherController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

}

From source file:poe.trade.assist.SearchPane.java

private void setupTableClickListener() {
    searchTable.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override/*from   w  w w . ja v a  2 s .c o  m*/
        public void handle(MouseEvent event) {
            if (event.getButton() == MouseButton.SECONDARY) {
                Search search = searchTable.getSelectionModel().getSelectedItem();
                if (search != null) {
                    search.markSeen();
                }
            }
        }
    });
    searchTable.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getClickCount() > 1 && event.getButton() == MouseButton.PRIMARY) {
                Search search = searchTable.getSelectionModel().getSelectedItem();
                if (search != null) {
                    SwingUtil.openUrlViaBrowser(search.getUrl());
                }
            }
        }
    });
}

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 {/* www  .j a  va  2  s.  com*/
            this.automatonEditor.showDefaultConfigFrame();
        }
    } else if (event.getButton() == MouseButton.SECONDARY) {
        this.contextMenu.show(this.pane, event.getScreenX(), event.getScreenY());
    }
}

From source file:mesclasses.view.TimetableController.java

private void handleClicks(Pane pane) {
    pane.setOnMouseClicked((MouseEvent mouseEvent) -> {
        if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
            if (mouseEvent.getClickCount() == 2) {
                Cours newCours = new Cours();
                newCours.setClasse(classes.get(0));
                newCours.setDay(paneMap.inverse().get(pane));
                newCours.setWeek(config.getProperty(Constants.CONF_WEEK_DEFAULT));
                newCours.setStartHour((int) (mouseEvent.getY()) / 60 + 7);
                newCours.setEndHour(newCours.getStartHour() + 1);
                createNewCours(newCours);
            }//  w w w .j  a v a  2 s . co m
        }
    });
}

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

public void onMouseClicked(final BaseObject baseObject, final MouseEvent event) {
    Validate.notNull(baseObject);/*from   w ww.j av a2s  . 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:account.management.controller.ViewVouchersController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(select_location);
    select_location.setOnHiding((e) -> {
        Location a = select_location.getSelectionModel().getSelectedItem();
        select_location.setEditable(false);
        select_location.getSelectionModel().select(a);
    });// w ww. j a  va 2 s .co m
    select_location.setOnShowing((e) -> {
        select_location.setEditable(true);
    });

    new AutoCompleteComboBoxListener<>(select_voucher_type);
    select_voucher_type.setOnHiding((e) -> {
        VoucherType a = select_voucher_type.getSelectionModel().getSelectedItem();
        select_voucher_type.setEditable(false);
        select_voucher_type.getSelectionModel().select(a);
    });
    select_voucher_type.setOnShowing((e) -> {
        select_voucher_type.setEditable(true);
    });

    account_list = FXCollections.observableArrayList();
    this.account_list = this.getAccounts();
    c_id.setCellValueFactory(new PropertyValueFactory("id"));
    c_date.setCellValueFactory(new PropertyValueFactory("date"));
    c_location.setCellValueFactory(new PropertyValueFactory("location"));
    c_narration.setCellValueFactory(new PropertyValueFactory("narration"));
    c_voucher_type.setCellValueFactory(new PropertyValueFactory("voucher_type"));

    table.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    try {
                        JSONArray res = Unirest.get(MetaData.baseUrl + "get/voucher/with/date")
                                .queryString("start_date", start_date.getValue().toString())
                                .queryString("end_date", end_date.getValue().toString())
                                .queryString("id", table.getSelectionModel().getSelectedItem().getId()).asJson()
                                .getBody().getArray();
                        Voucher v = table.getSelectionModel().getSelectedItem();
                        gerReport("VN" + String.format("%03d", Integer.parseInt(v.getId())), v.getDate(),
                                v.getNarration(), v.getVoucher_type(), v.getLocation(), res.toString());
                        System.out.println(res);
                    } catch (UnirestException ex) {
                        Logger.getLogger(ViewVouchersController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    });

    locations = FXCollections.observableArrayList();
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
            JSONArray location_array = response.getBody().getArray();
            locations.add(new Location(0, "All", ""));
            for (int i = 0; i < location_array.length() - 1; i++) {
                String name = location_array.getJSONObject(i).getString("name");
                String details = location_array.getJSONObject(i).getString("details");
                int id = location_array.getJSONObject(i).getInt("id");
                locations.add(new Location(id, name, details));
            }
            select_location.getItems().addAll(locations);

        } catch (UnirestException ex) {
            System.out.println("exception in UNIREST");
        }
    }).start();

    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/voucher/type").asJson();
            JSONArray type = res.getBody().getArray();
            this.select_voucher_type.getItems().add(new VoucherType(0, "All", ""));
            for (int i = 0; i < type.length(); i++) {
                JSONObject obj = type.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("type_name").toString();
                String note = obj.get("details").toString();
                this.select_voucher_type.getItems().add(new VoucherType(id, name, note));
            }
        } catch (UnirestException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }).start();
}

From source file:photobooth.views.ExplorerPane.java

private BorderPane createImageView(final File imageFile) {
    // DEFAULT_THUMBNAIL_WIDTH is a constant you need to define
    // The last two arguments are: preserveRatio, and use smooth (slower)
    // resizing/*from w w w .ja  v a 2  s .c o m*/
    ExplorerPane explorerPane = this;
    ImageView imageView = null;
    BorderPane borderPane = new BorderPane();
    try {
        borderPane.setMaxSize(100, 100);
        borderPane.setMinSize(100, 100);
        FileInputStream fileInputStream = new FileInputStream(imageFile);
        final Image image = new Image(fileInputStream, 100, 100, true, true);
        imageView = new ImageView(image);
        fileInputStream.close();
        imageView.getStyleClass().add("image-view");
        borderPane.setCenter(imageView);
        //imageView.setFitWidth(80);
        imageView.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent mouseEvent) {

                if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {

                    if (mouseEvent.getClickCount() == 1) {
                        Global.getInstance().setSceneRoot(LoadingPane.getInstance());

                        Platform.runLater(() -> {
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    ImagePane.getInstance().init(explorerPane, imageFile);
                                    Global.getInstance().setSceneRoot(ImagePane.getInstance());
                                }
                            }).start();
                        });

                    }
                }
            }
        });
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
    }
    return borderPane;
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualization.java

protected void setChartClickHandler() {
    chart.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> {
        if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()) {
            selectedNodes.clear();//  w  w w .  j a  v  a  2 s.c o  m
        }
    });
}

From source file:View.Visualize.java

private void addColorChangeOnIndividual(ObservableList<XYChart.Data> data) {

    final ContextMenu contextMenu = new ContextMenu();
    MenuItem changeColor = new MenuItem("Change Color");
    MenuItem delete = new MenuItem("Standard color");

    ColorPicker cp = new ColorPicker();
    changeColor.setGraphic(cp);//from w  ww  . j ava2  s.  c om
    contextMenu.getItems().addAll(changeColor, delete);

    for (XYChart.Data d : data) {

        d.getNode().setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                if (t.getButton() == MouseButton.SECONDARY) {
                    delete.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            d.getNode().setStyle("");
                        }

                    });

                    cp.setValue(null);
                    cp.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            String hex1 = "#" + Integer.toHexString(cp.getValue().hashCode());

                            d.getNode().setStyle("-fx-background-color: " + hex1 + ";");
                        }
                    });

                    contextMenu.show(d.getNode(), t.getScreenX(), t.getScreenY());
                }
            }

        });
    }

}