List of usage examples for javafx.scene.control MenuItem setOnAction
public final void setOnAction(EventHandler<ActionEvent> value)
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java
/** * Creates the context menu./*from ww w . j a v a 2 s . com*/ * * @return The context menu. */ private ContextMenu createContextMenu() { final ContextMenu menu = new ContextMenu(); Menu export = new Menu("Export As"); MenuItem pngItem = new MenuItem("PNG ..."); pngItem.setOnAction((ActionEvent e) -> { handleExportToPNG(); }); export.getItems().add(pngItem); MenuItem jpegItem = new MenuItem("JPEG ..."); jpegItem.setOnAction((ActionEvent e) -> { handleExportToJPEG(); }); export.getItems().add(jpegItem); MenuItem tikzItem = new MenuItem("Tikz ..."); tikzItem.setOnAction((ActionEvent e) -> { handleExportToTikz(); }); export.getItems().add(tikzItem); MenuItem wsvItem = new MenuItem("Text ..."); wsvItem.setOnAction((ActionEvent e) -> { handleExportToWSV(); }); export.getItems().add(wsvItem); if (ExportUtils.isOrsonPDFAvailable()) { 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:de.pixida.logtest.designer.automaton.AutomatonNode.java
@Override ContextMenu createContextMenu() {//from www . j a v a2s .c om 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:de.pixida.logtest.designer.MainWindow.java
private void createAndAppendFileMenuItems(final Menu menu) { final Menu newDocument = new Menu("New"); final Menu open = new Menu("Open"); for (final Type type : Editor.Type.values()) { final MenuItem newFile = new MenuItem(type.getName()); newFile.setOnAction(event -> this.handleCreateNewDocument(type)); newDocument.getItems().add(newFile); if (type.supportsFilesProperty().get()) { final MenuItem openFile = new MenuItem(type.getName()); openFile.setOnAction(event -> { final FileChooser fileChooser = this.createFileDialog(type, "Open"); final File selectedFile = fileChooser.showOpenDialog(this.primaryStage); if (selectedFile != null) { this.applyFolderOfSelectedFileInOpenOrSaveAsFileDialog(selectedFile); this.handleLoadDocument(type, selectedFile); }/*from w w w. j a v a 2 s . c o m*/ }); open.getItems().add(openFile); } } this.menuItemSave = new MenuItem("Save"); this.menuItemSave.setGraphic(Icons.getIconGraphics("disk")); this.menuItemSave.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); this.menuItemSave.setOnAction(event -> this.handleSaveDocument()); this.menuItemSaveAs = new MenuItem("Save as"); this.menuItemSaveAs.setOnAction(event -> this.handleSaveDocumentAs()); final MenuItem exit = new MenuItem("Exit"); exit.setOnAction(event -> this.handleExitApplication()); menu.getItems().addAll(newDocument, open, this.menuItemSave, this.menuItemSaveAs, new SeparatorMenuItem(), exit); }
From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java
protected void onColumnsChanged(ListChangeListener.Change<? extends SimpleStringProperty> c) { while (c.next()) { List<? extends SimpleStringProperty> added = c.getAddedSubList(); List<? extends SimpleStringProperty> removed = c.getRemoved(); for (SimpleStringProperty column : added) { int columnIndex = columnHeaders.indexOf(column); addColumnConstraint();//from w w w .ja v a 2s.com TextField title = new TextField(); title.textProperty().bindBidirectional(column); title.getStyleClass().add("editorViewLabel"); MenuItem deleteColumnItem = new MenuItem(Localized.get("column.delete")); deleteColumnItem.setOnAction(e -> { columnHeaders.remove(column); }); title.setContextMenu(new ContextMenu(deleteColumnItem)); headers.add(title); dataContainer.add(title, columnIndex + COLUMN_OFFSET, 0); for (int i = 0; i < rows.size(); i++) { ChartRow chartRow = rows.get(i); SimpleStringProperty value = chartRow.getValue(columnIndex); TextField editor = createValueEditor(chartRow, i, columnIndex); editor.textProperty().bindBidirectional(value); } } for (SimpleStringProperty column : removed) { Optional<Integer> first = dataContainer.getChildren().stream() .filter(n -> GridPane.getRowIndex(n) == 0).map(n -> (TextField) n) .filter(t -> t.getText().equals(column.getValue())).map(t -> GridPane.getColumnIndex(t)) .findFirst(); if (first.isPresent()) { int columnIndex = first.get(); rows.forEach(r -> { SimpleStringProperty value = r.getValue(columnIndex); value.set(""); value.unbind(); }); List<Node> childrenToRemove = dataContainer.getChildren().stream() .filter(n -> GridPane.getColumnIndex(n) == columnIndex).collect(Collectors.toList()); dataContainer.getChildren().removeAll(childrenToRemove); dataContainer.getColumnConstraints().remove(dataContainer.getColumnConstraints().size() - 1); } } sortGridPane(); } }
From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java
private void updateRecentFilesMenu() { List<MenuItem> items = new ArrayList<>(); List<File> filesToClear = new ArrayList<>(); for (final File f : recentFiles) { if (f.exists() && f.isFile()) { CustomMenuItem item = new CustomMenuItem(new Label(f.getName())); item.setOnAction(e -> loadSourceFromFile(f)); item.setMnemonicParsing(false); Tooltip.install(item.getContent(), new Tooltip(f.getAbsolutePath())); items.add(item);/*from w w w .ja va 2 s . c o m*/ } else { filesToClear.add(f); } } recentFiles.removeAll(filesToClear); if (items.isEmpty()) { openRecentMenu.setDisable(true); return; } Collections.reverse(items); items.add(new SeparatorMenuItem()); MenuItem clearItem = new MenuItem(); clearItem.setText("Clear menu"); clearItem.setOnAction(e -> { recentFiles.clear(); openRecentMenu.setDisable(true); }); items.add(clearItem); openRecentMenu.getItems().setAll(items); }
From source file:ipat_fx.FXMLDocumentController.java
@Override public void initialize(URL url, ResourceBundle rb) { contextPath = System.getProperty("user.dir") + "/web/"; dataPath = contextPath + "/Client Data"; File index = new File(dataPath); if (!index.exists()) { index.mkdir();/*from ww w . j av a 2 s . c om*/ } else { index.delete(); if (!index.exists()) { index.mkdir(); } } File prePopulatedProfilePath = new File(contextPath + "/data/"); File[] listFiles = prePopulatedProfilePath.listFiles(); for (File listFile : listFiles) { if (listFile.isDirectory()) { caseFileArray.add(listFile); } } caseItemArray = new MenuItem[caseFileArray.size()]; for (int i = 0; i < caseFileArray.size(); i++) { File get = caseFileArray.get(i); MenuItem menuItem = new MenuItem(get.getName()); cases.getItems().add(menuItem); caseItemArray[i] = menuItem; } problemDataFolderName = "/" + caseItemArray[0].getText(); profilePath = new File(contextPath + "/data" + problemDataFolderName + "/Profiles/"); hintsXML = new File(contextPath + "/data" + problemDataFolderName + "/hints.xml"); inputFolder = new File(dataPath + "/input/"); outputFolder = new File(dataPath + "/output/"); for (MenuItem caseItem : caseItemArray) { caseItem.setOnAction(e -> { MenuItem mItem = (MenuItem) e.getSource(); problemDataFolderName = "/" + mItem.getText(); profilePath = new File(contextPath + "/data" + problemDataFolderName + "/Profiles/"); hintsXML = new File(contextPath + "/data" + problemDataFolderName + "/hints.xml"); inputFolder = new File(dataPath + "/input/"); outputFolder = new File(dataPath + "/output/"); }); } tabFlag = "byProfile"; }
From source file:be.makercafe.apps.makerbench.Main.java
/** * Creates the menubar//from w ww. j av a2 s .com * * @return */ private MenuBar createMenuBar() { MenuBar bar = new MenuBar(); Menu projectMenu = new Menu("Project"); MenuItem openProject = new MenuItem("Open..."); openProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { directoryChooser.setTitle("Please choose a project folder"); File file = directoryChooser.showDialog(stage); viewer.setRoot(setRootFolder(file)); } }); Menu newProject = new Menu("New"); MenuItem newFolder = new MenuItem("Folder..."); newFolder.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TextInputDialog dialog = new TextInputDialog("my_project_folder"); dialog.setTitle("New folder"); dialog.setHeaderText("Create a new folder"); dialog.setContentText("Folder name:"); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { String homeDir = System.getProperty("user.home"); System.out.println("Folder name: " + result.get()); System.out.println("User home: " + homeDir); } } }); newProject.getItems().add(newFolder); MenuItem importProject = new MenuItem("Import"); importProject.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.CONTROL_DOWN)); importProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Import"); } }); MenuItem deleteProject = new MenuItem("Delete"); deleteProject.setAccelerator(new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN)); deleteProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Delete"); } }); projectMenu.getItems().addAll(openProject, newProject, importProject, deleteProject); Menu helpMenu = new Menu("Help"); MenuItem aboutItem = new MenuItem("About"); aboutItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Information Dialog"); alert.setHeaderText("About makerbench"); alert.setContentText( "Makerbench is an open source IDE for designing and manufacturing objects and code.\nWritten by Luc De pauw\n\nUses opensource libraries from the next projects:\n-RichtextFX by Tomas Mikula\n-JCSG by Michael Hoffer\n-ControlsFX by FXexperience.com"); alert.showAndWait(); } }); helpMenu.getItems().add(aboutItem); bar.getMenus().addAll(projectMenu, helpMenu); return bar; }
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 . java 2 s . co 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:jviewmda.JViewMda.java
@Override public void start(Stage primaryStage) { m_stage = primaryStage;/*from w ww . j a v a2 s . co m*/ String array_path = ""; Parameters params = getParameters(); List<String> unnamed_params = params.getUnnamed(); if (unnamed_params.size() > 0) { array_path = unnamed_params.get(0); } // FOR DEBUGING PURPOSES if (array_path.length() == 0) { //String debug_path = "/home/magland/wisdm/www/wisdmfileserver/files/fetalmri/sessions/SESSION1/crops/FNP001A-coronal.crop.mda"; String debug_path = "/home/magland/data/LesionProbe/Images/ID001_FLAIR.nii"; if ((new File(debug_path)).exists()) { array_path = debug_path; } } Menu menu; MenuItem item; MenuBar menubar = new MenuBar(); //file menu menu = new Menu("File"); menubar.getMenus().add(menu); item = new MenuItem("Open..."); item.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_open()); menu.getItems().add(item); item = new MenuItem("Save As..."); item.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_saveas()); menu.getItems().add(item); menu.getItems().add(new SeparatorMenuItem()); ///////////////////////////////////////////// item = new MenuItem("Exit"); item.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_exit()); menu.getItems().add(item); //view menu menu = new Menu("View"); menubar.getMenus().add(menu); item = new MenuItem("Zoom In"); item.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_zoom_in()); menu.getItems().add(item); item = new MenuItem("Zoom Out"); item.setAccelerator( new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)); item.setOnAction(e -> on_zoom_out()); menu.getItems().add(item); menu.getItems().add(new SeparatorMenuItem()); ///////////////////////////////////////////// { CheckMenuItem item0 = new CheckMenuItem("Top Controls"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setTopControlsVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Bottom Controls"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setBottomControlsVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Brightness/Contrast"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setBrightnessContrastVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Slice Slider"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setSliceSliderVisible(item0.isSelected()); }); menu.getItems().add(item0); } //selection menu menu = new Menu("Selection"); menubar.getMenus().add(menu); Map<String, CheckMenuItem> mode_items = new HashMap<>(); m_selection_mode_items = mode_items; mode_items.put("rectangle", new CheckMenuItem("Rectangle")); mode_items.put("ellipse", new CheckMenuItem("Ellipse")); Set<String> keys = mode_items.keySet(); for (String key : keys) { CheckMenuItem item0 = mode_items.get(key); menu.getItems().add(item0); item0.setOnAction(evt -> { on_selection_mode_changed(key); }); } mode_items.get("rectangle").setSelected(true); VBox root = new VBox(); root.getChildren().addAll(menubar, m_widget); Scene scene = new Scene(root, 500, 450); primaryStage.setTitle("JViewMda"); primaryStage.setScene(scene); primaryStage.show(); if (array_path.length() > 0) { open_file(array_path); } m_prefs = Preferences.userNodeForPackage(this.getClass()); }
From source file:com.properned.application.SystemController.java
public void populateRecentFileMenu() { logger.info("Loading recent files"); recentFileMenu.getItems().clear();//from w w w . j a va 2s. co m List<RecentFile> recentFileList = Preferences.getInstance().getRecentFileList(); for (final RecentFile recentFile : recentFileList) { if (recentFile.getFile().exists()) { MenuItem menuItemRecentFile = new MenuItem(recentFile.getFile().getAbsolutePath()); menuItemRecentFile.setMnemonicParsing(false); menuItemRecentFile.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { loadFileList(recentFile.getFile()); } }); recentFileMenu.getItems().add(menuItemRecentFile); } } }