javafx.scene.control.Menu Java Examples

The following examples show how to use javafx.scene.control.Menu. 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: RenameMenuItem.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	primaryStage.setScene(new Scene(root, 300, 250));
	primaryStage.requestFocus();
	primaryStage.show();

	// Get the toolkit
	MenuToolkit tk = MenuToolkit.toolkit();

	// Create the default Application menu
	Menu defaultApplicationMenu = tk.createDefaultApplicationMenu("test");

	// Update the existing Application menu
	tk.setApplicationMenu(defaultApplicationMenu);

	// Since we now have a reference to the menu, we can rename items
	defaultApplicationMenu.getItems().get(1).setText("Hide all the otters");
}
 
Example #2
Source File: WorkspaceMenu.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
@Inject
public WorkspaceMenu(RecentWorkspacesService service) {
    super(DefaultI18nContext.getInstance().i18n("_Workspace"));
    this.service = service;
    setId("workspaceMenu");
    MenuItem load = new MenuItem(DefaultI18nContext.getInstance().i18n("_Load"));
    load.setId("loadWorkspace");
    load.setOnAction(e -> loadWorkspace());
    MenuItem save = new MenuItem(DefaultI18nContext.getInstance().i18n("_Save"));
    save.setOnAction(e -> saveWorkspace());
    save.setId("saveWorkspace");
    recent = new Menu(DefaultI18nContext.getInstance().i18n("Recen_ts"));
    recent.setId("recentWorkspace");
    service.getRecentlyUsedWorkspaces().stream().map(WorkspaceMenuItem::new).forEach(recent.getItems()::add);
    MenuItem clear = new MenuItem(DefaultI18nContext.getInstance().i18n("_Clear recents"));
    clear.setOnAction(e -> clearWorkspaces());
    clear.setId("clearWorkspaces");
    getItems().addAll(load, save, new SeparatorMenuItem(), recent, clear);
    eventStudio().addAnnotatedListeners(this);
}
 
Example #3
Source File: DemoView.java    From PreferencesFX with Apache License 2.0 6 votes vote down vote up
private void initializeParts() {
  menuBar = new MenuBar();
  menu = new Menu("Edit");
  preferencesMenuItem = new MenuItem("Preferences");

  welcomeLbl = new Label();
  brightnessLbl = new Label();
  nightModeLbl = new Label();
  scalingLbl = new Label();
  screenNameLbl = new Label();
  resolutionLbl = new Label();
  orientationLbl = new Label();
  favoritesLbl = new Label();
  fontSizeLbl = new Label();
  lineSpacingLbl = new Label();
  favoriteNumberLbl = new Label();
}
 
Example #4
Source File: PhysicsControlTreeNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
                            @NotNull final ObservableList<MenuItem> items) {

    if (getElement() instanceof PhysicsCollisionObject) {

        final Menu changeShapeMenu = new Menu(Messages.MODEL_NODE_TREE_ACTION_CHANGE_COLLISION_SHAPE, new ImageView(Icons.ADD_12));
        changeShapeMenu.getItems().addAll(new GenerateCollisionShapeAction(nodeTree, this),
                new CreateBoxCollisionShapeAction(nodeTree, this),
                new CreateCapsuleCollisionShapeAction(nodeTree, this),
                new CreateConeCollisionShapeAction(nodeTree, this),
                new CreateCylinderCollisionShapeAction(nodeTree, this),
                new CreateSphereCollisionShapeAction(nodeTree, this));

        items.add(changeShapeMenu);
    }

    super.fillContextMenu(nodeTree, items);
}
 
Example #5
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 #6
Source File: RFXMenuItem.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private String getTagForMenu(MenuItem source) {
    LinkedList<MenuItem> menuItems = new LinkedList<>();
    while (source != null) {
        menuItems.addFirst(source);
        source = source.getParentMenu();
    }
    if (menuItems.getFirst() instanceof Menu) {
        if (menuItems.size() >= 2) {
            ownerNode = menuItems.get(1).getParentPopup().getOwnerNode();
            return isMenuBar(ownerNode) ? "#menu" : "#contextmenu";
        }
    } else {
        ownerNode = menuItems.getFirst().getParentPopup().getOwnerNode();
        return "#contextmenu";
    }
    return null;
}
 
Example #7
Source File: RFXMenuItemTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void menuPath() {
    List<String> path = new ArrayList<>();
    Platform.runLater(() -> {
        Menu menuFile = new Menu("File");
        MenuItem add = new MenuItem("Shuffle");
        MenuItem clear = new MenuItem("Clear");
        MenuItem exit = new MenuItem("Exit");
        menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit);
        RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null);
        path.add(rfxMenuItem.getSelectedMenuPath(clear));
    });
    new Wait("Waiting for menu selection path") {
        @Override
        public boolean until() {
            return path.size() > 0;
        }
    };
    AssertJUnit.assertEquals("File>>Clear", path.get(0));
}
 
Example #8
Source File: RFXMenuItemTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void menuItemIconNoText() {
    List<String> path = new ArrayList<>();
    Platform.runLater(() -> {
        Menu menuFile = new Menu("File");
        MenuItem add = new MenuItem("Shuffle");
        MenuItem clear = new MenuItem();
        clear.setGraphic(new ImageView(RFXTabPaneTest.imgURL.toString()));
        MenuItem exit = new MenuItem("Exit");
        menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit);
        RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null);
        path.add(rfxMenuItem.getSelectedMenuPath(clear));
    });
    new Wait("Waiting for menu selection path") {
        @Override
        public boolean until() {
            return path.size() > 0;
        }
    };
    AssertJUnit.assertEquals("File>>middle", path.get(0));
}
 
Example #9
Source File: RFXMenuItemTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void subMenuPath() {
    List<String> path = new ArrayList<>();
    Platform.runLater(() -> {
        Menu menuEdit = new Menu("Edit");
        Menu menuEffect = new Menu("Picture Effect");

        final MenuItem noEffects = new MenuItem("No Effects");

        menuEdit.getItems().addAll(menuEffect, noEffects);
        MenuItem add = new MenuItem("Shuffle");
        menuEffect.getItems().addAll(add);
        RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null);
        path.add(rfxMenuItem.getSelectedMenuPath(add));
    });
    new Wait("Waiting for menu selection path") {
        @Override
        public boolean until() {
            return path.size() > 0;
        }
    };
    AssertJUnit.assertEquals("Edit>>Picture Effect>>Shuffle", path.get(0));
}
 
Example #10
Source File: RFXMenuItemTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void duplicateMenuPath() {
    List<String> path = new ArrayList<>();
    Platform.runLater(() -> {
        Menu menuFile = new Menu("File");
        MenuItem add = new MenuItem("Shuffle");

        MenuItem clear = new MenuItem("Clear");
        MenuItem clear1 = new MenuItem("Clear");
        MenuItem clear2 = new MenuItem("Clear");

        MenuItem exit = new MenuItem("Exit");

        menuFile.getItems().addAll(add, clear, clear1, clear2, new SeparatorMenuItem(), exit);
        RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null);
        path.add(rfxMenuItem.getSelectedMenuPath(clear2));
    });
    new Wait("Waiting for menu selection path") {
        @Override
        public boolean until() {
            return path.size() > 0;
        }
    };
    AssertJUnit.assertEquals("File>>Clear(2)", path.get(0));
}
 
Example #11
Source File: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleSwitchType(SwitchSelection selection) {
	ContextMenu menu = new ContextMenu();
	Menu refs = new Menu(LangUtil.translate("ui.edit.method.follow"));
	for(AST ast : root.getChildren()) {
		if(ast instanceof LabelAST) {
			String name = ((LabelAST) ast).getName().getName();
			String key = selection.mappings.get(name);
			if (key == null && name.equals(selection.dflt))
				key = "Default";
			if(key != null) {
				MenuItem ref = new ActionMenuItem(key + ": '" + ast.getLine() + ": " + ast.print() +"'", () -> {
					int line = ast.getLine() - 1;
					codeArea.moveTo(line, 0);
					codeArea.requestFollowCaret();
				});
				refs.getItems().add(ref);
			}
		}
	}
	if(refs.getItems().isEmpty())
		refs.setDisable(true);
	menu.getItems().add(refs);
	codeArea.setContextMenu(menu);
}
 
Example #12
Source File: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleVariableType(VariableSelection selection) {
	ContextMenu menu = new ContextMenu();
	Menu refs = new Menu(LangUtil.translate("ui.edit.method.referrers"));
	for (AST ast : root.getChildren()) {
		if (ast instanceof VarInsnAST && ((VarInsnAST) ast).getVariableName().getName().equals(selection.name)) {
			MenuItem ref = new ActionMenuItem(ast.getLine() + ": " + ast.print(), () -> {
				int line = ast.getLine() - 1;
				codeArea.moveTo(line, 0);
				codeArea.requestFollowCaret();
			});
			refs.getItems().add(ref);
		}
	}
	if (refs.getItems().isEmpty())
		refs.setDisable(true);
	menu.getItems().add(refs);
	codeArea.setContextMenu(menu);
}
 
Example #13
Source File: TestUtils.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
public static Collection<MenuItem> findItemsInMenuWithId(FxRobot robot, String menuToFind) {
    MenuBar menuBar = robot.lookup("#mainMenu").query();
    MenuItem menu =  menuBar.getMenus().stream().flatMap(m-> m.getItems().stream())
            .filter(m -> menuToFind.equals(m.getId()))
            .findFirst().orElseThrow(RuntimeException::new);
    return ((Menu)menu).getItems();
}
 
Example #14
Source File: JavaFXMenuBarElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Menu getParentMenu(ObservableList<Menu> menus, String menuText) {
    for (Menu menu : menus) {
        if (parentMenuText(menus, menus.indexOf(menu)).equals(menuText)) {
            return menu;
        }
    }
    return null;
}
 
Example #15
Source File: TestUtils.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
public static Collection<MenuItem> recurseGetAllMenus(FxRobot robot, Collection<MenuItem> items) {
    var ret = new ArrayList<MenuItem>();
    for (MenuItem item : items) {
        ret.add(item);
        if(item instanceof Menu) {
            ret.addAll(recurseGetAllMenus(robot, ((Menu)item).getItems()));
        }
    }
    return ret;
}
 
Example #16
Source File: LogFX.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
@MustCallOnJavaFXThread
private Menu viewMenu() {
    Menu menu = new Menu( "_View" );
    menu.setMnemonicParsing( true );

    CheckMenuItem highlight = new CheckMenuItem( "_Highlight Options" );
    highlight.setAccelerator( new KeyCodeCombination( KeyCode.H, KeyCombination.SHORTCUT_DOWN ) );
    highlight.setMnemonicParsing( true );
    bindMenuItemToDialog( highlight, () ->
            showHighlightOptionsDialog( highlightOptions ) );

    MenuItem orientation = new MenuItem( "Switch Pane Orientation" );
    orientation.setAccelerator( new KeyCodeCombination( KeyCode.S,
            KeyCombination.SHIFT_DOWN, KeyCombination.SHORTCUT_DOWN ) );
    orientation.setOnAction( event -> logsPane.switchOrientation() );

    CheckMenuItem font = new CheckMenuItem( "Fon_t" );
    font.setAccelerator( new KeyCodeCombination( KeyCode.F,
            KeyCombination.SHIFT_DOWN, KeyCombination.SHORTCUT_DOWN ) );
    font.setMnemonicParsing( true );
    bindMenuItemToDialog( font, () -> showFontPicker( config.fontProperty() ) );

    CheckMenuItem filter = new CheckMenuItem( "Enable _filters" );
    filter.setAccelerator( new KeyCodeCombination( KeyCode.F,
            KeyCombination.SHORTCUT_DOWN ) );
    filter.setMnemonicParsing( true );
    filter.selectedProperty().bindBidirectional( config.filtersEnabledProperty() );

    MenuItem showContextMenu = new MenuItem( "Show Context Menu" );
    showContextMenu.setAccelerator( new KeyCodeCombination( KeyCode.E, KeyCombination.SHORTCUT_DOWN ) );
    showContextMenu.setOnAction( event -> logsPane.showContextMenu() );

    menu.getItems().addAll( highlight, orientation, font, filter, showContextMenu );
    return menu;
}
 
Example #17
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 #18
Source File: DisplayWindow.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Create Menu with new file/folder options
 * 
 * @return
 */
private Menu createNewMenu() {
    Menu newMenu = new Menu("New");
    newMenu.getItems().add(newTestcaseAction.getMenuItem());
    newMenu.getItems().add(etAction.getMenuItem());
    newMenu.getItems().add(newModuleAction.getMenuItem());
    newMenu.getItems().add(newFixtureAction.getMenuItem());
    newMenu.getItems().add(newCheckListAction.getMenuItem());
    newMenu.getItems().add(newModuleDirAction.getMenuItem());
    newMenu.getItems().add(newSuiteFileAction.getMenuItem());
    newMenu.getItems().add(newFeatureFileAction.getMenuItem());
    newMenu.getItems().add(newStoryFileAction.getMenuItem());
    newMenu.getItems().add(newIssueFileAction.getMenuItem());
    return newMenu;
}
 
Example #19
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String parentMenuText(ObservableList<Menu> menus, int index) {
    String original = getMenuText(menus, index);
    String itemText = original;
    int suffixIndex = 0;
    for (int i = 0; i < index; i++) {
        String current = getMenuText(menus, i);
        if (current.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example #20
Source File: MyMenuBar.java    From classpy with MIT License 5 votes vote down vote up
private void createHelpMenu() {
    MenuItem aboutMenuItem = new MenuItem("_About");
    aboutMenuItem.setOnAction(e -> AboutDialog.showDialog());
    aboutMenuItem.setMnemonicParsing(true);

    Menu helpMenu = new Menu("_Help");
    helpMenu.getItems().add(aboutMenuItem);
    helpMenu.setMnemonicParsing(true);

    getMenus().add(helpMenu);
}
 
Example #21
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private String getMenuText(ObservableList<Menu> menus, int index) {
    Menu menu = menus.get(index);
    String text = menu.getText();
    if (text == null || "".equals(text)) {
        return getMenuTextFromIcon(menu, index);
    }
    return text;
}
 
Example #22
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getTextForMenuItem(MenuItem menuItem, Menu parentMenu) {
    int index = parentMenu.getItems().indexOf(menuItem);
    String original = getMenuItemText(parentMenu, index);
    String itemText = original;
    int suffixIndex = 0;

    for (int i = 0; i < index; i++) {
        String current = getMenuItemText(parentMenu, i);

        if (current.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example #23
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getMenuItemText(Menu parentMenu, int index) {
    MenuItem menuItem = parentMenu.getItems().get(index);
    String text = menuItem.getText();
    if (text == null || "".equals(text)) {
        return getTextFromIcon(menuItem, index);
    }
    return text;
}
 
Example #24
Source File: MyMenuBar.java    From classpy with MIT License 5 votes vote down vote up
private void createFileMenu() {
    Menu fileMenu = new Menu("_File");
    fileMenu.getItems().add(createOpenMenu());
    fileMenu.getItems().add(createRecentMenu());
    fileMenu.setMnemonicParsing(true);
    getMenus().add(fileMenu);
}
 
Example #25
Source File: NodeTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @Nullable Menu createToolMenu(@NotNull final NodeTree<?> nodeTree) {
    final Menu toolMenu = new Menu(Messages.MODEL_NODE_TREE_ACTION_TOOLS, new ImageView(Icons.INFLUENCER_16));
    toolMenu.getItems().addAll(new OptimizeGeometryAction(nodeTree, this));
    return toolMenu;
}
 
Example #26
Source File: JavaFXContextMenuElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getTextForMenuItem(MenuItem menuItem) {
    Menu parentMenu = menuItem.getParentMenu();
    if (parentMenu == null) {
        String text = menuItem.getText();
        if (text == null || "".equals(text)) {
            return getTextFromIcon(menuItem, -1);
        }
        return text;
    }
    return getTextForMenuItem(menuItem, parentMenu);
}
 
Example #27
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(ActionEvent event) {
    if (recorder.isPaused() || recorder.isInsertingScript() || JavaServer.handlingRequest) {
        return;
    }
    if (event.getSource() instanceof Menu) {
        return;
    }
    if (event.getSource() != null)
        new RFXMenuItem(recorder, objectMapConfiguration).record(event);
}
 
Example #28
Source File: RFXMenuItem.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getTextForMenuItem(MenuItem menuItem) {
    Menu parentMenu = menuItem.getParentMenu();
    if (parentMenu == null) {
        if (menuBar != null) {
            ObservableList<Menu> menus = menuBar.getMenus();
            return parentMenuText(menus, menus.indexOf(menuItem));
        }
        String text = menuItem.getText();
        if (text == null || "".equals(text)) {
            return getTextFromIcon(menuItem, -1);
        }
        return text;
    }
    return getTextForMenuItem(menuItem, parentMenu);
}
 
Example #29
Source File: TaChartViewer.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the context menu.
 *
 * @return The context menu.
 */
private ContextMenu createContextMenu() {
    final ContextMenu menu = new ContextMenu();
    menu.setAutoHide(true);
    Menu export = new Menu("Export As");

    MenuItem pngItem = new MenuItem("PNG...");
    pngItem.setOnAction(e -> handleExportToPNG());
    export.getItems().add(pngItem);

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

    if (ExportUtils.isOrsonPDFAvailable()) {
        MenuItem pdfItem = new MenuItem("PDF...");
        pdfItem.setOnAction(e -> handleExportToPDF());
        export.getItems().add(pdfItem);
    }
    if (ExportUtils.isJFreeSVGAvailable()) {
        MenuItem svgItem = new MenuItem("SVG...");
        svgItem.setOnAction(e -> handleExportToSVG());
        export.getItems().add(svgItem);
    }
    menu.getItems().add(export);
    return menu;
}
 
Example #30
Source File: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void addMenuNode(Menu parent, MenuTreeNode node) {

        for (MenuEntry entry : node.getMenuItems()) {
            MenuItem m = createMenuItem(entry);
            parent.getItems().add(m);
        }

        for (MenuTreeNode child : node.getChildren()) {
            Menu childMenu = new Menu(child.getName());
            addMenuNode(childMenu, child);
            parent.getItems().add(childMenu);
        }
    }