List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:net.pandoragames.far.ui.swing.component.FileListPopupMenu.java
private void init(Localizer localizer, ComponentRepository componentRepository) { // Edit// ww w.j a v a2 s.c om edit = new JMenuItem(localizer.localize("label.edit")); edit.setToolTipText(localizer.localize("tooltip.edit")); edit.setMnemonic(config.getAccessKey("popup.label.edit")); edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileEditor editor = new FileEditor(mainFrame, tableModel.getRow(selectedRow), config); editor.pack(); editor.setVisible(true); } }); this.add(edit); // View JMenuItem view = new JMenuItem(viewAction); view.setToolTipText(localizer.localize("tooltip.view")); this.add(view); // Preview JMenuItem preview = new JMenuItem(previewAction); preview.setToolTipText(localizer.localize("tooltip.preview")); this.add(preview); // Info info = new JMenuItem(localizer.localize("label.info")); info.setToolTipText(localizer.localize("tooltip.info")); info.setMnemonic(config.getAccessKey("popup.label.info")); info.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { InfoView infoView = new InfoView(mainFrame, tableModel.getRow(selectedRow), config, repository); infoView.pack(); infoView.setVisible(true); } }); this.add(info); if (SwingConfig.getEffectiveJavaVersion() > 5 && DesktopHelper.isFileOpeningSupported()) { openItemsAreActive = true; // seperator this.addSeparator(); openFile = new JMenuItem(localizer.localize("label.open-file")); openFile.setToolTipText(localizer.localize("tooltip.open-file")); openFile.setMnemonic(config.getAccessKey("popup.label.open-file")); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { DesktopHelper.openFile(tableModel.getRow(selectedRow).getFile()); } catch (IOException iox) { errorSink.error(iox.getMessage()); } } }); this.add(openFile); openDir = new JMenuItem(localizer.localize("label.open-directory")); openDir.setToolTipText(localizer.localize("tooltip.open-directory")); openDir.setMnemonic(config.getAccessKey("popup.label.open-directory")); this.add(openDir); openDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { DesktopHelper.openFile(tableModel.getRow(selectedRow).getFile().getParentFile()); } catch (IOException iox) { errorSink.error(iox.getMessage()); } } }); } // seperator this.addSeparator(); // rename rename = new JMenuItem(localizer.localize("menu.rename-dialog")); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.renameDialog(selectedRow, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(rename); // copy copy = new JMenuItem(localizer.localize("menu.copy")); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = selectedRow; int count = 1; if (fileTable.getSelectedRowCount() > 0) { index = fileTable.getSelectedRow(); count = fileTable.getSelectedRowCount(); } FileOperationDialog.copyDialog(index, count, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(copy); // tree copy treeCopy = new JMenuItem(localizer.localize("menu.treeCopy")); treeCopy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = selectedRow; int count = 1; if (fileTable.getSelectedRowCount() > 0) { index = fileTable.getSelectedRow(); count = fileTable.getSelectedRowCount(); } FileOperationDialog.treeCopyDialog(index, count, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(treeCopy); // move move = new JMenuItem(localizer.localize("menu.move")); move.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = selectedRow; int count = 1; if (fileTable.getSelectedRowCount() > 0) { index = fileTable.getSelectedRow(); count = fileTable.getSelectedRowCount(); } FileOperationDialog.moveDialog(index, count, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(move); // delete delete = new JMenuItem(localizer.localize("menu.delete")); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = selectedRow; int count = 1; if (fileTable.getSelectedRowCount() > 0) { index = fileTable.getSelectedRow(); count = fileTable.getSelectedRowCount(); } FileOperationDialog.deleteDialog(index, count, tableModel, findForm.getBaseDirectory(), errorSink, config, mainFrame); } }); this.add(delete); }
From source file:org.simbrain.plot.piechart.PieChartGui.java
/** * Creates the menu bar./*from ww w. java 2s.c om*/ */ private void createAttachMenuBar() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); JMenu editMenu = new JMenu("Edit"); JMenuItem preferences = new JMenuItem("Preferences..."); preferences.addActionListener(this); preferences.setActionCommand("dialog"); editMenu.add(preferences); JMenu helpMenu = new JMenu("Help"); ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/pie_chart.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderJoinCondition.java
private void createPopupMenu() { bindingGroup = new BindingGroup(); menu = new JPopupMenu("Popup menu"); JMenuItem item1;//from ww w . j a v a 2s. c om JCheckBoxMenuItem item2; JCheckBoxMenuItem item3; JCheckBoxMenuItem item4; item1 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE)); item1.setActionCommand(DELETE); item1.addActionListener(this); item2 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MANDATORY)); Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${mandatory}"), item2, BeanProperty.create("selected")); bindingGroup.addBinding(binding); item2.setActionCommand(TOGGLE_MANDATORY); item2.addActionListener(this); item3 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_FOREIGN)); Binding binding2 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${monodirectional}"), item3, BeanProperty.create("selected")); bindingGroup.addBinding(binding2); item3.setActionCommand(TOGGLE_FOREIGN); item3.addActionListener(this); item4 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MATCH_STRING)); Binding binding3 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${matchString}"), item4, BeanProperty.create("selected")); bindingGroup.addBinding(binding3); item4.setActionCommand(TOGGLE_MATCH_STRING); item4.addActionListener(this); menu.add(item1); menu.add(item2); menu.add(item3); menu.add(item4); bindingGroup.bind(); }
From source file:ActionExampleSwing.java
public ActionExampleSwing() { super("ActionExample Swing"); setChannel(currentChannel); // enable/disable the Actions as appropriate channelLabel.setHorizontalAlignment(JLabel.CENTER); channelLabel.setFont(new Font("Serif", Font.PLAIN, 32)); getContentPane().add(channelLabel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16)); getContentPane().add(buttonPanel, BorderLayout.CENTER); buttonPanel.add(new JButton(upAction)); buttonPanel.add(new JButton(gotoFavoriteAction)); buttonPanel.add(new JButton(downAction)); buttonPanel.add(new JButton(setFavoriteAction)); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("Channel"); menu.add(new JMenuItem(upAction)); menu.add(new JMenuItem(downAction)); menu.addSeparator();/*w w w . j a v a2s. c o m*/ menu.add(new JMenuItem(gotoFavoriteAction)); menu.add(new JMenuItem(setFavoriteAction)); mb.add(menu); setJMenuBar(mb); }
From source file:gdt.jgui.entity.JEntitiesPanel.java
/** * Get context menu.//w ww. j a v a2 s.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) { 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:CutAndPasteDemo.java
public CutAndPasteDemo() { super("Cut And Paste Demonstration"); clipboard = getToolkit().getSystemClipboard(); GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 15); textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25); textArea2 = new JTextArea("<Paste text here>", 5, 25); textArea1.setFont(font);// www . j a va 2 s . c o m textArea2.setFont(font); JPanel jPanel = new JPanel(); JMenuBar jMenuBar = new JMenuBar(); JMenuItem cutItem = new JMenuItem("Cut"); JMenuItem pasteItem = new JMenuItem("Paste"); JMenu jMenu = new JMenu("Edit"); jMenu.add(cutItem); jMenu.add(pasteItem); cutItem.addActionListener(new CutActionListener()); pasteItem.addActionListener(new PasteActionListener()); jMenuBar.add(jMenu); jPanel.add(jMenuBar); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); jPanel.add(textArea1); jPanel.add(Box.createRigidArea(new Dimension(0, 10))); jPanel.add(textArea2); getContentPane().add(jPanel, BorderLayout.CENTER); }
From source file:io.github.jeddict.relation.mapper.widget.table.SecondaryTableWidget.java
@Override protected List<JMenuItem> getPopupMenuItemList() { List<JMenuItem> menuList = super.getPopupMenuItemList(); JMenuItem menuItem = new JMenuItem("Delete Secondary Table"); menuItem.addActionListener((ActionEvent e) -> { Entity entity = this.getBaseElementSpec().getEntity(); entity.getAttributes().getAllAttribute().stream().filter(a -> a instanceof PersistenceBaseAttribute) .filter(a -> StringUtils.equalsIgnoreCase(((PersistenceBaseAttribute) a).getColumn().getTable(), this.getBaseElementSpec().getSecondaryTable().getName())) .forEach(a -> ((PersistenceBaseAttribute) a).getColumn().setTable(null)); entity.removeSecondaryTable(this.getBaseElementSpec().getSecondaryTable()); ModelerFile parentFile = SecondaryTableWidget.this.getModelerScene().getModelerFile().getParentFile(); DBUtil.openDBModeler(parentFile); JeddictLogger.recordDBAction("Delete Secondary Table"); });/* ww w .j a v a2s .c o m*/ menuList.add(0, menuItem); return menuList; }
From source file:io.github.jeddict.relation.mapper.widget.table.BaseTableWidget.java
@Override protected List<JMenuItem> getPopupMenuItemList() { List<JMenuItem> menuList = super.getPopupMenuItemList(); JMenuItem menuItem = new JMenuItem("Create Secondary Table"); menuItem.addActionListener((ActionEvent e) -> { Entity entity = this.getBaseElementSpec().getEntity(); String secondaryTableName = JOptionPane.showInputDialog( (Component) BaseTableWidget.this.getModelerScene().getModelerPanelTopComponent(), "Please enter secondary table name"); if (entity.getTable(secondaryTableName) == null) { //check from complete table list SecondaryTable secondaryTable = new SecondaryTable(); secondaryTable.setName(secondaryTableName); entity.addSecondaryTable(secondaryTable); ModelerFile parentFile = BaseTableWidget.this.getModelerScene().getModelerFile().getParentFile(); DBUtil.openDBModeler(parentFile); JeddictLogger.recordDBAction("Create Secondary Table"); } else {/*w w w . j a v a 2s . c o m*/ JOptionPane.showMessageDialog( (Component) BaseTableWidget.this.getModelerScene().getModelerPanelTopComponent(), "Table already exist"); } }); menuList.add(0, menuItem); return menuList; }
From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java
/** * creates a new ChartPanel inside this UI * //from w ww.j a v a2 s . co m * @param categoryDataset * the Data * @param questionText * the questiontext to display above * @param background * background color * @param showAnswers * highlight correct answer in green? * @param correctAnswer * index of correct answer * @param showPercent * should it show percent values or absolute values? */ public void createNewChartPanel(CategoryDataset categoryDataset, String questionText, Color background, boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) { JFreeChart chart = createChart(categoryDataset, questionText, background, showAnswers, correctAnswers, showPercent); ChartPanel chartPanel = new ChartPanel(chart); setNewChartPanel(chartPanel); String menuItemText = Localize .getString(showPercent ? "label.jfreechart.switch.absolute" : "label.jfreechart.switch.percent"); JMenuItem menuItem = new JMenuItem(menuItemText); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(menuItem); menuItem.addActionListener(_menuItemActionListener); }
From source file:gdt.jgui.entity.bookmark.JBookmarksEditor.java
/** * Get context menu.// w w w . j av a2 s . c om * @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; }