Example usage for javafx.scene.control MenuItem MenuItem

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

Introduction

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

Prototype

public MenuItem(String text) 

Source Link

Document

Constructs a MenuItem and sets the display text with the specified text

Usage

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    file = new File("");
    csvFormat = CSVFormat.DEFAULT.withIgnoreEmptyLines(false);

    ContextMenu contextMenu = new ContextMenu();
    contextMenu.setAutoHide(true);/* ww  w . ja v a  2  s  . c  o m*/
    MenuItem inserirLinha = new MenuItem("Inserir linha");
    inserirLinha.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            addNewRow();
            setNotSaved();
        }
    });

    contextMenu.getItems().add(inserirLinha);
    MenuItem removerLinha = new MenuItem("Remover linha");
    removerLinha.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            deleteRow();
            setNotSaved();
        }
    });
    contextMenu.getItems().add(removerLinha);

    contextMenu.getItems().add(new SeparatorMenuItem());

    MenuItem inserirColuna = new MenuItem("Inserir coluna");
    inserirColuna.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            addNewColumn();
            setNotSaved();
        }
    });
    contextMenu.getItems().add(inserirColuna);

    MenuItem removerColuna = new MenuItem("Remover coluna");
    removerColuna.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            deleteColumn();
            setNotSaved();
        }
    });
    contextMenu.getItems().add(removerColuna);

    tableView.setContextMenu(contextMenu);
}

From source file:View.Visualize.java

public void getPieChartData(Integer nameColumn, Integer valueColumn, Table table, PieChart pieChart, Label lbl,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();//  www.  jav a2 s  .co m

    if (!newSeries) {
        pieChart.getData().clear();
    }

    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new PieChart.Data(entry.getKey(), entry.getValue()))
            .forEach(pieChart.getData()::add);

    for (PieChart.Data d : pieChart.getData()) {
        //deretter legger vi animasjon p piecharten.. 
        d.getNode().setOnMouseClicked(new mouseHooverAnimationPieChart.MouseHoverAnimation(d, pieChart));
        final Node n = d.getNode();
        Tooltip tooltip = new Tooltip();
        String toolTipText = "Value : " + d.getPieValue();
        tooltip.setText(toolTipText);
        Tooltip.install(n, tooltip);
        n.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(glow);
            }
        });
        n.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(null);
            }
        });
        final ContextMenu contextMenu = new ContextMenu();
        MenuItem changeColor = new MenuItem("Change Color");
        MenuItem delete = new MenuItem("Standard color");
        ColorPicker cp = new ColorPicker();
        changeColor.setGraphic(cp);
        contextMenu.getItems().addAll(changeColor, delete);

        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());
                }
            }

        });

    }

}

From source file:org.beryx.viewreka.fxapp.codearea.ViewrekaCodeArea.java

protected void showContextMenu(ContextMenu cm) {
    if (codeTemplates.isEmpty())
        return;//from   w w  w. j  ava  2 s.com

    cm.getItems().clear();
    for (CodeTemplate template : codeTemplates) {
        // TODO retrieve context and create MenuItem only if template.isAllowedInContext() returns true
        MenuItem item = new MenuItem(template.getName());
        item.setOnAction(ev -> {
            if (classLoaderManager != null) {
                classLoaderManager.setProjectClassLoader();
            }
            try {
                insertCodeFragment(template);
            } finally {
                classLoaderManager.resetClassLoader();
            }
        });
        cm.getItems().add(item);
    }
    cm.getItems()
            .sort((item1, item2) -> item1.getText().toLowerCase().compareTo(item2.getText().toLowerCase()));
    cm.show(getScene().getWindow());
}

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

@Override
ContextMenu createContextMenu() {/* w w w. j a v a2s. c  o m*/
    final ContextMenu cm = new ContextMenu();

    MenuItem mi = new MenuItem("Create edge from here");
    mi.setGraphic(Icons.getIconGraphics("bullet_go"));
    mi.setOnAction(event -> {
        final AutomatonEdgeBuilder newEdge = new AutomatonEdgeBuilder(this.getGraph());
        this.getGraph().startDrawingConnector(this, newEdge);
    });
    cm.getItems().add(mi);

    mi = new MenuItem("Delete state");
    mi.setGraphic(Icons.getIconGraphics("delete"));
    mi.setStyle("-fx-text-fill:#FF3030");
    mi.setOnAction(event -> {
        final Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Confirm");
        alert.setHeaderText("You are about to delete the state.");
        alert.setContentText("Do you want to continue?");
        alert.showAndWait().filter(response -> response == ButtonType.OK)
                .ifPresent(response -> this.removeNodeAndEdges());
    });
    cm.getItems().add(mi);

    return cm;
}

From source file:com.heliosdecompiler.helios.gui.view.editors.DisassemblerView.java

@Override
protected Node createView0(OpenedFile file, String path) {
    CodeArea codeArea = new CodeArea();

    if (controller instanceof KrakatauDisassemblerController) {
        ContextMenu contextMenu = new ContextMenu();

        MenuItem save = new MenuItem("Assemble");
        save.setOnAction(e -> {/*w  w w .j  a  v  a 2s  . c o  m*/
            save(codeArea).whenComplete((res, err) -> {
                if (err != null) {
                    if (err instanceof KrakatauException) {
                        StringBuilder message = new StringBuilder();
                        message.append("stdout:\r\n").append(((KrakatauException) err).getStdout())
                                .append("\r\n\r\nstderr:\r\n").append(((KrakatauException) err).getStderr());

                        messageHandler.handleLongMessage(Message.ERROR_FAILED_TO_ASSEMBLE_KRAKATAU,
                                message.toString());
                    } else {
                        messageHandler.handleException(Message.ERROR_UNKNOWN_ERROR.format(), err);
                    }
                } else {
                    file.putContent(path, res);
                    messageHandler.handleMessage(Message.GENERIC_ASSEMBLED.format());
                }
            });
        });

        contextMenu.getItems().add(save);
        codeArea.setContextMenu(contextMenu);
    }

    codeArea.setStyle("-fx-font-size: 1em");
    codeArea.getProperties().put("fontSize", 1);

    codeArea.setParagraphGraphicFactory(line -> {
        Node label = LineNumberFactory.get(codeArea, (digits) -> "%1$" + digits + "d").apply(line);
        label.styleProperty().bind(codeArea.styleProperty());
        return label;
    });
    codeArea.replaceText("Disassembling... this may take a while");
    codeArea.getUndoManager().forgetHistory();

    codeArea.richChanges().filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
            .successionEnds(Duration.ofMillis(500)).supplyTask(() -> computeHighlightingAsync(codeArea))
            .awaitLatest(codeArea.richChanges()).filterMap(t -> {
                if (t.isSuccess()) {
                    return Optional.of(t.get());
                } else {
                    t.getFailure().printStackTrace();
                    return Optional.empty();
                }
            }).subscribe(f -> applyHighlighting(codeArea, f));
    codeArea.getStylesheets().add(getClass().getResource("/java-keywords.css").toExternalForm());

    codeArea.addEventFilter(ScrollEvent.SCROLL, e -> {
        if (e.isShortcutDown()) {
            if (e.getDeltaY() > 0) {
                int size = (int) codeArea.getProperties().get("fontSize") + 1;
                codeArea.setStyle("-fx-font-size: " + size + "em");
                codeArea.getProperties().put("fontSize", size);
            } else {
                int size = (int) codeArea.getProperties().get("fontSize") - 1;
                if (size > 0) {
                    codeArea.setStyle("-fx-font-size: " + size + "em");
                    codeArea.getProperties().put("fontSize", size);
                }
            }
            e.consume();
        }
    });

    controller.disassemble(file, path, (success, text) -> {
        Platform.runLater(() -> {
            codeArea.replaceText(text);
            codeArea.getUndoManager().forgetHistory();
        });
    });

    return new VirtualizedScrollPane<>(codeArea);
}

From source file:Watcher.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    ServiceHandler.start(new notificationService());

    try {/*from   w w w.  j  ava  2  s.com*/
        HSQL_Manager.init("jdbc:hsqldb:file:src/dbEnv/", "SA", "");
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
    }

    int count = 0;
    for (Site a : HSQL_Manager.getSites()) {
        items.add(a.getAddress());

        try {
            //sites.add(new Site(siteList.getItems().get(i).toString()));
            watcherManager.addSite(a);
        } catch (WatchDogNotStartedException | SiteAlreadyAddedException ex) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            new errDialog().showError(sw.toString());
            break;
        }
        count++;
    }

    MenuItem deleteItem = new MenuItem("Delete");
    final ContextMenu contextMenu = new ContextMenu(deleteItem);
    contextMenu.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            removeItem(new Site(siteList.getSelectionModel().getSelectedItem().toString()));
        }
    });
    siteList.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {

        @Override
        public ListCell<String> call(ListView<String> param) {
            ListCell<String> cell = new ListCell<String>() {

                @Override
                protected void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    //textProperty().unbind();
                    setContextMenu(null);
                    if (!empty && item != null) {
                        setContextMenu(contextMenu);
                        setText(item);
                    }
                    if (item != null) {
                    } else {
                        setGraphic(null);
                        setText("");
                    }
                }
            };
            return cell;
        }
    });

    siteList.getSelectionModel().selectedItemProperty().addListener(new listViewChangeListener());
    siteList.setItems(items);
    siteList.autosize();

    if (count > 0) {
        siteList.getSelectionModel().select(0);
    }
    uptime.setAnimated(false);
    //uptime.setStyle(null);
    processor = new processData(uptime, detailedData);

    try {
        ServiceHandler.startService(new InternetWatcher("http://www.google.com", 3));
        ServiceHandler.startService(
                new StatusUpdater(1, (FXMLDocumentController) JavaFXApplication4.getLoader().getController()));
    } catch (InternetWatcherServiceAlreadyStartedException | WatchDogTimerServiceAlreadyStartedException
            | StatusUpdaterServiceAlreadyStartedException ex) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        ex.printStackTrace(pw);
        new errDialog().showError(sw.toString());
    }

    removeFilter.setOnMousePressed(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if (t.isPrimaryButtonDown()) {
                processor.cancelFilter(getSelectedItem());
            }
        }
    });
}

From source file:calendarioSeries.vistas.MainViewController.java

public void populateImagenes() {
    Platform.runLater(new Runnable() {
        @Override/*from  w ww  .j  av  a  2  s.  c  o  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();
                }
            }
        }
    });

}

From source file:net.sf.mzmine.chartbasics.gui.javafx.EChartViewer.java

protected void addMenuItem(Menu parent, String title, EventHandler<ActionEvent> al) {
    MenuItem pngItem = new MenuItem(title);
    pngItem.setOnAction(al);// w  ww  .  j av  a  2s  .c  o  m
    parent.getItems().add(pngItem);
}

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

private ContextMenu createContextMenu() {

    menu = new ContextMenu();

    Menu export = new Menu("Export As");

    MenuItem pngItem = new MenuItem("PNG...");
    pngItem.setOnAction((ActionEvent e) -> {
        handleExportToPNG();// w ww  .  java2  s  . c o m
    });
    export.getItems().add(pngItem);

    MenuItem jpegItem = new MenuItem("JPEG...");
    jpegItem.setOnAction((ActionEvent e) -> {
        handleExportToJPEG();
    });
    export.getItems().add(jpegItem);

    MenuItem pdfItem = new MenuItem("PDF...");
    pdfItem.setOnAction((ActionEvent e) -> {
        handleExportToPDF();
    });
    export.getItems().add(pdfItem);

    if (ExportUtils.isJFreeSVGAvailable()) {
        MenuItem svgItem = new MenuItem("SVG...");
        svgItem.setOnAction((ActionEvent e) -> {
            handleExportToSVG();
        });
        export.getItems().add(svgItem);
    }
    menu.getItems().add(export);
    return menu;
}

From source file:net.sf.mzmine.chartbasics.gui.javafx.EChartViewer.java

protected void addMenuItem(ContextMenu parent, String title, EventHandler<ActionEvent> al) {
    MenuItem pngItem = new MenuItem(title);
    pngItem.setOnAction(al);/*  w w w. j  a v a2s .  com*/
    parent.getItems().add(pngItem);
}