List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java
private JMenu createMenuFileExport() { final JMenu menuExport = new JMenu("Export as"); final JMenuItem asImageItem = new JMenuItem("Image"); asImageItem.addActionListener(new ActionListener() { @Override//from w ww. j ava 2s . c o m public void actionPerformed(final ActionEvent e) { exportAsImage(); } }); menuExport.add(asImageItem); return menuExport; }
From source file:gdt.jgui.entity.bookmark.JBookmarksEditor.java
/** * Get context menu.//www. j a va 2s .c o m * @return the context menu. */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); mia = null; int cnt = menu.getItemCount(); if (cnt > 0) { mia = new JMenuItem[cnt]; for (int i = 0; i < cnt; i++) mia[i] = menu.getItem(i); } menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("BookmarksEditor:getConextMenu:menu selected"); menu.removeAll(); if (mia != null) { for (JMenuItem mi : mia) menu.add(mi); } if (hasSelectedItems()) { menu.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(); } }); menu.add(copyItem); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { String[] sa = JBookmarksEditor.this.listSelectedItems(); if (sa == null) return; String bookmarkKey$; Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); for (String aSa : sa) { bookmarkKey$ = Locator.getProperty(aSa, BOOKMARK_KEY); if (bookmarkKey$ == null) continue; entity.removeElementItem("jbookmark", bookmarkKey$); } entigrator.save(entity); JConsoleHandler.execute(console, getLocator()); } } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(deleteItem); } if (hasToPaste()) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { paste(); } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:edu.ku.brc.specify.tasks.PluginsTask.java
@Override public List<MenuItemDesc> getMenuItems() { String menuDesc = "Specify.SYSTEM_MENU"; menuItems = new Vector<MenuItemDesc>(); if (permissions == null || permissions.canModify()) { String menuTitle = "PluginsTask.PLUGIN_MENU"; //$NON-NLS-1$ String mneu = "PluginsTask.PLUGIN_MNEU"; //$NON-NLS-1$ String desc = "PluginsTask.PLUGIN_DESC"; //$NON-NLS-1$ JMenuItem mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override//w w w . ja v a 2 s.c o m public void actionPerformed(ActionEvent ae) { PluginsTask.this.requestContext(); } }); MenuItemDesc rsMI = new MenuItemDesc(mi, menuDesc); rsMI.setPosition(MenuItemDesc.Position.After); rsMI.setSepPosition(MenuItemDesc.Position.Before); menuItems.add(rsMI); } return menuItems; }
From source file:jhplot.HPlotChart.java
/** * Create canvas that keeps JFreeChart panel. * /*from w ww .ja va 2 s. c om*/ * @param jchart * chart of JFreeChart. * @param xsize * size in x direction * @param ysize * size in y direction */ public HPlotChart(JFreeChart jchart, int xsize, int ysize) { this.xsize = xsize; this.ysize = ysize; frame = new JFrame("HPloatChart"); chart = jchart; cp = new ChartPanel(chart); cp.setPreferredSize(new Dimension(xsize, ysize)); cp.setBackground(DEFAULT_BG_COLOR); cp.setLayout(new BorderLayout()); cp.setDomainZoomable(true); cp.setRangeZoomable(true); chart.setAntiAlias(true); chart.setBorderPaint(DEFAULT_BG_COLOR); chart.setBackgroundPaint(DEFAULT_BG_COLOR); chart.setBorderVisible(false); org.jfree.chart.plot.Plot pp = (org.jfree.chart.plot.Plot) chart.getPlot(); pp.setBackgroundPaint(DEFAULT_BG_COLOR); setTheme("LEGACY_THEME"); frame.add(cp); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem item1 = new JMenuItem("Export"); item1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportDialog(); } }); JMenuItem item2 = new JMenuItem("Close"); item2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { close(); } }); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); menu.add(item1); menu.add(item2); bar.add(menu); frame.setJMenuBar(bar); frame.setPreferredSize(new Dimension(xsize, ysize)); }
From source file:com.clank.launcher.dialog.LauncherFrame.java
/** * Popup the menu for the instances.//from w w w.j a v a 2s. c o m * * @param component the component * @param x mouse X * @param y mouse Y * @param selected the selected instance, possibly null */ private void popupInstanceMenu(Component component, int x, int y, final Instance selected) { JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem; if (selected != null) { menuItem = new JMenuItem(!selected.isLocal() ? "Install" : "Launch"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { launch(); } }); popup.add(menuItem); if (selected.isLocal()) { popup.addSeparator(); menuItem = new JMenuItem(_("instance.openFolder")); menuItem.addActionListener( ActionListeners.browseDir(LauncherFrame.this, selected.getContentDir(), true)); popup.add(menuItem); menuItem = new JMenuItem(_("instance.openSaves")); menuItem.addActionListener(ActionListeners.browseDir(LauncherFrame.this, new File(selected.getContentDir(), "saves"), true)); popup.add(menuItem); menuItem = new JMenuItem(_("instance.openResourcePacks")); menuItem.addActionListener(ActionListeners.browseDir(LauncherFrame.this, new File(selected.getContentDir(), "resourcepacks"), true)); popup.add(menuItem); menuItem = new JMenuItem(_("instance.openScreenshots")); menuItem.addActionListener(ActionListeners.browseDir(LauncherFrame.this, new File(selected.getContentDir(), "screenshots"), true)); popup.add(menuItem); menuItem = new JMenuItem(_("instance.copyAsPath")); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File dir = selected.getContentDir(); dir.mkdirs(); SwingHelper.setClipboard(dir.getAbsolutePath()); } }); popup.add(menuItem); popup.addSeparator(); if (!selected.isUpdatePending()) { menuItem = new JMenuItem(_("instance.forceUpdate")); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selected.setUpdatePending(true); launch(); instancesModel.update(); } }); popup.add(menuItem); } menuItem = new JMenuItem(_("instance.hardForceUpdate")); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmHardUpdate(selected); } }); popup.add(menuItem); menuItem = new JMenuItem(_("instance.deleteFiles")); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmDelete(selected); } }); popup.add(menuItem); } popup.addSeparator(); } menuItem = new JMenuItem(_("launcher.refreshList")); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadInstances(); } }); popup.add(menuItem); popup.show(component, x, y); }
From source file:gdt.jgui.entity.JEntitiesPanel.java
/** * Get context menu.// www . java2s . co m * @return the context menu. * */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); mia = null; int cnt = menu.getItemCount(); if (cnt > 0) { mia = new JMenuItem[cnt]; for (int i = 0; i < cnt; i++) mia[i] = menu.getItem(i); } menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { menu.removeAll(); if (mia != null) for (JMenuItem mi : mia) try { if (mi != null) menu.add(mi); } catch (Exception ee) { System.out.println("JEntitiesPanel:getConextMenu:" + ee.toString()); } Properties locator = Locator.toProperties(locator$); if (locator.getProperty(EntityHandler.ENTITY_CONTAINER) != null) { if (JEntityPrimaryMenu.hasToPaste(console, locator$)) { pasteItem = new JMenuItem("Paste components"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pasteComponents(); } }); menu.add(pasteItem); } if (hasSelectedItems()) { if (containerKey$ != null) { removeComponentsItem = new JMenuItem("Remove components"); removeComponentsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeComponents(); } }); menu.add(removeComponentsItem); } } } if (locator.getProperty(EntityHandler.ENTITY_COMPONENT) != null) { if (componentKey$ != null) { removeContainersItem = new JMenuItem("Remove containers"); removeContainersItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeContainers(); } }); menu.add(removeContainersItem); } } if (hasSelectedItems()) { menu.addSeparator(); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); ArrayList<String> sl = new ArrayList<String>(); for (JItemPanel ip : ipa) if (ip.isChecked()) sl.add(ip.getLocator()); String[] sa = sl.toArray(new String[0]); console.clipboard.clear(); for (String aSa : sa) console.clipboard.putString(aSa); } }); menu.add(copyItem); reindexItem = new JMenuItem("Reindex"); reindexItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); for (JItemPanel ip : ipa) if (ip.isChecked()) { JEntityPrimaryMenu.reindexEntity(console, ip.getLocator()); } } }); menu.add(reindexItem); archiveItem = new JMenuItem("Archive"); archiveItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); Entigrator entigrator = console.getEntigrator(entihome$); Properties locator; ArrayList<String> sl = new ArrayList<String>(); String entityKey$; for (JItemPanel ip : ipa) { if (ip.isChecked()) { locator = Locator.toProperties(ip.getLocator()); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); sl.add(entityKey$); } } String[] sa = sl.toArray(new String[0]); System.out.println("JEntitiesPanel:archive:1"); String[] ea = JReferenceEntry.getCoalition(console, entigrator, sa); if (ea == null) System.out.println("JEntitiesPanel:archive:ea null"); else System.out.println("JEntitiesPanel:archive:ea=" + ea.length); JArchivePanel archivePanel = new JArchivePanel(); String apLocator$ = archivePanel.getLocator(); //locator$=getLocator(); apLocator$ = Locator.append(apLocator$, Entigrator.ENTIHOME, entihome$); apLocator$ = Locator.append(apLocator$, EntityHandler.ENTITY_LIST, Locator.toString(ea)); String icon$ = Support.readHandlerIcon(null, JEntityPrimaryMenu.class, "archive.png"); apLocator$ = Locator.append(apLocator$, Locator.LOCATOR_ICON, icon$); JConsoleHandler.execute(console, apLocator$); } }); menu.add(archiveItem); menu.addSeparator(); deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); Entigrator entigrator = console.getEntigrator(entihome$); String iLocator$; Properties iLocator; String iEntityKey$; String iEntityLabel$; Sack iEntity; ArrayList<String> sl = new ArrayList<String>(); for (JItemPanel ip : ipa) { iLocator$ = ip.getLocator(); iLocator = Locator.toProperties(iLocator$); iEntityLabel$ = iLocator.getProperty(EntityHandler.ENTITY_LABEL); if (ip.isChecked()) { iEntityKey$ = iLocator.getProperty(EntityHandler.ENTITY_KEY); iEntity = entigrator.getEntityAtKey(iEntityKey$); if (iEntity != null) entigrator.deleteEntity(iEntity); } else { sl.add(iEntityLabel$); } } String[] sa = sl.toArray(new String[0]); if (sa != null && sa.length > 0) { String sa$ = Locator.toString(sa); locator$ = Locator.append(locator$, EntityHandler.ENTITY_LIST, sa$); } JConsoleHandler.execute(console, locator$); } } }); menu.add(deleteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); menu.addSeparator(); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); return menu; }
From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java
private JToolBar createDefinitionToolbar() { final JButton openButton = new JButton(Theme.ICON_OPEN); openButton.setToolTipText(Messages.getString("Toolbar.open")); //$NON-NLS-1$ openButton.addActionListener(new ActionListener() { @Override// w w w . j a va 2 s. co m public void actionPerformed(final ActionEvent event) { openFile(); } }); definitionToolbar.add(openButton); final JPopupMenu importMenu = new JPopupMenu(Messages.getString("Toolbar.import")); //$NON-NLS-1$ final JMenuItem importBonitaItem = new JMenuItem("Bonita"); importBonitaItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { importBonita(); } }); importMenu.add(importBonitaItem); final JButton importButton = new JButton(Theme.ICON_IMPORT); importButton.setToolTipText(Messages.getString("Toolbar.import")); //$NON-NLS-1$ importButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { importMenu.show(importButton, 0, importButton.getHeight()); } }); definitionToolbar.add(importButton); return definitionToolbar; }
From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderConnectionChainComposition.java
private void createPopupMenu() { menu = new JPopupMenu("Popup menu"); JMenuItem item; // item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.SHOW_HIDE_INFO_CONNECTION)); // item.setActionCommand(SHOW); // item.addActionListener(this); // menu.add(item); // itemConfidence = new JMenuItem(); // menu.add(itemConfidence); ////from w ww .jav a2s . c o m // itemImplied = new JCheckBoxMenuItem(); // menu.add(itemImplied); item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION)); item.setActionCommand(DELETE); item.addActionListener(this); menu.add(item); }
From source file:org.angnysa.yaba.swing.BudgetFrame.java
private void buildMenubar() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu(Messages.getString("menu.file.label")); //$NON-NLS-1$ JMenuItem item; // new// w w w . ja v a 2s. c om item = new JMenuItem(Messages.getString("menu.file.new")); //$NON-NLS-1$ item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingMain.newEditor(null); } }); fileMenu.add(item); // open item = new JMenuItem(Messages.getString("menu.file.open")); //$NON-NLS-1$ item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingMain.open(id); } }); fileMenu.add(item); // save item = new JMenuItem(Messages.getString("menu.file.save")); //$NON-NLS-1$ item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingMain.save(id); } }); fileMenu.add(item); // save as item = new JMenuItem(Messages.getString("menu.file.save-as")); //$NON-NLS-1$ item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingMain.saveas(id); } }); fileMenu.add(item); // close item = new JMenuItem(Messages.getString("menu.file.close")); //$NON-NLS-1$ item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingMain.close(id); } }); fileMenu.add(item); menuBar.add(fileMenu); setJMenuBar(menuBar); }