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:open.dolphin.client.MainWindowController.java

/**
 * Initializes the controller class./*  ww  w  .  ja  v  a  2s  . c o m*/
 *
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    //- Init TableView
    ReceptView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    PatientSearchView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    PatientFutureView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    LabRecieverView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    //        mainTab.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
    //            @Override
    //            public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) {
    //                SingleSelectionModel<Tab> selectionModel = mainTab.getSelectionModel();
    //                if(mainTab.getTabs() != null){
    //                    if(selectionModel.isSelected(0)){
    //                        karteTabPane.getTabs().clear();
    //                    }
    //                }
    //            }
    //        }); 

    // ?????
    TableColumn colId = new TableColumn("ID");
    recept.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("recept"));
    visitTime.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("visitTime"));
    tableCellAlignRight(visitTime);
    clientId.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("clientId"));
    name.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("name"));
    sex.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("sex"));
    tableCellAlignCenter(sex);
    insurance.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("insurance"));
    birthDay.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("birthDay"));
    physicianInCharge.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("physicianInCharge"));
    clinicalDepartments
            .setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("clinicalDepartments"));
    reservation.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("reservation"));
    memo.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("memo"));
    status.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("status"));
    tableCellImageAlignCenter(status);
    // ????
    ReceptView.getItems().setAll(fetchDataFromServer());

    // ???(?)
    ReceptView.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    System.out.println("Double clicked");
                    ReceptInfo selectedUser = ((TableView<ReceptInfo>) mouseEvent.getSource())
                            .getSelectionModel().getSelectedItem();
                    // ??????????
                    for (ReceptInfo info : receptList) {
                        if (info.getName().equals(selectedUser.getName())) {
                            return;
                        }
                    }
                    System.out.println(selectedUser.getClientId());
                    receptList.add(selectedUser);
                    // ??
                    final ContextMenu contextMenu = new ContextMenu();
                    MenuItem item1 = new MenuItem("?");
                    item1.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Reserve Karte?");
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item2 = new MenuItem("???");
                    item2.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab and Preservation???");
                            karteTabPane.getTabs().remove(karteTabPane.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item3 = new MenuItem("?");
                    item3.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab?");
                            karteTabPane.getTabs().remove(karteTabPane.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    contextMenu.getItems().addAll(item1, item2, item3);

                    Tab tab = new Tab(selectedUser.getName());
                    tab.setOnClosed(new EventHandler<Event>() {
                        @Override
                        public void handle(Event t) {
                            Tab tab = (Tab) t.getSource();
                            for (int i = 0; i < receptList.size(); i++) {
                                if (tab.getText().equals(receptList.get(i).getName())) {
                                    receptList.remove(i);
                                }
                            }
                            System.out.println("Closed!");
                        }
                    });
                    tab.setContextMenu(contextMenu); // Right-click mouse button menu
                    try {
                        // Loading content on demand
                        Parent root = (Parent) new FXMLLoader()
                                .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream());
                        tab.setContent(root);
                        karteTabPane.getSelectionModel().select(tab);
                        karteTabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
                        karteTabPane.getTabs().add(tab);
                        karteTabPane.setPrefSize(kartePane.getPrefWidth(), kartePane.getPrefHeight());
                        kartePane.getChildren().retainAll();
                        kartePane.getChildren().add(karteTabPane);
                    } catch (IOException ex) {
                        Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
        }
    });

    // ????
    clientId1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("clientId1"));
    name1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("name1"));
    kana1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("kana1"));
    sex1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("sex1"));
    birthDay1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("birthDay1"));
    receiveDay1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("receiveDay1"));
    status1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("status1"));
    // dummy?
    PatientSearchView.getItems().setAll(fetchDataFromPatientInfo());

    // ??(?)
    PatientSearchView.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    System.out.println("Double clicked");
                    PatientSearchInfo selectedUser = ((TableView<PatientSearchInfo>) mouseEvent.getSource())
                            .getSelectionModel().getSelectedItem();
                    // ??????????
                    for (PatientSearchInfo info : patientSearchList) {
                        if (info.getName1().equals(selectedUser.getName1())) {
                            return;
                        }
                    }
                    System.out.println(selectedUser.getKana1());
                    patientSearchList.add(selectedUser);
                    // ??
                    final ContextMenu contextMenu = new ContextMenu();
                    MenuItem item1 = new MenuItem("?");
                    item1.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Reserve Karte?");
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item2 = new MenuItem("???");
                    item2.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab and Preservation???");
                            karteTabPane1.getTabs().remove(karteTabPane1.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item3 = new MenuItem("?");
                    item3.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab?");
                            karteTabPane1.getTabs().remove(karteTabPane1.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    contextMenu.getItems().addAll(item1, item2, item3);

                    Tab tab = new Tab(selectedUser.getName1());
                    tab.setOnClosed(new EventHandler<Event>() {
                        @Override
                        public void handle(Event t) {
                            Tab tab = (Tab) t.getSource();
                            for (int i = 0; i < patientSearchList.size(); i++) {
                                if (tab.getText().equals(patientSearchList.get(i).getName1())) {
                                    patientSearchList.remove(i);
                                }
                            }
                            System.out.println("Closed!");
                        }
                    });
                    tab.setContextMenu(contextMenu); // Right-click mouse button menu
                    try {
                        // Loading content on demand
                        Parent root = (Parent) new FXMLLoader()
                                .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream());
                        tab.setContent(root);
                        karteTabPane1.getSelectionModel().select(tab);
                        karteTabPane1.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
                        karteTabPane1.getTabs().add(tab);
                        karteTabPane1.setPrefSize(kartePane1.getPrefWidth(), kartePane1.getPrefHeight());
                        kartePane1.getChildren().retainAll();
                        kartePane1.getChildren().add(karteTabPane1);
                    } catch (IOException ex) {
                        Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    });

    // ????
    clientId2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("clientId2"));
    name2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("name2"));
    kana2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("kana2"));
    insurance2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("insurance2"));
    sex2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("sex2"));
    birthDay2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("birthDay2"));
    physicianInCharge2
            .setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("physicianInCharge2"));
    clinicalDepartments2
            .setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("clinicalDepartments2"));
    karte2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("karte2"));
    // dummy?
    PatientFutureView.getItems().setAll(fetchDataFromPatientFutureInfo());

    // ??(?)
    PatientFutureView.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    System.out.println("Double clicked");
                    PatientFutureInfo selectedUser = ((TableView<PatientFutureInfo>) mouseEvent.getSource())
                            .getSelectionModel().getSelectedItem();
                    System.out.println(selectedUser.getName2());
                    // ??
                    final ContextMenu contextMenu = new ContextMenu();
                    MenuItem item1 = new MenuItem("?");
                    item1.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Reserve Karte?");
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item2 = new MenuItem("???");
                    item2.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab and Preservation???");
                            karteTabPane2.getTabs().remove(karteTabPane2.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item3 = new MenuItem("?");
                    item3.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab?");
                            karteTabPane2.getTabs().remove(karteTabPane2.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    contextMenu.getItems().addAll(item1, item2, item3);

                    Tab tab = new Tab(selectedUser.getName2());
                    tab.setContextMenu(contextMenu); // Right-click mouse button menu
                    try {
                        // Loading content on demand
                        Parent root = (Parent) new FXMLLoader()
                                .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream());
                        tab.setContent(root);
                        karteTabPane2.getSelectionModel().select(tab);
                        karteTabPane2.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
                        karteTabPane2.getTabs().add(tab);
                        karteTabPane2.setPrefSize(kartePane2.getPrefWidth(), kartePane2.getPrefHeight());
                        kartePane2.getChildren().retainAll();
                        kartePane2.getChildren().add(karteTabPane2);
                    } catch (IOException ex) {
                        Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
        }
    });

    // ?????
    lab3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("lab3"));
    clientId3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("clientId3"));
    kana3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("kana3"));
    karteKana3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("karteKana3"));
    sex3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("sex3"));
    karteSex3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("karteSex3"));
    sampleGetDay3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("sampleGetDay3"));
    register3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("register3"));
    status3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("status3"));
    // dummy?
    LabRecieverView.getItems().setAll(fetchDataFromLabRecieverInfo());

    // ???(?)
    LabRecieverView.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    System.out.println("Double clicked");
                    LabReceiverInfo selectedUser = ((TableView<LabReceiverInfo>) mouseEvent.getSource())
                            .getSelectionModel().getSelectedItem();
                    System.out.println(selectedUser.getKana3());
                    // ??
                    final ContextMenu contextMenu = new ContextMenu();
                    MenuItem item1 = new MenuItem("?");
                    item1.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Reserve Karte?");
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item2 = new MenuItem("???");
                    item2.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab and Preservation???");
                            karteTabPane3.getTabs().remove(karteTabPane3.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    MenuItem item3 = new MenuItem("?");
                    item3.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent e) {
                            System.out.println("Close Tab?");
                            karteTabPane3.getTabs().remove(karteTabPane3.getSelectionModel().getSelectedItem());
                            // ??
                            // e.getSource();
                        }
                    });
                    contextMenu.getItems().addAll(item1, item2, item3);

                    Tab tab = new Tab(selectedUser.getKana3());
                    tab.setContextMenu(contextMenu); // Right-click mouse button menu
                    try {
                        // Loading content on demand
                        Parent root = (Parent) new FXMLLoader()
                                .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream());
                        tab.setContent(root);
                        karteTabPane3.getSelectionModel().select(tab);
                        karteTabPane3.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
                        karteTabPane3.getTabs().add(tab);
                        karteTabPane3.setPrefSize(kartePane3.getPrefWidth(), kartePane3.getPrefHeight());
                        kartePane3.getChildren().retainAll();
                        kartePane3.getChildren().add(karteTabPane3);
                    } catch (IOException ex) {
                        Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
        }
    });

    // ??5??????
    Timer exeTimer = new Timer();
    Calendar cal = Calendar.getInstance();
    final int sec = cal.get(Calendar.SECOND);
    int delay = (60 - sec) * 1000;
    int interval = 5 * 1000;
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            if (!stopFlag) {
                System.out.println("this is called every 5 seconds on UI thread");
                receptUpdate();
            } else {
                this.cancel();
            }
        }
    };
    exeTimer.schedule(task, delay, interval);

}

From source file:ui.main.MainViewController.java

private synchronized void paintSentPhoto(Chat chat, File file, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override/*from www .j a  v  a2s . co  m*/
        protected HBox call() throws Exception {
            //                Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(myAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            Label chatterName = new Label(name.getText());
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            try {
                Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(file), null);
                ImageView receivedImageView = new ImageView(recievedImage);
                receivedImageView.setFitHeight(300);
                receivedImageView.setFitWidth(300);
                receivedImageView.setPreserveRatio(true);

                receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Desktop dt = Desktop.getDesktop();
                            try {
                                dt.open(file);
                            } catch (IOException ex) {
                                Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }
                });

                receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.HAND);
                    }
                });

                receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.DEFAULT);
                    }
                });

                vbox.getChildren().addAll(chatterName, receivedImageView, timeL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            vbox.setAlignment(Pos.CENTER_LEFT);
            HBox hbox = new HBox();
            hbox.setAlignment(Pos.CENTER_RIGHT);
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(vbox, imageRec);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedPhotoLoad(Chat chat, File recievedFile, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override/* w  w w  .  j a v a 2  s  .  c o m*/
        protected HBox call() throws Exception {
            Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            try {
                Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null);
                ImageView receivedImageView = new ImageView(recievedImage);
                receivedImageView.setFitHeight(300);
                receivedImageView.setFitWidth(300);
                receivedImageView.setPreserveRatio(true);

                receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Desktop dt = Desktop.getDesktop();
                            try {
                                dt.open(recievedFile);
                            } catch (IOException ex) {
                                Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }
                });

                receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.HAND);
                    }
                });

                receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.DEFAULT);
                    }
                });

                vbox.getChildren().addAll(chatterName, receivedImageView, timeL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedPhotoOnTransmit(Chat chat, File recievedFile, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//from  w  ww .  j a v  a2s  .c o m
        protected HBox call() throws Exception {
            VBox vbox = new VBox(); //to add text
            Thread.sleep(2000);
            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            try {
                Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null);
                ImageView receivedImageView = new ImageView(recievedImage);
                receivedImageView.setFitHeight(300);
                receivedImageView.setFitWidth(300);
                receivedImageView.setPreserveRatio(true);

                receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Desktop dt = Desktop.getDesktop();
                            try {
                                dt.open(recievedFile);
                            } catch (IOException ex) {
                                Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }
                });

                receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.HAND);
                    }
                });

                receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        chatList.getScene().setCursor(Cursor.DEFAULT);
                    }
                });

                vbox.getChildren().addAll(chatterName, receivedImageView, timeL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });
    //set the received chat message appear on the screen
    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
    }
    Task t = new Task() {
        @Override
        protected Object call() throws Exception {
            Thread.sleep(2500);
            return new Object();
        }
    };

    t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

    Thread thread1 = new Thread(t);
    thread1.start();
}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Handle the service selection button event.
 *
 * @param event The mouse click event.//from   w  w w .j  a v a 2 s . co m
 */
@FXML
protected void handleServiceSelectButton(MouseEvent event) {
    if (event.getButton().equals(MouseButton.PRIMARY)) {
        this.downloadConfig = null;
        doSelectService();
    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintSentFile(Chat chat, String path, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//  w  w  w . j  a  v a2s  .  c  o  m
        protected HBox call() throws Exception {
            Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(myAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            Label chatterName = new Label(name.getText());
            chatterName.setDisable(true);

            Hyperlink link = new Hyperlink("File Sent: " + path);
            link.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<javafx.scene.input.MouseEvent>() {
                @Override
                public void handle(javafx.scene.input.MouseEvent event) {
                    try {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Runtime.getRuntime().exec("explorer.exe /select," + path);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
            vbox.getChildren().addAll(chatterName, link, timeL);
            vbox.setAlignment(Pos.CENTER_LEFT);
            HBox hbox = new HBox();
            hbox.setAlignment(Pos.CENTER_RIGHT);
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(vbox, imageRec);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedFile(Chat chat, String path, String time) {
    //this method paints the recieved picture message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override/*from  w  w w .ja  v  a  2s  . c o m*/
        protected HBox call() throws Exception {
            Thread.sleep(100);
            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            Hyperlink link = new Hyperlink("File Recieved: " + path);
            link.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<javafx.scene.input.MouseEvent>() {
                @Override
                public void handle(javafx.scene.input.MouseEvent event) {
                    try {
                        if (event.getButton() == MouseButton.PRIMARY) {
                            Runtime.getRuntime().exec("explorer.exe /select," + path);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
            vbox.getChildren().addAll(chatterName, link, timeL);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());
    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        //t.setDaemon(true);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //set the received chat message appear on the screen
    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        t.start();
    }
    Task t = new Task() {
        @Override
        protected Object call() throws Exception {
            Thread.sleep(2500);
            return new Object();
        }
    };

    t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

    Thread thread1 = new Thread(t);
    thread1.start();

}

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  w w  . j ava  2  s  . c  om*/
        } 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  . j a  v  a2s  . 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;
            }
        }
    }
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur/*from   w  ww. ja  v  a 2 s  . c om*/
 * @param iHauteur
 * @param bMasqueZones
 * @param strIdZone
 * @param mouseEvent
 */
private static void choixZone(int iLargeur, int iHauteur, boolean bMasqueZones, String strIdZone,
        MouseEvent mouseEvent) {
    ComboBox cbTouchesBarre = new ComboBox();
    cbTouchesBarre.getItems().clear();
    for (int i = 0; i < strTouchesBarre.length; i++) {
        cbTouchesBarre.getItems().add(i, strTouchesBarre[i]);
    }
    cbTouchesBarre.setLayoutX(200);
    cbTouchesBarre.setLayoutX(40);

    final int iNumeroZone = Integer.parseInt(strIdZone.split("-")[1]);
    if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
        if (mouseEvent.getClickCount() == 2) {
            for (int ij = iNumeroZone; ij < iNombreZones - 1; ij++) {
                zones[ij] = zones[ij + 1];
            }
            iNombreZones--;
            afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        } else {
            afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
            apZoneBarrePersonnalisee.getChildren().clear();
            apZoneBarrePersonnalisee.getChildren().add(cbTouchesBarre);
            ZoneTelecommande zone = zones[iNumeroZone];
            int index = -1;
            for (int ij = 0; ij < strCodeBarre.length; ij++) {
                if (strCodeBarre[ij].equals(zone.getStrIdZone())) {
                    index = ij;
                }
            }
            if (index != -1) {
                cbTouchesBarre.getSelectionModel().select(index);
            }

            cbTouchesBarre.valueProperty().addListener((ov, ancienneValeur, nouvelleValeur) -> {
                if (nouvelleValeur != null) {
                    String strId = strCodeBarre[cbTouchesBarre.getSelectionModel().getSelectedIndex()];
                    zones[iNumeroZone].setStrIdZone(strId);
                }
            });

            Label lblTypeBarre = new Label(zone.getStrTypeZone());
            lblTypeBarre.setLayoutX(20);
            lblTypeBarre.setLayoutY(40);
            Label lblCoordsBarre = new Label(zone.getStrCoordonneesZone());
            lblCoordsBarre.setLayoutX(20);
            lblCoordsBarre.setLayoutY(70);
            lblCoordsBarre.setPrefWidth(260);
            lblCoordsBarre.setMaxWidth(260);
            lblCoordsBarre.setWrapText(true);
            apZoneBarrePersonnalisee.getChildren().addAll(lblTypeBarre, lblCoordsBarre);
            switch (zone.getStrTypeZone()) {
            case "poly":
                Polygon poly = (Polygon) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                poly.setFill(Color.rgb(255, 0, 0, 0.5));
                poly.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren()
                        .addAll(olCreeAncresPourPolygone(iNumeroZone, poly.getPoints()));
                break;
            case "rect":
                Rectangle rect = (Rectangle) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren().addAll(olCreeAncresPourRectangle(iNumeroZone, rect));
                break;
            case "circle":
                Circle cercle = (Circle) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren().addAll(olCreeAncresPourCercle(iNumeroZone, cercle));
                break;
            }

        }
    }

}