Java Code Examples for javafx.scene.control.Menu#setDisable()

The following examples show how to use javafx.scene.control.Menu#setDisable() . 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: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleLabelType(LabelSelection selection) {
	ContextMenu menu = new ContextMenu();
	Menu refs = new Menu(LangUtil.translate("ui.edit.method.referrers"));
	for (AST ast : root.getChildren()) {
		if ((ast instanceof FlowController && ((FlowController) ast).targets().contains(selection.name)) ||
				(ast instanceof LineInsnAST && ((LineInsnAST) ast).getLabel().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 2
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 3
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 4
Source File: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private MenuBar createMenu(final Stage stage) {
    final MenuBar menuBar = new MenuBar();
    // For Mac OS X, use it's menu bar on top of screen
    if (PlatformInfo.is_mac_os_x)
        menuBar.setUseSystemMenuBar(true);

    // File
    final MenuItem open = new MenuItem(Messages.Open, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open.setOnAction(event -> fileOpen(stage, false));

    final MenuItem open_with = new MenuItem(Messages.OpenWith, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open_with.setOnAction(event -> fileOpen(stage, true));

    top_resources_menu = new Menu(Messages.TopResources, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    top_resources_menu.setDisable(true);

    final MenuItem file_save = new MenuItem(Messages.Save, ImageCache.getImageView(getClass(), "/icons/save_edit.png"));
    file_save.setOnAction(event -> JobManager.schedule(Messages.Save, monitor -> active_item_with_input.get().save(monitor)));

    final MenuItem file_save_as = new MenuItem(Messages.SaveAs, ImageCache.getImageView(getClass(), "/icons/saveas_edit.png"));
    file_save_as.setOnAction(event ->JobManager.schedule(Messages.SaveAs, monitor -> active_item_with_input.get().save_as(monitor)));

    final MenuItem exit = new MenuItem(Messages.Exit);
    exit.setOnAction(event ->
    {
        if (closeMainStage(null))
            stop();
    });

    final Menu file = new Menu(Messages.File, null,
                               open,
                               open_with,
                               top_resources_menu,
                               new SeparatorMenuItem(),
                               file_save,
                               file_save_as,
                               new SeparatorMenuItem(),
                               exit);
    file.setOnShowing(event ->
    {
        final DockItemWithInput input_item = active_item_with_input.get();
        if (input_item == null)
        {
            file_save.setDisable(true);
            file_save_as.setDisable(true);
        }
        else
        {
            file_save.setDisable(! input_item.isDirty());
            file_save_as.setDisable(! input_item.isSaveAsSupported());
        }
    });
    menuBar.getMenus().add(file);

    // Application Contributions
    final Menu applicationsMenu = new Menu(Messages.Applications);
    final MenuTreeNode node = MenuEntryService.getInstance().getMenuEntriesTree();
    addMenuNode(applicationsMenu, node);
    menuBar.getMenus().add(applicationsMenu);

    // Window
    show_tabs = new CheckMenuItem(Messages.AlwaysShowTabs);
    show_tabs.setSelected(DockPane.isAlwaysShowingTabs());
    show_tabs.setOnAction(event ->  DockPane.alwaysShowTabs(show_tabs.isSelected()));

    show_toolbar = new CheckMenuItem(Messages.ShowToolbar);
    show_toolbar.setOnAction(event -> showToolbar(show_toolbar.isSelected()));

    save_layout = new SaveLayoutMenuItem(this, memento_files);
    delete_layouts = new DeleteLayoutsMenuItem(this, memento_files);

    final Menu menu = new Menu(Messages.Window, null,
            show_tabs,
            show_toolbar,
            new SeparatorMenuItem(),
            save_layout,
            load_layout,
            delete_layouts,
            new SeparatorMenuItem(),
            /* Full Screen placeholder */
            new FullScreenAction(stage));
    // Update Full screen action when shown to get correct enter/exit FS mode
    menu.setOnShowing(event ->
    {   // Last menu item
        final int full_screen_index = menu.getItems().size()-1;
        final FullScreenAction full_screen = new FullScreenAction(stage);
        if (! AuthorizationService.hasAuthorization("full_screen"))
            full_screen.setDisable(true);
        menu.getItems().set(full_screen_index, full_screen);
    });
    menuBar.getMenus().add(menu);

    // Help
    final MenuItem content = createMenuItem(new OpenHelp());
    final MenuItem about = createMenuItem(new OpenAbout());
    menuBar.getMenus().add(new Menu(Messages.Help, null, about, content));

    return menuBar;
}