Example usage for javax.swing JMenu setAction

List of usage examples for javax.swing JMenu setAction

Introduction

In this page you can find the example usage for javax.swing JMenu setAction.

Prototype

@BeanProperty(visualUpdate = true, description = "the Action instance connected with this ActionEvent source")
public void setAction(Action a) 

Source Link

Document

Sets the Action.

Usage

From source file:Main.java

/**
 * Creates a {@link JMenu} from the given list and action map.
 * //from   w  w w.j av a 2  s . c o m
 * @param actionMap
 * @param list
 * @return
 */
public static JMenu createMenu(ActionMap actionMap, List<?> list) {
    // The first item will be the action for the JMenu
    final Action titleAction = actionMap.get(list.get(0));
    if (titleAction == null) {
        return null;
    }
    final JMenu menu = new JMenu();
    menu.setAction(titleAction);

    // The rest of the items represent the menu items.
    for (Object element : list.subList(1, list.size())) {
        if (element == null) {
            menu.addSeparator();
        } else if (element instanceof List<?>) {
            JMenu newMenu = createMenu(actionMap, (List<?>) element);
            if (newMenu != null) {
                menu.add(newMenu);
            }
        } else if (element.getClass().isArray()) {
            JMenu newMenu = createMenu(actionMap, (Object[]) element);
            if (newMenu != null) {
                menu.add(newMenu);
            }
        } else {
            final Action action = actionMap.get(element);
            if (action == null) {
                continue;
            } else {
                menu.add(createMenuItem(action));
            }
        }
    }
    return menu;
}

From source file:org.datavyu.views.DatavyuView.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.//from w w  w  . j a  va2 s.  com
 */
// <editor-fold defaultstate="collapsed"
// <editor-fold defaultstate="collapsed"
// <editor-fold defaultstate="collapsed"
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    mainPanel = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    menuBar = new javax.swing.JMenuBar();
    javax.swing.JMenu fileMenu = new javax.swing.JMenu();
    newMenuItem = new javax.swing.JMenuItem();
    openMenuItem = new javax.swing.JMenuItem();
    openRecentFileMenu = new javax.swing.JMenu();
    jMenuItem2 = new javax.swing.JMenuItem();
    jSeparator7 = new javax.swing.JSeparator();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exportMenuItem = new javax.swing.JMenuItem();
    javax.swing.JSeparator fileMenuSeparator = new javax.swing.JSeparator();
    javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
    spreadsheetMenu = new javax.swing.JMenu();
    showSpreadsheetMenuItem = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JSeparator();
    jMenuItem1 = new javax.swing.JMenuItem();
    newVariableMenuItem = new javax.swing.JMenuItem();
    vocabEditorMenuItem = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JSeparator();
    newCellMenuItem = new javax.swing.JMenuItem();
    newCellLeftMenuItem = new javax.swing.JMenuItem();
    newCellRightMenuItem = new javax.swing.JMenuItem();
    jSeparator8 = new javax.swing.JPopupMenu.Separator();
    changeVarNameMenuItem = new javax.swing.JMenuItem();
    hideSelectedColumnsMenuItem = new javax.swing.JMenuItem();
    ShowAllVariablesMenuItem = new javax.swing.JMenuItem();
    jSeparator3 = new javax.swing.JSeparator();
    deleteColumnMenuItem = new javax.swing.JMenuItem();
    deleteCellMenuItem = new javax.swing.JMenuItem();
    jSeparator6 = new javax.swing.JSeparator();
    historySpreadSheetMenuItem = new javax.swing.JMenuItem();
    undoSpreadSheetMenuItem = new javax.swing.JMenuItem();
    redoSpreadSheetMenuItem = new javax.swing.JMenuItem();
    jSeparator9 = new javax.swing.JPopupMenu.Separator();
    weakTemporalOrderMenuItem = new javax.swing.JCheckBoxMenuItem();
    strongTemporalOrderMenuItem = new javax.swing.JCheckBoxMenuItem();
    zoomMenu = new javax.swing.JMenu();
    zoomInMenuItem = new javax.swing.JMenuItem();
    zoomOutMenuItem = new javax.swing.JMenuItem();
    jSeparator5 = new javax.swing.JSeparator();
    resetZoomMenuItem = new javax.swing.JMenuItem();
    jSeparator10 = new javax.swing.JPopupMenu.Separator();
    pushMenuItem = new javax.swing.JMenuItem();
    pullMenuItem = new javax.swing.JMenuItem();
    controllerMenu = new javax.swing.JMenu();
    qtControllerItem = new javax.swing.JMenuItem();
    videoConverterMenuItem = new javax.swing.JMenuItem();
    scriptMenu = new javax.swing.JMenu();
    runScriptMenuItem = new javax.swing.JMenuItem();
    runRecentScriptMenu = new javax.swing.JMenu();
    recentScriptsHeader = new javax.swing.JMenuItem();
    jSeparator4 = new javax.swing.JSeparator();
    favScripts = new javax.swing.JMenuItem();
    windowMenu = new javax.swing.JMenu();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();
    updateMenuItem = new javax.swing.JMenuItem();
    supportMenuItem = new javax.swing.JMenuItem();
    guideMenuItem = new javax.swing.JMenuItem();

    mainPanel.setName("mainPanel"); // NOI18N

    jLabel1.setName("jLabel1"); // NOI18N

    org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
    mainPanel.setLayout(mainPanelLayout);
    mainPanelLayout
            .setHorizontalGroup(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mainPanelLayout.createSequentialGroup().add(119, 119, 119).add(jLabel1)
                            .addContainerGap(149, Short.MAX_VALUE)));
    mainPanelLayout
            .setVerticalGroup(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mainPanelLayout.createSequentialGroup().add(55, 55, 55).add(jLabel1)
                            .addContainerGap(184, Short.MAX_VALUE)));
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
            .getInstance(org.datavyu.Datavyu.class).getContext().getResourceMap(DatavyuView.class);
    resourceMap.injectComponents(mainPanel);

    menuBar.setName("menuBar"); // NOI18N

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application
            .getInstance(org.datavyu.Datavyu.class).getContext().getActionMap(DatavyuView.class, this);
    fileMenu.setAction(actionMap.get("saveAs")); // NOI18N
    fileMenu.setName("fileMenu"); // NOI18N

    newMenuItem.setAction(actionMap.get("showNewProjectForm")); // NOI18N
    java.util.ResourceBundle bundle = java.util.ResourceBundle
            .getBundle("org/datavyu/views/resources/DatavyuView"); // NOI18N
    newMenuItem.setText(bundle.getString("file_new.text")); // NOI18N
    newMenuItem.setName("newMenuItem"); // NOI18N
    fileMenu.add(newMenuItem);

    openMenuItem.setAction(actionMap.get("open")); // NOI18N
    openMenuItem.setText(bundle.getString("file_open.text")); // NOI18N
    openMenuItem.setName(bundle.getString("file_open.text")); // NOI18N
    fileMenu.add(openMenuItem);

    openRecentFileMenu.setName("openRecentFileMenu"); // NOI18N
    openRecentFileMenu.addMenuListener(new javax.swing.event.MenuListener() {
        public void menuSelected(javax.swing.event.MenuEvent evt) {
            openRecentFileMenuMenuSelected(evt);
        }

        public void menuDeselected(javax.swing.event.MenuEvent evt) {
        }

        public void menuCanceled(javax.swing.event.MenuEvent evt) {
        }
    });

    jMenuItem2.setEnabled(false);
    jMenuItem2.setName("jMenuItem2"); // NOI18N
    openRecentFileMenu.add(jMenuItem2);

    fileMenu.add(openRecentFileMenu);

    jSeparator7.setName("jSeparator7"); // NOI18N
    fileMenu.add(jSeparator7);

    saveMenuItem.setAction(actionMap.get("save")); // NOI18N
    saveMenuItem.setName("saveMenuItem"); // NOI18N
    fileMenu.add(saveMenuItem);

    saveAsMenuItem.setAction(actionMap.get("saveAs")); // NOI18N
    saveAsMenuItem.setName("saveAsMenuItem"); // NOI18N
    fileMenu.add(saveAsMenuItem);

    exportMenuItem.setAction(actionMap.get("exportFile")); // NOI18N
    exportMenuItem.setName("exportMenuItem"); // NOI18N
    fileMenu.add(exportMenuItem);

    fileMenuSeparator.setName("fileMenuSeparator"); // NOI18N
    if (Datavyu.getPlatform() != Platform.MAC) {
        fileMenu.add(fileMenuSeparator);
    }

    exitMenuItem.setAction(actionMap.get("safeQuit")); // NOI18N
    exitMenuItem.setName("exitMenuItem"); // NOI18N
    if (Datavyu.getPlatform() != Platform.MAC) {
        fileMenu.add(exitMenuItem);
    }

    menuBar.add(fileMenu);

    spreadsheetMenu.setAction(actionMap.get("showQTVideoController")); // NOI18N
    spreadsheetMenu.setName("spreadsheetMenu"); // NOI18N
    spreadsheetMenu.addMenuListener(new javax.swing.event.MenuListener() {
        public void menuSelected(javax.swing.event.MenuEvent evt) {
            //                spreadsheetMenuSelected(evt);
        }

        public void menuDeselected(javax.swing.event.MenuEvent evt) {
        }

        public void menuCanceled(javax.swing.event.MenuEvent evt) {
        }
    });

    showSpreadsheetMenuItem.setAction(actionMap.get("showSpreadsheet")); // NOI18N
    showSpreadsheetMenuItem.setName("showSpreadsheetMenuItem"); // NOI18N
    spreadsheetMenu.add(showSpreadsheetMenuItem);

    jSeparator1.setName("jSeparator1"); // NOI18N
    spreadsheetMenu.add(jSeparator1);

    jMenuItem1.setAction(actionMap.get("showNewVariableForm")); // NOI18N
    jMenuItem1.setName("jMenuItem1"); // NOI18N
    spreadsheetMenu.add(jMenuItem1);

    newVariableMenuItem.setAction(actionMap.get("showVariableList")); // NOI18N
    newVariableMenuItem.setName("newVariableMenuItem"); // NOI18N
    spreadsheetMenu.add(newVariableMenuItem);

    vocabEditorMenuItem.setAction(actionMap.get("showVocabEditor")); // NOI18N
    vocabEditorMenuItem.setName("vocabEditorMenuItem"); // NOI18N
    spreadsheetMenu.add(vocabEditorMenuItem);

    jSeparator2.setName("jSeparator2"); // NOI18N
    spreadsheetMenu.add(jSeparator2);

    newCellMenuItem.setName("newCellMenuItem"); // NOI18N
    newCellMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            newCellMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(newCellMenuItem);

    newCellLeftMenuItem.setName("newCellLeftMenuItem"); // NOI18N
    newCellLeftMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            newCellLeftMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(newCellLeftMenuItem);

    newCellRightMenuItem.setName("newCellRightMenuItem"); // NOI18N
    newCellRightMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            newCellRightMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(newCellRightMenuItem);

    jSeparator8.setName("jSeparator8"); // NOI18N
    spreadsheetMenu.add(jSeparator8);

    changeVarNameMenuItem.setName("changeVarNameMenuItem"); // NOI18N
    changeVarNameMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            changeVarNameMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(changeVarNameMenuItem);

    hideSelectedColumnsMenuItem.setName("hideSelectedColumnsMenuItem"); // NOI18N
    hideSelectedColumnsMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            hideSelectedColumnsMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(hideSelectedColumnsMenuItem);

    ShowAllVariablesMenuItem.setName("ShowAllVariablesMenuItem"); // NOI18N
    ShowAllVariablesMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            ShowAllVariablesMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(ShowAllVariablesMenuItem);

    jSeparator3.setName("jSeparator3"); // NOI18N
    spreadsheetMenu.add(jSeparator3);

    deleteColumnMenuItem.setAction(actionMap.get("deleteColumn")); // NOI18N
    deleteColumnMenuItem.setName("deleteColumnMenuItem"); // NOI18N
    spreadsheetMenu.add(deleteColumnMenuItem);

    deleteCellMenuItem.setAction(actionMap.get("deleteCells")); // NOI18N
    deleteCellMenuItem.setName("deleteCellMenuItem"); // NOI18N
    spreadsheetMenu.add(deleteCellMenuItem);

    jSeparator6.setName("jSeparator6"); // NOI18N
    spreadsheetMenu.add(jSeparator6);

    historySpreadSheetMenuItem.setAction(actionMap.get("history")); // NOI18N
    historySpreadSheetMenuItem.setName("historySpreadSheetMenuItem"); // NOI18N
    spreadsheetMenu.add(historySpreadSheetMenuItem);

    undoSpreadSheetMenuItem.setAction(actionMap.get("undo")); // NOI18N
    undoSpreadSheetMenuItem.setName("undoSpreadSheetMenuItem"); // NOI18N
    spreadsheetMenu.add(undoSpreadSheetMenuItem);

    redoSpreadSheetMenuItem.setAction(actionMap.get("redo")); // NOI18N
    redoSpreadSheetMenuItem.setName("redoSpreadSheetMenuItem"); // NOI18N
    spreadsheetMenu.add(redoSpreadSheetMenuItem);

    jSeparator9.setName("jSeparator9"); // NOI18N
    spreadsheetMenu.add(jSeparator9);

    weakTemporalOrderMenuItem.setName("weakTemporalOrderMenuItem"); // NOI18N
    weakTemporalOrderMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            weakTemporalMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(weakTemporalOrderMenuItem);

    strongTemporalOrderMenuItem.setName("strongTemporalOrderMenuItem"); // NOI18N
    strongTemporalOrderMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            strongTemporalMenuItemActionPerformed(evt);
        }
    });
    spreadsheetMenu.add(strongTemporalOrderMenuItem);

    zoomMenu.setName("zoomMenu"); // NOI18N

    zoomInMenuItem.setName("zoomInMenuItem"); // NOI18N
    zoomInMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            zoomInMenuItemActionPerformed(evt);
        }
    });
    zoomMenu.add(zoomInMenuItem);

    zoomOutMenuItem.setName("zoomOutMenuItem"); // NOI18N
    zoomOutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            zoomOutMenuItemActionPerformed(evt);
        }
    });
    zoomMenu.add(zoomOutMenuItem);

    jSeparator5.setName("jSeparator5"); // NOI18N
    zoomMenu.add(jSeparator5);

    resetZoomMenuItem.setName("resetZoomMenuItem"); // NOI18N
    resetZoomMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            resetZoomMenuItemActionPerformed(evt);
        }
    });
    zoomMenu.add(resetZoomMenuItem);

    spreadsheetMenu.add(zoomMenu);

    jSeparator10.setName("jSeparator10"); // NOI18N
    spreadsheetMenu.add(jSeparator10);

    pushMenuItem.setAction(actionMap.get("push")); // NOI18N
    pushMenuItem.setName("pushMenuItem"); // NOI18N
    spreadsheetMenu.add(pushMenuItem);

    pullMenuItem.setAction(actionMap.get("pull")); // NOI18N
    pullMenuItem.setName("pullMenuItem"); // NOI18N
    spreadsheetMenu.add(pullMenuItem);

    menuBar.add(spreadsheetMenu);

    controllerMenu.setName("controllerMenu"); // NOI18N

    qtControllerItem.setAction(actionMap.get("showQTVideoController")); // NOI18N
    qtControllerItem.setName("qtControllerItem"); // NOI18N
    controllerMenu.add(qtControllerItem);

    videoConverterMenuItem.setAction(actionMap.get("showVideoConverter")); // NOI18N
    videoConverterMenuItem.setName("videoConverterMenuItem"); // NOI18N
    controllerMenu.add(videoConverterMenuItem);

    menuBar.add(controllerMenu);

    scriptMenu.setName("scriptMenu"); // NOI18N
    scriptMenu.addMenuListener(new javax.swing.event.MenuListener() {
        public void menuSelected(javax.swing.event.MenuEvent evt) {
            populateFavourites(evt);
        }

        public void menuDeselected(javax.swing.event.MenuEvent evt) {
        }

        public void menuCanceled(javax.swing.event.MenuEvent evt) {
        }
    });

    runScriptMenuItem.setAction(actionMap.get("runScript")); // NOI18N
    runScriptMenuItem.setName("runScriptMenuItem"); // NOI18N
    scriptMenu.add(runScriptMenuItem);

    runRecentScriptMenu.setName("runRecentScriptMenu"); // NOI18N
    runRecentScriptMenu.addMenuListener(new javax.swing.event.MenuListener() {
        public void menuSelected(javax.swing.event.MenuEvent evt) {
            populateRecentScripts(evt);
        }

        public void menuDeselected(javax.swing.event.MenuEvent evt) {
        }

        public void menuCanceled(javax.swing.event.MenuEvent evt) {
        }
    });

    recentScriptsHeader.setEnabled(false);
    recentScriptsHeader.setName("recentScriptsHeader"); // NOI18N
    runRecentScriptMenu.add(recentScriptsHeader);

    scriptMenu.add(runRecentScriptMenu);

    jSeparator4.setName("jSeparator4"); // NOI18N
    scriptMenu.add(jSeparator4);

    favScripts.setEnabled(false);
    favScripts.setName("favScripts"); // NOI18N
    scriptMenu.add(favScripts);

    menuBar.add(scriptMenu);

    windowMenu.setName("windowMenu"); // NOI18N

    menuBar.add(windowMenu);

    helpMenu.setAction(actionMap.get("showVariableList")); // NOI18N
    helpMenu.setName("helpMenu"); // NOI18N

    aboutMenuItem.setAction(actionMap.get("showAboutWindow")); // NOI18N
    aboutMenuItem.setName("aboutMenuItem"); // NOI18N
    if (Datavyu.getPlatform() != Platform.MAC) {
        helpMenu.add(aboutMenuItem);
    }

    supportMenuItem.setAction(actionMap.get("openSupportSite"));
    supportMenuItem.setName("supportMenuItem");
    //TODO - don't add this on Macs.  Instead it will be in the "Application Menu"
    //if (Datavyu.getPlatform() != Platform.MAC) {
    helpMenu.add(supportMenuItem);
    //}

    guideMenuItem.setAction(actionMap.get("openGuideSite"));
    guideMenuItem.setName("guideMenuItem");
    //TODO - don't add this on Macs.  Instead it will be in the "Application Menu"
    //if (Datavyu.getPlatform() != Platform.MAC) {
    helpMenu.add(guideMenuItem);
    //}

    updateMenuItem.setAction(actionMap.get("showUpdateWindow")); // NOI18N
    updateMenuItem.setName("updateMenuItem"); // NOI18N
    //TODO - don't add this on Macs.  Instead it will be in the "Application Menu"
    //if (Datavyu.getPlatform() != Platform.MAC) {
    helpMenu.add(updateMenuItem);
    //}

    menuBar.add(helpMenu);
    resourceMap.injectComponents(menuBar);

    setMenuBar(menuBar);
}