List of usage examples for javafx.scene.control MenuItem MenuItem
public MenuItem(String text)
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); final ContextMenu contextMenu = new ContextMenu(); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); }//from w w w . j a v a 2s .co m }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); } }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); contextMenu.getItems().addAll(item1, item2); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); final ContextMenu contextMenu = new ContextMenu(); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); }// w w w . j a v a 2 s . c o m }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); } }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); contextMenu.getItems().addAll(item1, item2); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:com.bekwam.resignator.ResignatorAppMainViewControllerTest.java
@Before public void init() { resignatorAppMainViewController = new ResignatorAppMainViewController(); Menu mRecentProfiles = new Menu(); List<MenuItem> rpItems = new ArrayList<>(); rpItems.add(new MenuItem(noneMenuItemText)); mRecentProfiles.getItems().clear();/*from w w w . java 2 s . com*/ mRecentProfiles.getItems().addAll(rpItems); ActiveConfiguration activeConfiguration = new ActiveConfiguration(); resignatorAppMainViewController.mRecentProfiles = mRecentProfiles; resignatorAppMainViewController.activeConfiguration = activeConfiguration; }
From source file:ubicrypt.ui.tree.FolderItem.java
public FolderItem(final Path path, final EventHandler<ActionEvent> onAddHandler) { checkArgument(path != null, "path must not be null"); this.path = path; label = null;/*from w ww. j a v a2s .c o m*/ final MenuItem add = new MenuItem("Add File"); add.setOnAction(onAddHandler); menu.getItems().add(add); }
From source file:ubicrypt.ui.files.FolderItem.java
public FolderItem(final Path path, final EventHandler<ActionEvent> onAddHandler, final EventHandler<ActionEvent> onAddFolder) { checkArgument(path != null, "path must not be null"); this.path = path; label = null;/*ww w. j a va 2s . com*/ final MenuItem add = new MenuItem("Add Files"); add.setOnAction(onAddHandler); final MenuItem addFolder = new MenuItem("Add Folder"); addFolder.setOnAction(onAddFolder); menu.getItems().addAll(add, addFolder); }
From source file:de.pixida.logtest.designer.automaton.Graph.java
Graph(final IAutomatonEditor aAutomatonEditor) { Validate.notNull(aAutomatonEditor);//from w w w. j a va2s. com this.automatonEditor = aAutomatonEditor; this.pane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY))); final double minSizeX = 800.0; final double minSizeY = 600.0; this.pane.setMinSize(minSizeX, minSizeY); final double paddingRightBottom = 8.0; this.pane.setPadding(new Insets(0.0, paddingRightBottom, paddingRightBottom, 0.0)); this.pane.setOnMouseMoved(event -> this.mouseMovedOnPane(event)); this.pane.setOnMouseClicked(event -> this.mouseClickedOnPane(event)); final MenuItem mi = new MenuItem("Create new state"); mi.setGraphic(Icons.getIconGraphics("pencil_add")); mi.setOnAction(event -> { // The following code does not really belong here as the class is designed only to handle business belongings... it should be // moved somewhere else!? final AutomatonNode newNode = new AutomatonNode(Graph.this); newNode.setPosition(new Point2D(this.lastMousePositionOnPaneX, this.lastMousePositionOnPaneY)); newNode.setName("New state"); Graph.this.addObject(newNode); Graph.this.handleChange(); Graph.this.showConfigFrameOfObject(newNode); }); this.contextMenu.getItems().add(mi); }
From source file:account.management.controller.ViewSalaryVoucherController.java
/** * Initializes the controller class.//from www . j a v a 2 s . co m */ @Override public void initialize(URL url, ResourceBundle rb) { this.voucher_no.setCellValueFactory(new PropertyValueFactory("id")); this.date.setCellValueFactory(new PropertyValueFactory("date")); this.section.setCellValueFactory(new PropertyValueFactory("section")); this.name.setCellValueFactory(new PropertyValueFactory("name")); this.basis.setCellValueFactory(new PropertyValueFactory("basis")); this.amount.setCellValueFactory(new PropertyValueFactory("total")); final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem(" View "); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Data.salaryVoucher = table.getSelectionModel().getSelectedItem(); try { Parent root = FXMLLoader .load(getClass().getResource(MetaData.viewPath + "EditSalaryVoucher.fxml")); Scene scene = new Scene(root); Stage stage = new Stage(); scene.setRoot(root); stage.setResizable(false); stage.setTitle("Salary Voucher"); stage.setScene(scene); stage.showAndWait(); int index = table.getSelectionModel().getSelectedIndex(); getData(); } catch (IOException ex) { Logger.getLogger(ViewSalaryVoucherController.class.getName()).log(Level.SEVERE, null, ex); } } }); contextMenu.getItems().addAll(item1); this.table.setContextMenu(contextMenu); }
From source file:jviewmda.JViewMda.java
@Override public void start(Stage primaryStage) { m_stage = primaryStage;// ww w . j a va 2s .c om 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.LocaleListCell.java
private MenuItem getDeleteMenu(Locale locale) { MenuItem deleteMenu = new MenuItem(MessageReader.getInstance().getMessage("action.deleteMessageKey")); deleteMenu.setOnAction(new EventHandler<ActionEvent>() { @Override/*from ww w. ja va 2s .c o m*/ public void handle(ActionEvent event) { logger.info("Clic on delete button for locale '" + locale.toString() + "'"); String fileName = properties.getMapPropertiesFileByLocale().get(locale).getAbsolutePath(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.title")); alert.setHeaderText(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.header")); alert.setContentText( MessageReader.getInstance().getMessage("manageLocale.confirmDelete.content", fileName)); Optional<ButtonType> result = alert.showAndWait(); if (result.isPresent() && result.get() == ButtonType.OK) { logger.info("User say OK to the confirm"); properties.deleteLocale(locale); // Reload list controller.initializeList(); } } }); if (properties.getMapPropertiesByLocale().keySet().size() <= 1) { // We can delete only if there is more than the current locale deleteMenu.setDisable(true); } return deleteMenu; }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
@FXML public void initialize() { this.rootItem = new TreeItem<>(new TreeNode("[root]")); this.root.setRoot(this.rootItem); this.root.setCellFactory(new TreeCellFactory<>(node -> { if (node.getParent() == null) { ContextMenu export = new ContextMenu(); MenuItem exportItem = new MenuItem("Export"); export.setOnAction(e -> { File file = messageHandler.chooseFile().withInitialDirectory(new File(".")) .withTitle(Message.GENERIC_CHOOSE_EXPORT_LOCATION_JAR.format()) .withExtensionFilter(new FileFilter(Message.FILETYPE_JAVA_ARCHIVE.format(), "*.jar"), true)/* w w w . ja va 2s. c o m*/ .promptSave(); OpenedFile openedFile = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE); Map<String, byte[]> clone = new HashMap<>(openedFile.getContents()); backgroundTaskHelper.submit( new BackgroundTask(Message.TASK_SAVING_FILE.format(node.getDisplayName()), true, () -> { try { if (!file.exists()) { if (!file.createNewFile()) { throw new IOException("Could not create export file"); } } try (ZipOutputStream zipOutputStream = new ZipOutputStream( new FileOutputStream(file))) { for (Map.Entry<String, byte[]> ent : clone.entrySet()) { ZipEntry zipEntry = new ZipEntry(ent.getKey()); zipOutputStream.putNextEntry(zipEntry); zipOutputStream.write(ent.getValue()); zipOutputStream.closeEntry(); } } messageHandler.handleMessage(Message.GENERIC_EXPORTED.format()); } catch (IOException ex) { messageHandler.handleException(Message.ERROR_IOEXCEPTION_OCCURRED.format(), ex); } })); }); export.getItems().add(exportItem); return export; } return null; })); root.addEventHandler(KeyEvent.KEY_RELEASED, event -> { if (event.getCode() == KeyCode.ENTER) { TreeItem<TreeNode> selected = this.root.getSelectionModel().getSelectedItem(); if (selected != null) { if (selected.getChildren().size() != 0) { selected.setExpanded(!selected.isExpanded()); } else { getParentController().getAllFilesViewerController().handleClick(selected.getValue()); } } } }); Tooltip tooltip = new Tooltip(); StringBuilder search = new StringBuilder(); List<TreeItem<TreeNode>> searchContext = new ArrayList<>(); AtomicInteger searchIndex = new AtomicInteger(); root.focusedProperty().addListener((observable, oldValue, newValue) -> { if (!newValue) { tooltip.hide(); search.setLength(0); } }); root.boundsInLocalProperty().addListener((observable, oldValue, newValue) -> { Bounds bounds = root.localToScreen(newValue); tooltip.setAnchorX(bounds.getMinX()); tooltip.setAnchorY(bounds.getMinY()); }); root.addEventHandler(KeyEvent.KEY_PRESSED, event -> { if (tooltip.isShowing() && event.getCode() == KeyCode.UP) { if (searchIndex.decrementAndGet() < 0) { searchIndex.set(searchContext.size() - 1); } } else if (tooltip.isShowing() && event.getCode() == KeyCode.DOWN) { if (searchIndex.incrementAndGet() >= searchContext.size()) { searchIndex.set(0); } } else { return; } event.consume(); root.scrollTo(root.getRow(searchContext.get(searchIndex.get()))); root.getSelectionModel().select(searchContext.get(searchIndex.get())); }); root.addEventHandler(KeyEvent.KEY_TYPED, event -> { if (event.getCharacter().charAt(0) == '\b') { if (search.length() > 0) { search.setLength(search.length() - 1); } } else if (event.getCharacter().charAt(0) == '\u001B') { //esc tooltip.hide(); search.setLength(0); return; } else if (search.length() > 0 || (search.length() == 0 && StringUtils.isAlphanumeric(event.getCharacter()))) { search.append(event.getCharacter()); if (!tooltip.isShowing()) { tooltip.show(root.getScene().getWindow()); } } if (!tooltip.isShowing()) return; String str = search.toString(); tooltip.setText("Search for: " + str); searchContext.clear(); ArrayDeque<TreeItem<TreeNode>> deque = new ArrayDeque<>(); deque.addAll(rootItem.getChildren()); while (!deque.isEmpty()) { TreeItem<TreeNode> item = deque.poll(); if (item.getValue().getDisplayName().contains(str)) { searchContext.add(item); } if (item.isExpanded() && item.getChildren().size() > 0) deque.addAll(item.getChildren()); } searchIndex.set(0); if (searchContext.size() > 0) { root.scrollTo(root.getRow(searchContext.get(0))); root.getSelectionModel().select(searchContext.get(0)); } }); openedFileController.loadedFiles().addListener((MapChangeListener<String, OpenedFile>) change -> { if (change.getValueAdded() != null) { updateTree(change.getValueAdded()); } if (change.getValueRemoved() != null) { this.rootItem.getChildren() .removeIf(ti -> ti.getValue().equals(change.getValueRemoved().getRoot())); } }); }