Example usage for javafx.scene.control MenuItem setId

List of usage examples for javafx.scene.control MenuItem setId

Introduction

In this page you can find the example usage for javafx.scene.control MenuItem setId.

Prototype

public final void setId(String value) 

Source Link

Usage

From source file:calendarioSeries.vistas.MainViewController.java

public void populateImagenes() {
    Platform.runLater(new Runnable() {
        @Override/* w  w w .j  a  va  2 s.co  m*/
        public void run() {
            imagenes.getChildren().clear();
            for (Serie serie : series) {
                //System.out.println(serie.getLastVisto());
                try {
                    Image image = new Image(serie.getUrlImagen());
                    ImageView poster = new ImageView();
                    ContextMenu menu = new ContextMenu();
                    //String css = MainApp.class.getResource("resources/MainTheme.css").toExternalForm();
                    MenuItem delete = new MenuItem("Eliminar");
                    delete.setId(serie.getId());
                    delete.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent event) {
                            menu.hide();
                            MenuItem clicked = (MenuItem) event.getSource();
                            String toDelete = clicked.getId();
                            for (Serie serie : series) {
                                if (serie.getId().equals(toDelete)) {
                                    series.remove(serie);
                                    populateImagenes();
                                    showDetallesMes(mesActual);
                                }
                            }
                            event.consume();
                        }
                    });

                    menu.getItems().add(delete);

                    poster.setId(serie.getTitulo());
                    poster.setImage(image);
                    poster.setCache(true);
                    // poster.setPreserveRatio(true);
                    poster.setFitWidth(210);
                    poster.setFitHeight(300);
                    poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                        @Override
                        public void handle(ContextMenuEvent event) {
                            menu.show(poster, event.getScreenX(), event.getScreenY());
                            //menu.getScene().getRoot().getStylesheets().add(css);
                            event.consume();
                        }
                    });
                    poster.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                            if (event.getButton() == MouseButton.PRIMARY) {
                                try {
                                    //serieToPass = serie;
                                    sceneToPass = mainApp.scene;

                                    FXMLLoader loader = new FXMLLoader(
                                            getClass().getResource("DetailsSerieController.fxml"));
                                    Parent root = loader.load();
                                    DetailsSerieController controller = loader.getController();
                                    controller.setData(serie, series);
                                    controller.setMainApp(mainApp);

                                    Scene scene = new Scene(root);
                                    mainApp.primaryStage.setScene(scene);
                                    mainApp.primaryStage.show();
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        }

                    });
                    imagenes.getChildren().add(poster);
                } catch (IllegalArgumentException e) {
                    Image image = new Image("file:src/calendarioSeries/resources/no-image.png");
                    ImageView poster = new ImageView();
                    ContextMenu menu = new ContextMenu();
                    MenuItem delete = new MenuItem("Eliminar");
                    delete.setId(serie.getId());
                    delete.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent event) {
                            menu.hide();
                            MenuItem clicked = (MenuItem) event.getSource();
                            String toDelete = clicked.getId();
                            for (Serie serie : series) {
                                if (serie.getId().equals(toDelete)) {
                                    series.remove(serie);
                                    populateImagenes();
                                    showDetallesMes(mesActual);
                                }
                            }
                            event.consume();
                        }
                    });

                    menu.getItems().add(delete);

                    poster.setId(serie.getTitulo());
                    poster.setImage(image);
                    poster.setCache(true);
                    //poster.setPreserveRatio(true);
                    poster.setFitWidth(210);
                    poster.setFitHeight(300);
                    poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                        @Override
                        public void handle(ContextMenuEvent event) {
                            menu.show(poster, event.getScreenX(), event.getScreenY());
                            event.consume();
                        }
                    });
                    Text text = new Text(serie.getTitulo());
                    text.getStyleClass().add("label");
                    StackPane pane = new StackPane();
                    pane.getChildren().addAll(poster, text);

                    imagenes.getChildren().add(pane);
                } finally {
                    rellenarArchivo();
                }
            }
        }
    });

}