List of usage examples for javax.swing JMenuItem setAction
@BeanProperty(visualUpdate = true, description = "the Action instance connected with this ActionEvent source") public void setAction(Action a)
Action
. From source file:fedroot.dacs.swingdemo.DacsSingleFrameApplication.java
private JMenu createMenu(String menuName, String[] actionNames) { JMenu menu = new JMenu(); menu.setName(menuName);//w ww .j a va 2s. c o m for (String actionName : actionNames) { JMenuItem menuItem = new JMenuItem(); menuItem.setAction(actionMap().get(actionName)); menu.add(menuItem); } return menu; }
From source file:cz.lidinsky.editor.Menu.java
protected JMenuItem loadMenuItem(Properties settings, String key) { try {/*from w ww .ja v a 2 s . c o m*/ String temp = settings.getProperty(key + "_menu_items"); JMenuItem menuItem; if (temp != null) { JMenu menu = new JMenu(); String menuItems[] = temp.split(" "); for (String item : menuItems) { if (item.equals("|")) { menu.add(new JSeparator()); } else { menu.add(loadMenuItem(settings, item)); } } menuItem = menu; } else { menuItem = new JMenuItem(); } // set the menu item label setLabel(menuItem, settings.getProperty(key + "_menu_label")); // action String actionKey = settings.getProperty(key + "_menu_action"); if (actionKey != null) { menuItem.setAction(Action.getAction(settings, actionKey)); } return menuItem; } catch (Exception e) { // TODO: throw new AssertionError(); } }
From source file:it.unibas.spicygui.widget.operators.ConnectionInfoCreator.java
public void createConfidenceLabel(JMenuItem itemConfidence, JCheckBoxMenuItem itemCheckImplied, BindingGroup bindingGroup, ConnectionInfo connectionInfo, ConnectionWidget connection) { // binding//www . j a va 2s .co m Binding bindingImplied = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, connectionInfo.getValueCorrespondence(), ELProperty.create("${implied}"), itemCheckImplied, BeanProperty.create("selected")); Binding bindingConfidence = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, connectionInfo, ELProperty.create("${confidence}"), itemConfidence, BeanProperty.create("text")); bindingGroup.addBinding(bindingConfidence); bindingGroup.addBinding(bindingImplied); //action itemCheckImplied.setAction(new ActionSetImplied(connectionInfo)); itemConfidence.setAction(new MyEditProviderConfidence(connection, connectionInfo)); }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private void buildFileMenu(JMenu mnuFile) { mnuFile.removeAll();/*from w w w . ja v a 2 s.c o m*/ String[] fileMenuActions = { "newFile", "loadFile", "closeFile", "-", "saveFile", "saveAsFile", "-", "importDirectives", "exportDirectives" }; MenuBuilder.buildMenu(mnuFile, fileMenuActions, _actionMap); mnuFile.addSeparator(); String[] previous = EditorPreferences.getPreviouslyUsedFiles(); if (previous != null && previous.length > 0) { javax.swing.Action a = this._actionMap.get("loadPreviousFile"); if (a != null) { for (int i = 0; i < previous.length; ++i) { String filename = previous[i]; JMenuItem item = new JMenuItem(); item.setAction(a); item.setText(String.format("%d %s", i + 1, filename)); item.putClientProperty("Filename", filename); item.setMnemonic(KeyEvent.VK_1 + i); mnuFile.add(item); } } } if (!isMac()) { mnuFile.addSeparator(); JMenuItem mnuItFileExit = new JMenuItem(); mnuItFileExit.setAction(_actionMap.get("exitApplication")); mnuFile.add(mnuItFileExit); } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private JMenuBar buildMenus() { JMenuBar menuBar = new JMenuBar(); // File menu. This on is kind of special, in that it gets rebuilt each // time a file is opened. _fileMenu = new JMenu(); _fileMenu.setName("mnuFile"); buildFileMenu(_fileMenu);/*from w ww . j ava 2s . com*/ menuBar.add(_fileMenu); // Edit Menu JMenu mnuEdit = buildEditMenu(); menuBar.add(mnuEdit); // Search Menu JMenu mnuSearch = buildSearchMenu(); menuBar.add(mnuSearch); // View Menu JMenu mnuView = buildViewMenu(); menuBar.add(mnuView); // Window menu _windowMenu = new JMenu(); _windowMenu.setName("mnuWindow"); buildWindowMenu(_windowMenu); menuBar.add(_windowMenu); JMenu mnuHelp = new JMenu(); mnuHelp.setName("mnuHelp"); JMenuItem mnuItHelpContents = new JMenuItem(); mnuItHelpContents.setName("mnuItHelpContents"); mnuHelp.add(mnuItHelpContents); mnuItHelpContents.addActionListener(_helpController.helpAction()); JMenuItem mnuItHelpOnSelection = new JMenuItem(IconHelper.createImageIcon("help_cursor.png")); mnuItHelpOnSelection.setName("mnuItHelpOnSelection"); mnuItHelpOnSelection.addActionListener(_helpController.helpOnSelectionAction()); mnuHelp.add(mnuItHelpOnSelection); javax.swing.Action openAboutAction = _actionMap.get("openAbout"); if (isMac()) { configureMacAboutBox(openAboutAction); } else { JMenuItem mnuItAbout = new JMenuItem(); mnuItAbout.setAction(openAboutAction); mnuHelp.addSeparator(); mnuHelp.add(mnuItAbout); } menuBar.add(mnuHelp); return menuBar; }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private void buildWindowMenu(JMenu mnuWindow) { mnuWindow.removeAll();/*from w w w .j av a 2 s . c om*/ JMenuItem mnuItCascade = new JMenuItem(); mnuItCascade.setAction(_actionMap.get("cascadeFrames")); mnuWindow.add(mnuItCascade); JMenuItem mnuItTile = new JMenuItem(); mnuItTile.setAction(_actionMap.get("tileFrames")); mnuWindow.add(mnuItTile); JMenuItem mnuItTileHorz = new JMenuItem(); mnuItTileHorz.setAction(_actionMap.get("tileFramesHorizontally")); mnuWindow.add(mnuItTileHorz); JMenuItem mnuItArrangeIcons = new JMenuItem(); mnuItArrangeIcons.setAction(_actionMap.get("arrangeIcons")); mnuWindow.add(mnuItArrangeIcons); JMenuItem mnuItCloseAll = new JMenuItem(); mnuItCloseAll.setAction(_actionMap.get("closeAllFrames")); mnuWindow.add(mnuItCloseAll); mnuWindow.addSeparator(); JMenuItem mnuItChooseFont = new JMenuItem(); mnuItChooseFont.setAction(_actionMap.get("chooseFont")); mnuWindow.add(mnuItChooseFont); mnuWindow.addSeparator(); JMenu mnuLF = new JMenu(); mnuLF.setName("mnuLF"); mnuLF.setText(_resourceMap.getString("mnuLF.text")); mnuWindow.add(mnuLF); JMenuItem mnuItMetalLF = new JMenuItem(); mnuItMetalLF.setAction(_actionMap.get("metalLookAndFeel")); mnuLF.add(mnuItMetalLF); JMenuItem mnuItWindowsLF = new JMenuItem(); mnuItWindowsLF.setAction(_actionMap.get("systemLookAndFeel")); mnuLF.add(mnuItWindowsLF); try { // Nimbus L&F was added in update java 6 update 10. Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel").newInstance(); JMenuItem mnuItNimbusLF = new JMenuItem(); mnuItNimbusLF.setAction(_actionMap.get("nimbusLookAndFeel")); mnuLF.add(mnuItNimbusLF); } catch (Exception e) { // The Nimbus L&F is not available, no matter. } mnuWindow.addSeparator(); int i = 1; for (final JInternalFrame frame : _frames) { JMenuItem windowItem = new JCheckBoxMenuItem(); if (i < 10) { windowItem.setText(String.format("%d %s", i, frame.getTitle())); windowItem.setMnemonic(KeyEvent.VK_1 + (i - 1)); } else { windowItem.setText(frame.getTitle()); } windowItem.setSelected(frame.isSelected()); windowItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { frame.setSelected(true); } catch (PropertyVetoException e1) { } } }); mnuWindow.add(windowItem); ++i; } }
From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java
public BdbAdminClient(HttpClient httpClient, JFrame window, File configPath, ProxyFactory proxyFactory) { this.httpClient = httpClient; this.ancestor = window; this.configPath = configPath; this.proxyFactory = proxyFactory; try {//from w w w. ja v a 2s. c om configJaxbContext = JAXBContext.newInstance(ServiceConfig.class); } catch (JAXBException ex) { throw new RuntimeException(ex); } JMenuItem newServiceItem = new JMenuItem("New Service"); newServiceItem.setAction(new NewServiceAction()); JMenu fileMenu = new JMenu("File"); fileMenu.add(newServiceItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); window.setJMenuBar(menuBar); window.setIconImage(new ImageIcon(this.getClass().getClassLoader().getResource("service.gif")).getImage()); this.root = new DefaultMutableTreeNode(); this.model = new DefaultTreeModel(root); getTree().setModel(model); getTree().setShowsRootHandles(true); getTree().setRootVisible(false); getTree().setCellRenderer(new Renderer()); getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); getTree().getSelectionModel().addTreeSelectionListener(new SelectionListener()); getTree().addMouseListener(new ContextMenuHandler()); addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { loadConfig(); } public void ancestorMoved(AncestorEvent event) { } public void ancestorRemoved(AncestorEvent event) { } }); }
From source file:com.pingtel.sipviewer.SIPViewerFrame.java
protected void initMenu() { JMenu menu;//from w ww . j a v a 2s. c o m JMenu submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; // Create the menu bar. JMenuBar menuBar = new JMenuBar(); this.setJMenuBar(menuBar); // Build the File menu. menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); // Add the load-file items to the File menu. menuItem = new JMenuItem(); menuItem.setAction(new icOpenFileAction()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.ALT_MASK)); menuItem.setMnemonic(KeyEvent.VK_F); menu.add(menuItem); menuItem = new JMenuItem(); menuItem.setAction(new icImportSyslogAction()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.ALT_MASK)); menuItem.setMnemonic(KeyEvent.VK_Y); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(); menuItem.setAction(new icSaveAsAction()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK)); menuItem.setMnemonic(KeyEvent.VK_S); menu.add(menuItem); menu.addSeparator(); // Add the reload item to the File menu. menuItem = new JMenuItem(); menuItem.setAction(new icReloadAction()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK)); menuItem.setMnemonic(KeyEvent.VK_R); menu.add(menuItem); menu.addSeparator(); // Add the quit item to the File menu. menuItem = new JMenuItem(); menuItem.setAction(new icQuitAction()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setMnemonic(KeyEvent.VK_Q); menu.add(menuItem); // Build the Options menu. menu = new JMenu("Options"); menu.setMnemonic(KeyEvent.VK_O); menuBar.add(menu); // Add the split/single screen mode to the options menu menuItem = new JMenuItem(); menuItem.setAction(new icScreenModeAction()); menuItem.setMnemonic(KeyEvent.VK_M); menu.add(menuItem); menu.addSeparator(); // Add the show all dialogs option to the options menu menuItem = new JMenuItem(); menuItem.setAction(new icShowAllDialogsAction()); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); menu.addSeparator(); // Add the Time Zone Selection Time submenu submenu = new JMenu("Time Zone Setting"); submenu.setMnemonic(KeyEvent.VK_Z); ButtonGroup timeZoneGroup = new ButtonGroup(); // Set Time Zone to Local Time Zone m_localTimeZone = new JRadioButtonMenuItem(); m_localTimeZone.setAction(new icSetTimeToLocalZone()); m_localTimeZone.setMnemonic(KeyEvent.VK_L); timeZoneGroup.add(m_localTimeZone); m_localTimeZone.setSelected(true); submenu.add(m_localTimeZone); // Set Time Zone to UTC Time Zone m_utcTimeZone = new JRadioButtonMenuItem(); m_utcTimeZone.setAction(new icSetTimeToUTCZone()); m_utcTimeZone.setMnemonic(KeyEvent.VK_U); timeZoneGroup.add(m_utcTimeZone); submenu.add(m_utcTimeZone); menu.add(submenu); // Add the show/hide time index column menuItem = new JMenuItem(); menuItem.setAction(new icTimeVisibilityAction()); menuItem.setMnemonic(KeyEvent.VK_V); menu.add(menuItem); // Add the Time Display Format submenu submenu = new JMenu("Time Display Format"); submenu.setMnemonic(KeyEvent.VK_T); ButtonGroup group = new ButtonGroup(); m_dateAndTimeFormat = new JRadioButtonMenuItem(); m_dateAndTimeFormat.setAction(new icDateAndTimeAction()); m_dateAndTimeFormat.setMnemonic(KeyEvent.VK_I); group.add(m_dateAndTimeFormat); submenu.add(m_dateAndTimeFormat); m_defaultTimeFormat = new JRadioButtonMenuItem(); m_defaultTimeFormat.setAction(new icTimeOfDay()); m_defaultTimeFormat.setMnemonic(KeyEvent.VK_E); m_defaultTimeFormat.setSelected(true); group.add(m_defaultTimeFormat); submenu.add(m_defaultTimeFormat); m_sincePreviousFormat = new JRadioButtonMenuItem(); m_sincePreviousFormat.setAction(new icSincePrevious()); m_sincePreviousFormat.setMnemonic(KeyEvent.VK_P); group.add(m_sincePreviousFormat); submenu.add(m_sincePreviousFormat); m_sinceBeginningFormat = new JRadioButtonMenuItem(); m_sinceBeginningFormat.setAction(new icSinceBeginning()); m_sinceBeginningFormat.setMnemonic(KeyEvent.VK_B); group.add(m_sinceBeginningFormat); submenu.add(m_sinceBeginningFormat); m_sinceKeyIndexFormat = new JRadioButtonMenuItem(); m_sinceKeyIndexFormat.setAction(new icSinceKeyIndex()); m_sinceKeyIndexFormat.setMnemonic(KeyEvent.VK_K); group.add(m_sinceKeyIndexFormat); submenu.add(m_sinceKeyIndexFormat); menu.add(submenu); // Build the Help menu. menu = new JMenu("Help"); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); // Add the items to the File menu. menuItem = new JMenuItem(); menuItem.setAction(new icAboutAction()); menu.add(menuItem); }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
private void createMenuItemsForTaxonomyElements(JMenuItem parentMenuItem, Collection<?> taxonomyElements) throws JAXRException { Iterator<?> iter = taxonomyElements.iterator(); while (iter.hasNext()) { Object taxonomyElementObj = iter.next(); Collection<?> children = null; if (taxonomyElementObj instanceof ClassificationScheme) { children = ((ClassificationScheme) taxonomyElementObj).getChildrenConcepts(); } else if (taxonomyElementObj instanceof Concept) { children = ((Concept) taxonomyElementObj).getChildrenConcepts(); } else {/*from w w w . java 2 s.c o m*/ throw new JAXRException(CommonResourceBundle.getInstance() .getString("message.unexpectedObjectType", new String[] { taxonomyElementObj.getClass().toString(), "javax.xml.registry.infomodel.ClassificationScheme, javax.xml.registry.infomodel.ClassificationScheme" })); } String childName = ((RegistryObjectImpl) taxonomyElementObj).getDisplayName(); JMenuItem childMenuItem = null; //Need to handle intermediate nodes different from terminal nodes //Intermediate nodes: have a JMenu and JMenuItem children where first child represents themself //Leaf nodes: have a JMenuItem that represents themself if (children.size() > 0) { //Intermediate node childMenuItem = new JMenu(childName); //Add a first child that represents the intermediate node itself JMenuItem firstGrandChildMenuItem = new TaxonomyElementMenuItem( ((RegistryObjectImpl) taxonomyElementObj)); Action action = new SetStatusAction(((RegistryObjectImpl) taxonomyElementObj)); firstGrandChildMenuItem.setAction(action); childMenuItem.add(firstGrandChildMenuItem); //Now add a separator JSeparator separator = new JSeparator(); childMenuItem.add(separator); createMenuItemsForTaxonomyElements(childMenuItem, children); } else { //Leaf node childMenuItem = new TaxonomyElementMenuItem(((RegistryObjectImpl) taxonomyElementObj)); Action action = new SetStatusAction(((RegistryObjectImpl) taxonomyElementObj)); childMenuItem.setAction(action); } parentMenuItem.add(childMenuItem); } }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Build the re-execute menu// w ww. java 2s .c o m * * @param actionMap * The action map for the main GUI window * @return The JMenu for the re-execute menu */ private JMenu buildReExecuteMenu(ActionMap actionMap) { JMenu mnuReExecute = new JMenu(); mnuReExecute.setName("mnuReExecute"); JMenuItem mnuItReExecute = new JMenuItem(); mnuItReExecute.setAction(actionMap.get("mnuItReExecute")); mnuReExecute.add(mnuItReExecute); return mnuReExecute; }