Example usage for javax.swing JMenuItem setActionCommand

List of usage examples for javax.swing JMenuItem setActionCommand

Introduction

In this page you can find the example usage for javax.swing JMenuItem setActionCommand.

Prototype

public void setActionCommand(String actionCommand) 

Source Link

Document

Sets the action command for this button.

Usage

From source file:org.orbisgis.sif.components.fstree.TreeNodeFolder.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    if (menu.getComponentCount() > 0) {
        menu.addSeparator();/*from  w  w  w . j a v a 2 s.com*/
    }
    // Open the folder
    JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path"));
    copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard"));
    copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath");
    copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu);
    // Read the file system to update the tree
    JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), SifIcon.getIcon("refresh"));
    updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system"));
    updateMenu.setActionCommand("Update");
    updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu);
    // Add a new Sub Folder
    JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), SifIcon.getIcon("folder_add"));
    newSubFolder.setToolTipText(I18N.tr("Create a sub-folder"));
    newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder");
    newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder);
    // Remove the folder
    //The root folder cannot be removed
    if (parent instanceof TreeNodeFolder) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), SifIcon.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the folder"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true);
    }
}

From source file:org.orbisgis.view.components.fstree.TreeNodeFolder.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    if (menu.getComponentCount() > 0) {
        menu.addSeparator();/*  ww  w.j  a v a2s  .  c o  m*/
    }
    // Open the folder
    JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path"));
    copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard"));
    copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath");
    copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu);
    // Read the file system to update the tree
    JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), OrbisGISIcon.getIcon("arrow_refresh"));
    updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system"));
    updateMenu.setActionCommand("Update");
    updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu);
    // Add a new Sub Folder
    JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), OrbisGISIcon.getIcon("folder_add"));
    newSubFolder.setToolTipText(I18N.tr("Create a sub-folder"));
    newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder");
    newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder"));
    MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder);
    // Remove the folder
    //The root folder cannot be removed
    if (parent instanceof TreeNodeFolder) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), OrbisGISIcon.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the folder"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true);
    }
}

From source file:org.orbisgis.view.map.mapsManager.TreeLeafMapContextFile.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    super.feedPopupMenu(menu);
    if (!isLoaded()) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), OrbisGISIcon.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the map"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFile"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove);
    }//from  w  w  w . ja  v  a 2 s.  c  o  m
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

void createUI() {
    photoTransferHandler = new PhotoCollectionTransferHandler(this);
    setTransferHandler(photoTransferHandler);

    setAutoscrolls(true);/*from www .  j  a  v  a 2  s.co  m*/

    addMouseListener(this);
    addMouseMotionListener(this);

    // Create the popup menu
    popup = new JPopupMenu();
    ImageIcon propsIcon = getIcon("view_properties.png");
    editSelectionPropsAction = new EditSelectionPropsAction(this, "Properties...", propsIcon,
            "Edit properties of the selected photos", KeyEvent.VK_P);
    JMenuItem propsItem = new JMenuItem(editSelectionPropsAction);
    ImageIcon colorsIcon = getIcon("colors.png");
    editSelectionColorsAction = new EditSelectionColorsAction(this, null, "Adjust colors...", colorsIcon,
            "Adjust colors of the selected photos", KeyEvent.VK_A);
    JMenuItem colorsItem = new JMenuItem(editSelectionColorsAction);
    ImageIcon showIcon = getIcon("show_new_window.png");
    showSelectedPhotoAction = new ShowSelectedPhotoAction(this, "Show image", showIcon,
            "Show the selected phot(s)", KeyEvent.VK_S);
    JMenuItem showItem = new JMenuItem(showSelectedPhotoAction);
    showHistoryAction = new ShowPhotoHistoryAction(this, "Show history", null, "Show history of selected photo",
            KeyEvent.VK_H, null);
    resolveConflictsAction = new ResolvePhotoConflictsAction(this, "Resolve conflicts", null,
            "Resolve synchronization conflicts", KeyEvent.VK_R, null);
    JMenuItem rotateCW = new JMenuItem(ctrl.getActionAdapter("rotate_cw"));
    JMenuItem rotateCCW = new JMenuItem(ctrl.getActionAdapter("rotate_ccw"));
    JMenuItem rotate180deg = new JMenuItem(ctrl.getActionAdapter("rotate_180"));

    JMenuItem addToFolder = new JMenuItem("Add to folder...");
    addToFolder.addActionListener(this);
    addToFolder.setActionCommand(PHOTO_ADD_TO_FOLDER_CMD);
    addToFolder.setIcon(getIcon("empty_icon.png"));
    ImageIcon exportIcon = getIcon("filesave.png");
    exportSelectedAction = new ExportSelectedAction(this, "Export selected...", exportIcon,
            "Export the selected photos to from archive database to image files", KeyEvent.VK_E);
    JMenuItem exportSelected = new JMenuItem(exportSelectedAction);

    ImageIcon deleteSelectedIcon = getIcon("delete_image.png");
    deleteSelectedAction = new DeletePhotoAction(this, "Delete", deleteSelectedIcon,
            "Delete selected photos including all of their instances", KeyEvent.VK_D);
    JMenuItem deleteSelected = new JMenuItem(deleteSelectedAction);

    starIcon = getIcon("star_normal_border.png");
    rejectedIcon = getIcon("quality_unusable.png");

    rawIcon = getIcon("raw_icon.png");

    JMenuItem showHistory = new JMenuItem(showHistoryAction);
    JMenuItem resolveConflicts = new JMenuItem(resolveConflictsAction);
    AddTagAction addTagAction = new AddTagAction(ctrl, "Add tag...", null, "Add tag to image", KeyEvent.VK_T);
    JMenuItem addTag = new JMenuItem(addTagAction);
    popup.add(showItem);
    popup.add(propsItem);
    popup.add(colorsItem);
    popup.add(rotateCW);
    popup.add(rotateCCW);
    popup.add(rotate180deg);
    popup.add(addToFolder);
    popup.add(exportSelected);
    popup.add(deleteSelected);
    popup.add(showHistory);
    popup.add(resolveConflicts);
    popup.add(addTag);
    MouseListener popupListener = new PopupListener();
    addMouseListener(popupListener);

    ImageIcon selectNextIcon = getIcon("next.png");
    selectNextAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_FWD, "Next photo",
            selectNextIcon, "Move to next photo", KeyEvent.VK_N,
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    ImageIcon selectPrevIcon = getIcon("previous.png");
    selectPrevAction = new ChangeSelectionAction(this, ChangeSelectionAction.MOVE_BACK, "Previous photo",
            selectPrevIcon, "Move to previous photo", KeyEvent.VK_P,
            KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    creatingThumbIcon = getIcon("creating_thumb.png");
}

From source file:processing.app.Base.java

private boolean addSketchesSubmenu(JMenu menu, String name, File folder) {

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String path = e.getActionCommand();
            File file = new File(path);
            if (file.exists()) {
                try {
                    handleOpen(file);//from www . ja  v  a  2  s . com
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            } else {
                showWarning(tr("Sketch Does Not Exist"),
                        tr("The selected sketch no longer exists.\n"
                                + "You may need to restart Arduino to update\n" + "the sketchbook menu."),
                        null);
            }
        }
    };

    File entry = new File(folder, name + ".ino");
    if (!entry.exists() && (new File(folder, name + ".pde")).exists())
        entry = new File(folder, name + ".pde");

    // if a .pde file of the same prefix as the folder exists..
    if (entry.exists()) {

        if (!BaseNoGui.isSanitaryName(name)) {
            if (!builtOnce) {
                String complaining = I18n.format(
                        tr("The sketch \"{0}\" cannot be used.\n"
                                + "Sketch names must contain only basic letters and numbers\n"
                                + "(ASCII-only with no spaces, " + "and it cannot start with a number).\n"
                                + "To get rid of this message, remove the sketch from\n" + "{1}"),
                        name, entry.getAbsolutePath());
                showMessage(tr("Ignoring sketch with bad name"), complaining);
            }
            return false;
        }

        JMenuItem item = new JMenuItem(name);
        item.addActionListener(listener);
        item.setActionCommand(entry.getAbsolutePath());
        menu.add(item);
        return true;
    }

    // don't create an extra menu level for a folder named "examples"
    if (folder.getName().equals("examples"))
        return addSketches(menu, folder);

    // not a sketch folder, but maybe a subfolder containing sketches
    JMenu submenu = new JMenu(name);
    boolean found = addSketches(submenu, folder);
    if (found) {
        menu.add(submenu);
        MenuScroller.setScrollerFor(submenu);
    }
    return found;
}

From source file:processing.app.Editor.java

protected void configurePopupMenu(final SketchTextArea textarea) {

    JPopupMenu menu = textarea.getPopupMenu();

    menu.addSeparator();//from  w  w w  . j av  a 2  s  .c o m

    JMenuItem item = createToolMenuItem("cc.arduino.packages.formatter.AStyle");
    item.setName("menuToolsAutoFormat");

    menu.add(item);

    item = newJMenuItem(_("Comment/Uncomment"), '/');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleCommentUncomment();
        }
    });
    menu.add(item);

    item = newJMenuItem(_("Increase Indent"), ']');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(true);
        }
    });
    menu.add(item);

    item = newJMenuItem(_("Decrease Indent"), '[');
    item.setName("menuDecreaseIndent");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(false);
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Copy for Forum"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleDiscourseCopy();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Copy as HTML"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleHTMLCopy();
        }
    });
    menu.add(item);

    final JMenuItem referenceItem = new JMenuItem(_("Find in Reference"));
    referenceItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleFindReference();
        }
    });
    menu.add(referenceItem);

    final JMenuItem openURLItem = new JMenuItem(_("Open URL"));
    openURLItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openURL(e.getActionCommand());
        }
    });
    menu.add(openURLItem);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword());
            referenceItem.setEnabled(referenceFile != null);

            int offset = textarea.getCaretPosition();
            org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset);
            if (token != null && token.isHyperlink()) {
                openURLItem.setEnabled(true);
                openURLItem.setActionCommand(token.getLexeme());
            } else {
                openURLItem.setEnabled(false);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

}

From source file:processing.app.EditorTab.java

private void configurePopupMenu(final SketchTextArea textarea) {

    JPopupMenu menu = textarea.getPopupMenu();

    menu.addSeparator();//from w  w w  . j  a  v  a 2 s .c om

    JMenuItem item = editor.createToolMenuItem("cc.arduino.packages.formatter.AStyle");
    if (item == null) {
        throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable");
    }
    item.setName("menuToolsAutoFormat");

    menu.add(item);

    item = new JMenuItem(tr("Comment/Uncomment"), '/');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleCommentUncomment();
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Increase Indent"), ']');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(true);
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Decrease Indent"), '[');
    item.setName("menuDecreaseIndent");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(false);
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Copy for Forum"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleDiscourseCopy();
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Copy as HTML"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleHTMLCopy();
        }
    });
    menu.add(item);

    final JMenuItem referenceItem = new JMenuItem(tr("Find in Reference"));
    referenceItem.addActionListener(editor::handleFindReference);
    menu.add(referenceItem);

    final JMenuItem openURLItem = new JMenuItem(tr("Open URL"));
    openURLItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openURL(e.getActionCommand());
        }
    });
    menu.add(openURLItem);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            String referenceFile = editor.base.getPdeKeywords().getReference(getCurrentKeyword());
            referenceItem.setEnabled(referenceFile != null);

            int offset = textarea.getCaretPosition();
            org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset);
            if (token != null && token.isHyperlink()) {
                openURLItem.setEnabled(true);
                openURLItem.setActionCommand(token.getLexeme());
            } else {
                openURLItem.setEnabled(false);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryAuthoringTreePanel.java

/**
 * Creates the popup menus.//from  w ww .  j  a  va 2 s. co  m
 */
private void createPopupMenus() {

    queryActionsMenu = new JPopupMenu("Query Actions");
    JMenuItem orMenuItem = new JMenuItem("ANY of the following");
    orMenuItem.setActionCommand("Add OR");
    orMenuItem.addActionListener(this);

    JMenuItem andMenuItem = new JMenuItem("ALL of the following");
    andMenuItem.setActionCommand("Add And");
    andMenuItem.addActionListener(this);
    // add submenu to group logical relationships
    JMenu logicalSubMenu = new JMenu("Add Logical query");
    logicalSubMenu.add(andMenuItem);
    logicalSubMenu.add(orMenuItem);

    JMenuItem afterMenuItem = new JMenuItem("After");
    afterMenuItem.setActionCommand("After");
    afterMenuItem.addActionListener(this);
    JMenuItem beforeMenuItem = new JMenuItem("Before");
    beforeMenuItem.setActionCommand("Before");
    beforeMenuItem.addActionListener(this);
    // add submenu to group temporal relationships
    JMenu temporalSubMenu = new JMenu("Add Temporal query");
    temporalSubMenu.add(beforeMenuItem);
    temporalSubMenu.add(afterMenuItem);

    JMenuItem addCriterionMenuItem = new JMenuItem("Add Query criterion");
    addCriterionMenuItem.setActionCommand("Add Query criterion");
    addCriterionMenuItem.addActionListener(this);

    JMenuItem removeMenuItem1 = new JMenuItem("Remove criterion");
    removeMenuItem1.setActionCommand("Remove Expression");
    removeMenuItem1.addActionListener(this);

    queryActionsMenu.add(logicalSubMenu);
    queryActionsMenu.add(temporalSubMenu);
    queryActionsMenu.add(addCriterionMenuItem);
    queryActionsMenu.add(removeMenuItem1);

    queryActionsMenu.add(new AbstractAction("Toggle execution") {

        public void actionPerformed(ActionEvent arg0) {

            // get currently selected expression and toggle run time status between SKIP and EXECUTE
            QueryExpression.QueryRunTimeStatus status = selectedExpression.getRunTimeStatus();
            if (status == QueryExpression.QueryRunTimeStatus.EXECUTE) {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.SKIP);
            } else {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.EXECUTE);
            }
            // hide queryActionsMenu
            queryActionsMenu.setVisible(false);
            // revalidate tree
            queryInterfaceTree.revalidate();
        }
    });

    toggleStatusMenu = new JPopupMenu();
    JMenuItem removeMenuItem2 = new JMenuItem("Remove criterion");
    removeMenuItem2.setActionCommand("Remove Expression");
    removeMenuItem2.addActionListener(this);
    toggleStatusMenu.add(removeMenuItem2);
    toggleStatusMenu.add(new AbstractAction("Toggle execution") {

        public void actionPerformed(ActionEvent arg0) {

            // get currently selected expresion and toggle run time status between SKIP and EXECUTE
            QueryExpression.QueryRunTimeStatus status = selectedExpression.getRunTimeStatus();
            if (status == QueryExpression.QueryRunTimeStatus.EXECUTE) {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.SKIP);
            } else {
                selectedExpression.setRunTimeStatus(QueryExpression.QueryRunTimeStatus.EXECUTE);
            }

            // hide toggleStatusMenu
            toggleStatusMenu.setVisible(false);
            // revalidate tree
            queryInterfaceTree.revalidate();
            // notify listeners
            queryService.queryChanged(activeQuery, QueryAuthoringTreePanel.this);
        }
    });
}