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

The following examples show how to use javafx.scene.control.MenuItem#setGraphic() . 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: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param entry {@link MenuEntry}
 *  @return {@link MenuItem}
 */
private MenuItem createMenuItem(final MenuEntry entry)
{
    final MenuItem item = new MenuItem(entry.getName());
    final Image icon = entry.getIcon();
    if (icon != null)
        item.setGraphic(new ImageView(icon));
    item.setOnAction(event ->
    {
        try
        {
            entry.call();
        }
        catch (Exception ex)
        {
            logger.log(Level.WARNING, "Error invoking menu " + entry.getName(), ex);
        }
    });
    return item;
}
 
Example 2
Source File: FXUIUtils.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static MenuItem createMenuItem(String name, String commandName, String mnemonic) {
    MenuItem menuItem = new MenuItem();
    menuItem.setId(name + "MenuItem");
    Node enabledIcon = getImageFrom(name, "icons/", FromOptions.NULL_IF_NOT_EXISTS);
    if (enabledIcon != null) {
        menuItem.setGraphic(enabledIcon);
    }
    menuItem.setText(commandName);
    if (!"".equals(mnemonic)) {
        menuItem.setAccelerator(KeyCombination.keyCombination(mnemonic));
    }

    return menuItem;
}
 
Example 3
Source File: FXUIUtils.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static MenuItem createCheckboxMenuItem(String name, String commandName, String mnemonic) {
    MenuItem menuItem = new CheckMenuItem();
    menuItem.setId(name + "MenuItem");
    Node enabledIcon = getImageFrom(name, "icons/", FromOptions.NULL_IF_NOT_EXISTS);
    if (enabledIcon != null) {
        menuItem.setGraphic(enabledIcon);
    }
    menuItem.setText(commandName);
    if (!"".equals(mnemonic)) {
        menuItem.setAccelerator(KeyCombination.keyCombination(mnemonic));
    }
    return menuItem;
}
 
Example 4
Source File: TestRunner.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void populateSavedHistory(JSONArray savedHistory) {
    for (int i = 0; i < savedHistory.length(); i++) {
        JSONObject test = savedHistory.getJSONObject(i);
        MenuItem item = createMenuItem(test, true);
        item.setGraphic(FXUIUtils.getIcon("favourite"));
        historyMenuItems.add(item);
    }
}
 
Example 5
Source File: TestRunner.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void populateUnSavedHistory(JSONArray unsavedHistory) {
    if (unsavedHistory.length() > 0 && historyMenuItems.size() > 0) {
        historyMenuItems.add(new SeparatorMenuItem());
    }
    ArrayList<MenuItem> items = new ArrayList<>();
    for (int i = 0; i < unsavedHistory.length(); i++) {
        JSONObject testJSON = unsavedHistory.getJSONObject(i);
        MenuItem item = createMenuItem(testJSON, false);
        item.setGraphic(getIcon(State.valueOf(testJSON.getString("state"))));
        items.add(0, item);
    }
    historyMenuItems.addAll(items);
}
 
Example 6
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 7
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 8
Source File: ScheduleMenu.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create the scheudle menu
 */
public ScheduleMenu() {
    super(LabelGrabber.INSTANCE.getLabel("schedule.menu"));

    final MainPanel mainPanel = QueleaApp.get().getMainWindow().getMainPanel();
    final ScheduleList scheduleList = mainPanel.getSchedulePanel().getScheduleList();
    boolean darkTheme = QueleaProperties.get().getUseDarkTheme();

    addPowerpointItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.presentation.button"));
    if (!Utils.isMac()) {
        addPowerpointItem.setGraphic(new ImageView(new Image(darkTheme ? "file:icons/powerpoint-light.png" : "file:icons/powerpoint.png", 20, 20, true, false)));
    }
    addPowerpointItem.setOnAction(new AddPowerpointActionHandler());
    getItems().add(addPowerpointItem);

    addVideoItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.video.button"));
    if (!Utils.isMac()) {
        addVideoItem.setGraphic(new ImageView(new Image(darkTheme ? "file:icons/video file-light.png" : "file:icons/video file.png", 20, 20, true, false)));
    }
    addVideoItem.setOnAction(new AddVideoActionHandler());
    getItems().add(addVideoItem);

    addTimerItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.timer.tooltip"), new ImageView(new Image(darkTheme ? "file:icons/timer-dark-light.png" : "file:icons/timer-dark.png", 16, 16, false, true)));
    addTimerItem.setOnAction(new AddTimerActionHandler());
    getItems().add(addTimerItem);

    addPDFItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.pdf.tooltip"), new ImageView(new Image(darkTheme ? "file:icons/add_pdf-light.png" : "file:icons/add_pdf.png", 16, 16, false, true)));
    addPDFItem.setOnAction(new AddPdfActionHandler());
    getItems().add(addPDFItem);

    dvdImageStack = new StackPane();
    dvdImageStack.getChildren().add(new ImageView(new Image(darkTheme ? "file:icons/dvd-light.png" : "file:icons/dvd.png", 16, 16, false, true)));
    addDVDItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.dvd.button"), dvdImageStack);
    addDVDItem.setOnAction(new AddDVDActionHandler());
    if (!Utils.isMac()) {
        getItems().add(addDVDItem);
    }

    addWebItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.website"), new ImageView(new Image(darkTheme ? "file:icons/web-small-light.png" : "file:icons/web-small.png", 16, 16, false, true)));
    addWebItem.setOnAction(new AddWebActionHandler());
    getItems().add(addWebItem);

    addImageItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("add.images.panel"), new ImageView(new Image(darkTheme ? "file:icons/image-light.png" : "file:icons/image.png", 16, 16, false, true)));
    addImageItem.setOnAction(new AddImageActionHandler());
    getItems().add(addImageItem);

    getItems().add(new SeparatorMenuItem());

    manageNoticesItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("manage.notices.button"), new ImageView(new Image(darkTheme ? "file:icons/info-light.png" : "file:icons/info.png", 16, 16, false, true)));
    manageNoticesItem.setOnAction(new ShowNoticesActionHandler());
    manageNoticesItem.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCombination.SHORTCUT_DOWN));
    getItems().add(manageNoticesItem);

    exportScheduleItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("export.schedule.songs.pdf.button"), new ImageView(new Image(darkTheme ? "file:icons/pdf-light.png" : "file:icons/pdf.png", 16, 16, false, true)));
    exportScheduleItem.setOnAction(new ExportPDFScheduleSongsActionHandler());
    getItems().add(exportScheduleItem);

}
 
Example 9
Source File: FileMenu.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create the file menu.
 */
public FileMenu() {
    super(LabelGrabber.INSTANCE.getLabel("file.menu"));
    boolean darkTheme = QueleaProperties.get().getUseDarkTheme();

    newItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("new.schedule.button"));
    if (!Utils.isMac()) {
        newItem.setGraphic(getImage("file:icons/filenew.png"));
    }
    newItem.setOnAction(new NewScheduleActionHandler());
    newItem.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN));
    getItems().add(newItem);

    openItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("open.schedule.button"));
    if (!Utils.isMac()) {
        openItem.setGraphic(getImage("file:icons/fileopen.png"));
    }
    openItem.setOnAction(new OpenScheduleActionHandler());
    openItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    getItems().add(openItem);

    saveItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("save.schedule.button"));
    if (!Utils.isMac()) {
        saveItem.setGraphic(getImage("file:icons/filesave.png"));
    }
    saveItem.setOnAction(new SaveScheduleActionHandler(false));
    saveItem.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN));
    getItems().add(saveItem);

    saveAsItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("save.as.schedule.button"));
    if (!Utils.isMac()) {
        saveAsItem.setGraphic(getImage("file:icons/filesaveas.png"));
    }
    saveAsItem.setOnAction(new SaveScheduleActionHandler(true));
    getItems().add(saveAsItem);

    exportToPDFItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("export.schedule.pdf.button"));
    if(!Utils.isMac()) {
        exportToPDFItem.setGraphic(new ImageView(new Image("file:icons/fileexport.png", 20, 20, true, false)));
    }
    exportToPDFItem.setOnAction(new ExportPDFScheduleActionHandler());
    getItems().add(exportToPDFItem);

    printItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("print.schedule.button"));
    if (!Utils.isMac()) {
        printItem.setGraphic(getImage("file:icons/fileprint.png"));
    }
    printItem.setOnAction(new PrintScheduleActionHandler());
    printItem.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.SHORTCUT_DOWN));
    getItems().add(printItem);

    exitItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("exit.button"));
    if(!Utils.isMac()) {
        exitItem.setGraphic(new ImageView(new Image("file:icons/exit.png", 20, 20, true, false)));
    }
    exitItem.setOnAction(new ExitActionHandler());
    getItems().add(exitItem);
}
 
Example 10
Source File: Editor.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/** Initializes editor tree view and context menus. */
private void initTree() {
  // create tree directory context menu
  MenuItem newFile = new MenuItem("New File");
  newFile.setGraphic(Icons.get("new_file"));
  newFile.setOnAction(e -> addFile());
  MenuItem newFolder = new MenuItem("New Folder");
  newFolder.setGraphic(Icons.get("new_folder"));
  newFolder.setOnAction(e -> addFolder());
  MenuItem renameDir = new MenuItem("Rename");
  renameDir.setGraphic(Icons.get("edit"));
  renameDir.setOnAction(e -> renameFolder());
  MenuItem deleteDir = new MenuItem("Delete");
  deleteDir.setGraphic(Icons.get("trash"));
  deleteDir.setOnAction(e -> deleteFolder());
  dirContext = new ContextMenu();
  dirContext.getItems().addAll(newFile, newFolder, renameDir, deleteDir);
  // create tree file context menu
  MenuItem renameFile = new MenuItem("Rename");
  renameFile.setGraphic(Icons.get("edit"));
  renameFile.setOnAction(e -> renameFile());
  MenuItem deleteFile = new MenuItem("Delete");
  deleteFile.setGraphic(Icons.get("trash"));
  deleteFile.setOnAction(e -> deleteFile());
  fileContext = new ContextMenu();
  fileContext.getItems().addAll(renameFile, deleteFile);
  // add click action to tree
  tree.setOnMouseClicked(e -> {
    dirContext.hide();
    fileContext.hide();
    TreeFileItem item = (TreeFileItem) tree.getSelectionModel().getSelectedItem();
    if (item != null && e.getButton() == MouseButton.PRIMARY && item.getFile().isFile()) {
      tree.getSelectionModel().clearSelection();
      open(item.getFile());
    } else if (item != null && e.getButton() == MouseButton.SECONDARY) {
      File file = item.getFile();
      if (file.isDirectory()) {
        dirContext.show(tree, e.getScreenX(), e.getScreenY());
      } else {
        fileContext.show(tree, e.getScreenX(), e.getScreenY());
      }
    }
  });
  Platform.runLater(() -> updateTree());
  DirWatcher.start(this);
}
 
Example 11
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 12
Source File: ContextMenuHelper.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Add entries suitable for the current selection
 *
 *  <p>Invoke inside 'setOnContextMenuRequested' handler,
 *  after adding application specific menu entries,
 *  to add entries based on the current selection.
 *
 *  @param parent_node Parent node, usually owner of the context menu
 *  @param menu Menu where selection-based entries will be added
 *  @return <code>true</code> if a supported entry was added.
 */
public static boolean addSupportedEntries(final Node parent_node, final ContextMenu menu)
{
    final Window window = parent_node.getScene().getWindow();
    if (! (window instanceof Stage))
    {
        logger.log(Level.WARNING, "Expected 'Stage' for context menu, got " + window);
        return false;
    }
    final Stage stage = (Stage) window;
    // Assert that this window's dock pane is the active one.
    // (on Mac and Linux, invoking the context menu will not
    //  always activate the stage)
    DockStage.setActiveDockStage(stage);

    final List<ContextMenuEntry> entries = ContextMenuService.getInstance().listSupportedContextMenuEntries();
    if (entries.isEmpty())
        return false;

    for (ContextMenuEntry entry : entries)
    {
        final MenuItem item = new MenuItem(entry.getName());

        final Image icon = entry.getIcon();
        if (icon != null)
            item.setGraphic(new ImageView(icon));
        item.setOnAction(e ->
        {
            try
            {
                entry.call(SelectionService.getInstance().getSelection());
            }
            catch (Exception ex)
            {
                logger.log(Level.WARNING, "Cannot invoke context menu", ex);
            }
        });
        menu.getItems().add(item);
    }

    return true;
}