Java Code Examples for javafx.scene.control.MenuItem#setOnAction()

The following examples show how to use javafx.scene.control.MenuItem#setOnAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataViewer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public void updateMenuButton(Menu menuButton, DataView dataView) {
    for (DataView view : dataView.getSubDataViews()) {
        final String name = view.getName();
        final Node icon = view.getIcon();

        if (view.getSubDataViews().isEmpty()) {
            MenuItem menuItem = new MenuItem(name, icon); // NOPMD - allocation within loop ok in this context

            menuItem.setOnAction(evt -> dataView.setView(view));
            menuButton.getItems().add(menuItem);
            continue;
        }

        Menu subMenuButton = new Menu(name, icon); // NOPMD - allocation within loop ok in this context
        subMenuButton.setOnAction(evt -> dataView.setView(view));
        menuButton.getItems().add(subMenuButton);
        updateMenuButton(subMenuButton, view);
    }
}
 
Example 2
Source File: LogFX.java    From LogFX with GNU General Public License v3.0 6 votes vote down vote up
@MustCallOnJavaFXThread
private Menu fileMenu() {
    Menu menu = new Menu( "_File" );
    menu.setMnemonicParsing( true );

    MenuItem open = new MenuItem( "_Open File" );
    open.setAccelerator( new KeyCodeCombination( KeyCode.O, KeyCombination.SHORTCUT_DOWN ) );
    open.setMnemonicParsing( true );
    open.setOnAction( ( event ) -> new FileOpener( stage, this::open ) );

    MenuItem showLogFxLog = new MenuItem( "Open LogFX Log" );
    showLogFxLog.setAccelerator( new KeyCodeCombination( KeyCode.O,
            KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN ) );
    showLogFxLog.setOnAction( ( event ) ->
            open( LogFXLogFactory.INSTANCE.getLogFilePath().toFile() ) );

    MenuItem close = new MenuItem( "E_xit" );
    close.setAccelerator( new KeyCodeCombination( KeyCode.W,
            KeyCombination.SHIFT_DOWN, KeyCombination.SHORTCUT_DOWN ) );
    close.setMnemonicParsing( true );
    close.setOnAction( ( event ) -> stage.close() );
    menu.getItems().addAll( open, showLogFxLog, close );

    return menu;
}
 
Example 3
Source File: HexEditorView.java    From standalone-app with Apache License 2.0 6 votes vote down vote up
@Override
protected Node createView0(OpenedFile file, String path) {
    HexArea editor = new HexArea();
    editor.setContent(file.getContent(path));

    ContextMenu newContextMenu = new ContextMenu();
    MenuItem save = new MenuItem("Save");
    save.setOnAction(e -> {
        save(editor).whenComplete((res, err) -> {
            if (err != null) {
                err.printStackTrace();
            } else {
                file.putContent(path, res);
            }
        });
    });
    newContextMenu.getItems().add(save);
    editor.setContextMenu(newContextMenu);

    return editor;
}
 
Example 4
Source File: MeshesGroupContextMenu.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public ContextMenu createMenu(final double[] coordinate)
{
	final ContextMenu menu = new ContextMenu();
	final MenuItem centerAtItem = new MenuItem(String.format(
			"Center 2D orthoslices at (%.3f, %.3f, %.3f)",
			coordinate[0],
			coordinate[1],
			coordinate[2]
		));
	centerAtItem.setOnAction(e -> {
		final AffineTransform3D globalTransform = new AffineTransform3D();
		manager.getTransform(globalTransform);
		globalTransform.apply(coordinate, coordinate);
		globalTransform.set(globalTransform.get(0, 3) - coordinate[0], 0, 3);
		globalTransform.set(globalTransform.get(1, 3) - coordinate[1], 1, 3);
		globalTransform.set(globalTransform.get(2, 3) - coordinate[2], 2, 3);
		manager.setTransform(globalTransform);
	});
	menu.getItems().add(centerAtItem);
	menu.setAutoHide(true);
	return menu;
}
 
Example 5
Source File: YOLOApp.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private HBox buildBottomPane() {
	sldThreshold = new Slider(0.1f, 1.0f, DEFAULT_THRESHOLD);
	sldThreshold.setShowTickLabels(true);
	sldThreshold.setMajorTickUnit(0.1);
	sldThreshold.setBlockIncrement(0.01);
	sldThreshold.setShowTickMarks(true);
	sldThreshold.valueProperty().addListener(v -> update());
	MenuButton mbLoadImage = new MenuButton("Load Image");
	MenuItem mnLocalImage = new MenuItem("From Computer");
	mbLoadImage.getItems().add(mnLocalImage);
	MenuItem mnUrl = new MenuItem("Enter URL");
	mnUrl.setOnAction(e -> {
		Optional<String> imgUrl = AppUtils.askInputFromUser("Enter an URL", "Enter an image URL:");
		AppUtils.doBlockingAsyncWork(scene, () -> {
			imgUrl.ifPresent(this::checkAndLoadImage);
		});

	});
	mnLocalImage.setOnAction(e -> {
		FileChooser fc = new FileChooser();
		fc.getExtensionFilters().add(new ExtensionFilter("PNG Files", "*.png"));
		fc.getExtensionFilters().add(new ExtensionFilter("JPG Files", "*.jpg"));
		File selectedFile = fc.showOpenDialog(sldThreshold.getScene().getWindow());
		if (selectedFile != null) {
			checkAndLoadImage(selectedFile);
		}
	});
	mbLoadImage.getItems().add(mnUrl);
	HBox hbBottom = new HBox(10, new Label("Threshold: "), sldThreshold, mbLoadImage);
	hbBottom.setAlignment(Pos.CENTER);
	return hbBottom;
}
 
Example 6
Source File: DatabaseMenu.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create the database menu.
 */
public DatabaseMenu() {
    super(LabelGrabber.INSTANCE.getLabel("database.heading"));

    newSongItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("new.song.button"), new ImageView(new Image(QueleaProperties.get().getUseDarkTheme() ? "file:icons/newsong-light.png" : "file:icons/newsong.png", 16, 16, false, true)));
    newSongItem.setOnAction(new NewSongActionHandler());
    newSongItem.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    getItems().add(newSongItem);

    getItems().add(new SeparatorMenuItem());
    importMenu = new ImportMenu();
    getItems().add(importMenu);
    exportMenu = new ExportMenu();
    getItems().add(exportMenu);
}
 
Example 7
Source File: LogFX.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
@MustCallOnJavaFXThread
private Menu helpMenu() {
    Menu menu = new Menu( "_Help" );
    menu.setMnemonicParsing( true );

    MenuItem about = new MenuItem( "_About LogFX" );
    about.setOnAction( ( event ) -> new AboutLogFXView( getHostServices() ).show() );

    menu.getItems().addAll( about );

    return menu;
}
 
Example 8
Source File: IndexService.java    From xJavaFxTool-spring with Apache License 2.0 5 votes vote down vote up
public ContextMenu getSelectContextMenu(String selectText) {
    selectText = selectText.toLowerCase();
    ContextMenu contextMenu = new ContextMenu();
    for (MenuItem menuItem : indexController.getMenuItemMap().values()) {
        if (menuItem.getText().toLowerCase().contains(selectText)) {
            MenuItem menu_tab = new MenuItem(menuItem.getText(), menuItem.getGraphic());
            menu_tab.setOnAction(event1 -> {
                menuItem.fire();
            });
            contextMenu.getItems().add(menu_tab);
        }
    }
    return contextMenu;
}
 
Example 9
Source File: TransferMenu.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
private MenuItem getMenuItem (String text, EventHandler<ActionEvent> eventHandler,
    KeyCode keyCode)
{
  MenuItem menuItem = new MenuItem (text);
  menuItem.setOnAction (eventHandler);
  menuItem
      .setAccelerator (new KeyCodeCombination (keyCode, KeyCombination.SHORTCUT_DOWN));
  return menuItem;
}
 
Example 10
Source File: DisplayEditor.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private MenuItem createMenuItem(final ActionDescription action)
{
    final MenuItem item = new MenuItem();
    try
    {
        item.setGraphic(ImageCache.getImageView(action.getIconResourcePath()));
    }
    catch (final Exception ex)
    {
        logger.log(Level.WARNING, "Cannot load action icon", ex);
    }
    item.setText(action.getToolTip());
    item.setOnAction(event -> action.run(this));
    return item;
}
 
Example 11
Source File: PanelMenuCreator.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MenuItem closePanelMenuItem() {
    MenuItem closePanel = new MenuItem("Close");
    closePanel.setOnAction(e -> {
        logger.info("Menu: Panels > Close");
        panelControl.closeCurrentPanel();
    });
    closePanel.setAccelerator(CLOSE_PANEL);
    return closePanel;
}
 
Example 12
Source File: ChatShowPane.java    From oim-fx with MIT License 5 votes vote down vote up
private void initContextMenu() {
	MenuItem mi = new MenuItem("复制");
	mi.setOnAction(a -> {
		KeyEvent ke = createKeyEvent(KeyEvent.KEY_PRESSED, KeyCode.C, "", "", false, true, false, false);
		processKeyEvent(ke);
		ke = createKeyEvent(KeyEvent.KEY_RELEASED, KeyCode.C, "", "", false, true, false, false);
		processKeyEvent(ke);
	});
	contextMenu.getItems().add(mi);
}
 
Example 13
Source File: LabelSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TextFieldTreeCellImpl() {
    MenuItem addMenuItem = new MenuItem("Add Employee");
    addMenu.getItems().add(addMenuItem);
    addMenuItem.setOnAction((ActionEvent t) -> {
        TreeItem newEmployee = new TreeItem<>("New Employee");
        getTreeItem().getChildren().add(newEmployee);
    });
}
 
Example 14
Source File: ActionUtils.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static MenuItem createMenuItem(Action action) {
	MenuItem menuItem = (action.selected != null) ? new CheckMenuItem(action.text) : new MenuItem(action.text);
	if (action.accelerator != null)
		menuItem.setAccelerator(action.accelerator);
	if (action.icon != null)
		menuItem.setGraphic(FontAwesomeIconFactory.get().createIcon(action.icon));
	if (action.action != null)
		menuItem.setOnAction(action.action);
	if (action.disable != null)
		menuItem.disableProperty().bind(action.disable);
	if (action.selected != null)
		((CheckMenuItem)menuItem).selectedProperty().bindBidirectional(action.selected);
	return menuItem;
}
 
Example 15
Source File: SingleSelectionPane.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initContextMenu() {
    MenuItem infoItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Document properties"),
            MaterialDesignIcon.INFORMATION_OUTLINE);
    infoItem.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.ALT_DOWN));
    infoItem.setOnAction(
            e -> Platform.runLater(() -> eventStudio().broadcast(new ShowPdfDescriptorRequest(descriptor))));

    removeSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Remove"), MaterialDesignIcon.MINUS);
    removeSelected.setOnAction(e -> eventStudio().broadcast(new ClearModuleEvent(), getOwnerModule()));

    MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set destination"),
            MaterialDesignIcon.AIRPLANE_LANDING);
    setDestinationItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.ALT_DOWN));
    setDestinationItem.setOnAction(e -> eventStudio()
            .broadcast(requestDestination(descriptor.getFile(), getOwnerModule()), getOwnerModule()));

    MenuItem openFileItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open"),
            MaterialDesignIcon.FILE_PDF_BOX);
    openFileItem.setOnAction(e -> eventStudio().broadcast(new OpenFileRequest(descriptor.getFile())));

    MenuItem openFolderItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open Folder"),
            MaterialDesignIcon.FOLDER_OUTLINE);
    openFolderItem
            .setOnAction(e -> eventStudio().broadcast(new OpenFileRequest(descriptor.getFile().getParentFile())));

    field.getTextField().setContextMenu(new ContextMenu(setDestinationItem, new SeparatorMenuItem(), removeSelected,
            new SeparatorMenuItem(), infoItem, openFileItem, openFolderItem));
}
 
Example 16
Source File: LanguageHandler.java    From VocabHunter with Apache License 2.0 4 votes vote down vote up
public void setupControl(final MenuItem menuLanguage) {
    menuLanguage.setOnAction(e -> openChangeLanguageDialogueAction());
}
 
Example 17
Source File: SpectraIdentificationResultsWindowFX.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public SpectraIdentificationResultsWindowFX() {
  super();

  pnMain = new BorderPane();
  this.setScene(new Scene(pnMain));
  getScene().getStylesheets()
      .addAll(MZmineCore.getDesktop().getMainWindow().getScene().getStylesheets());

  pnMain.setPrefSize(1000, 600);
  pnMain.setMinSize(700, 500);
  setMinWidth(700);
  setMinHeight(500);

  setTitle("Processing...");

  pnGrid = new GridPane();
  // any number of rows

  noMatchesFound = new Label("I'm working on it");
  noMatchesFound.setFont(headerFont);
  // yellow
  noMatchesFound.setTextFill(Color.web("0xFFCC00"));
  pnGrid.add(noMatchesFound, 0, 0);
  pnGrid.setVgap(5);

  // Add the Windows menu
  MenuBar menuBar = new MenuBar();
  // menuBar.add(new WindowsMenu());

  Menu menu = new Menu("Menu");

  // set font size of chart
  MenuItem btnSetup = new MenuItem("Setup dialog");
  btnSetup.setOnAction(e -> {
    Platform.runLater(() -> {
      if (MZmineCore.getConfiguration()
          .getModuleParameters(SpectraIdentificationResultsModule.class)
          .showSetupDialog(true) == ExitCode.OK) {
        showExportButtonsChanged();
      }
    });
  });

  menu.getItems().add(btnSetup);

  CheckMenuItem cbCoupleZoomY = new CheckMenuItem("Couple y-zoom");
  cbCoupleZoomY.setSelected(true);
  cbCoupleZoomY.setOnAction(e -> setCoupleZoomY(cbCoupleZoomY.isSelected()));
  menu.getItems().add(cbCoupleZoomY);

  menuBar.getMenus().add(menu);
  pnMain.setTop(menuBar);

  scrollPane = new ScrollPane(pnGrid);
  pnMain.setCenter(scrollPane);
  scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
  scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);

  totalMatches = new ArrayList<>();
  matchPanels = new HashMap<>();
  setCoupleZoomY(true);

  show();
}
 
Example 18
Source File: DisplayNavigationViewController.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void createContextMenu(ContextMenuEvent e,
                               final List<File> selectedItems,
                               Control control) {
    contextMenu.getItems().clear();
    if (!selectedItems.isEmpty()) {
        open.setOnAction(event -> {
            selectedItems.forEach(item -> {
                openResource(item, null);
            });
        });
        copy.setOnAction(event -> {
            final ClipboardContent content = new ClipboardContent();
            content.putString(selectedItems.stream()
                    .map(f -> {
                        return f.getPath();
                    })
                    .collect(Collectors.joining(System.getProperty("line.separator"))));
            Clipboard.getSystemClipboard().setContent(content);
        });
        contextMenu.getItems().add(copy);
        contextMenu.getItems().add(open);
    }
    // If just one entry selected, check if there are multiple apps from which to select
    if (selectedItems.size() == 1) {
        final File file = selectedItems.get(0);
        final URI resource = ResourceParser.getURI(file);
        final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
        if (applications.size() > 0) {
            openWith.getItems().clear();
            for (AppResourceDescriptor app : applications) {
                final MenuItem open_app = new MenuItem(app.getDisplayName());
                final URL icon_url = app.getIconURL();
                if (icon_url != null)
                    open_app.setGraphic(new ImageView(icon_url.toExternalForm()));
                open_app.setOnAction(event -> app.create(resource));
                openWith.getItems().add(open_app);
            }
            contextMenu.getItems().add(openWith);
        }
    }
    contextMenu.show(control.getScene().getWindow(), e.getScreenX(), e.getScreenY());
}
 
Example 19
Source File: ScenegraphTreeView.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
private MenuItem goToTab(final String text) {
    final MenuItem goTo = new MenuItem(text);
    goTo.setOnAction(e -> scenicView.goToTab(text));
    return goTo;
}
 
Example 20
Source File: MenuToolkit.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MenuItem createMinimizeMenuItem() {
	MenuItem menuItem = new MenuItem(labelMaker.getLabel(LabelName.MINIMIZE));
	menuItem.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCombination.META_DOWN));
	menuItem.setOnAction(event -> StageUtils.minimizeFocusedStage());
	return menuItem;
}