List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java
@SuppressWarnings("serial") private JMenuBar createMenu() { JMenuBar menuBar = new JMenuBar(); // the file menu JMenu fileMenu = new JMenu("File"); fileMenu.add(this.saveGraphImageAction); menuBar.add(fileMenu);/*w w w . j a v a2 s . c o m*/ // the tools menu JMenu toolsMenu = new JMenu("Tools"); JMenuItem configureGraphItem = new JMenuItem("Configure Graph..."); configureGraphItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ResidualPlotPanel.this.chartConfigurationDialog.setVisible(true); } }); toolsMenu.add(configureGraphItem); toolsMenu.addSeparator(); toolsMenu.add(new AbstractAction("Zoom Out") { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ResidualPlotPanel.this.autoRangeChart(); } }); toolsMenu.addSeparator(); JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point"); showTooltipCheckbox.setSelected(true); this.showTooltip = true; showTooltipCheckbox.addItemListener(new ItemListener() { /** * {@inheritDoc} */ public void itemStateChanged(ItemEvent e) { ResidualPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED; ResidualPlotPanel.this.clearProbePopup(); } }); toolsMenu.add(showTooltipCheckbox); menuBar.add(toolsMenu); // the help menu JMenu helpMenu = new JMenu("Help"); JMenuItem helpMenuItem = new JMenuItem("Help...", new ImageIcon(ResidualPlotAction.class.getResource("/images/action/help-16x16.png"))); helpMenuItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { Maanova.getInstance().showHelp("residual-plot", ResidualPlotPanel.this); } }); helpMenu.add(helpMenuItem); menuBar.add(helpMenu); return menuBar; }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displayAddPopup(JButton src) { JPopupMenu p = new JPopupMenu(); Map<String, List<Series<?>>> series = sampler.getCategories(); for (Map.Entry<String, List<Series<?>>> e1 : series.entrySet()) { JMenu sm = new JMenu(e1.getKey()); for (final Series<?> s : e1.getValue()) { if (!enabled.contains(s.getKey())) { JMenuItem mi = new JMenuItem(s.getLabel()); mi.addActionListener(new ActionListener() { @Override// ww w .ja v a 2 s . c o m public void actionPerformed(ActionEvent e) { enable(s); } }); sm.add(mi); } } p.add(sm); } p.show(src, 4, 4); }
From source file:org.jax.maanova.madata.gui.ArrayScatterPlotPanel.java
@SuppressWarnings("serial") private JMenuBar createMenu() { JMenuBar menuBar = new JMenuBar(); // the file menu JMenu fileMenu = new JMenu("File"); fileMenu.add(this.saveGraphImageAction); menuBar.add(fileMenu);/*from w ww .jav a2 s . c o m*/ // the tools menu JMenu toolsMenu = new JMenu("Tools"); JMenuItem configureGraphItem = new JMenuItem("Configure Graph..."); configureGraphItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ArrayScatterPlotPanel.this.chartConfigurationDialog.setVisible(true); } }); toolsMenu.add(configureGraphItem); toolsMenu.addSeparator(); toolsMenu.add(new AbstractAction("Zoom Out") { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ArrayScatterPlotPanel.this.autoRangeChart(); } }); JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point"); showTooltipCheckbox.setSelected(true); this.showTooltip = true; showTooltipCheckbox.addItemListener(new ItemListener() { /** * {@inheritDoc} */ public void itemStateChanged(ItemEvent e) { ArrayScatterPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED; ArrayScatterPlotPanel.this.clearProbePopup(); } }); toolsMenu.add(showTooltipCheckbox); menuBar.add(toolsMenu); // the help menu JMenu helpMenu = new JMenu("Help"); JMenuItem helpMenuItem = new JMenuItem("Help..."); Icon helpIcon = new ImageIcon(ArrayScatterPlotPanel.class.getResource("/images/action/help-16x16.png")); helpMenuItem.setIcon(helpIcon); helpMenuItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { Maanova.getInstance().showHelp("array-scatter-plot", ArrayScatterPlotPanel.this); } }); helpMenu.add(helpMenuItem); menuBar.add(helpMenu); return menuBar; }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displaySeriesPopup(final JFreeChart chart, final String label, final int series, final ColorButton button) { JPopupMenu p = new JPopupMenu(); JMenuItem color = new JMenuItem("Color..."); p.add(color);// w w w . j a v a2 s . c o m color.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayColorPicker(chart, label, series, button); } }); JMenuItem remove = new JMenuItem("Remove"); p.add(remove); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeSeries(chart, series); } }); p.show(button, 4, 4); }
From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java
/** * Add the default menu items//from w w w. ja va 2s . c om * * @param items List of menu items * * @return The items list */ @Override protected List getPopupMenuItems(List items) { items = super.getPopupMenuItems(items); for (Object o : items) { if (o instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) o; if ("Properties...".equals(menuItem.getText())) { menuItem.setActionCommand(ChartPanel.PROPERTIES_COMMAND); menuItem.addActionListener(buildHistoPropsListener()); } } } return items; }
From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java
/** * Get the popup menu for the child node of the facet node * in the digest view.// w w w .jav a 2 s .c o m * @return the popup menu. */ @Override public JPopupMenu getPopupMenu(final String digestLocator$) { JPopupMenu popup = new JPopupMenu(); try { Properties locator = Locator.toProperties(digestLocator$); final String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION); byte[] ba = Base64.decodeBase64(encodedSelection$); final String selection$ = new String(ba, "UTF-8"); // System.out.println("JFolderFacetOpenItem:getPopupMenu:selection:="+selection$); locator = Locator.toProperties(selection$); String nodeType$ = locator.getProperty(JEntityDigestDisplay.NODE_TYPE); if (JEntityDigestDisplay.NODE_TYPE_FACET_OWNER.equals(nodeType$)) { JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); File file = new File(entihome$ + "/" + entityKey$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); JMenuItem editItem = new JMenuItem("Edit"); popup.add(editItem); editItem.setHorizontalTextPosition(JMenuItem.RIGHT); editItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); JFolderPanel fp = new JFolderPanel(); String fpLocator$ = fp.getLocator(); fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$); fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, fpLocator$); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); } if (NODE_TYPE_FILE_NODE.equals(nodeType$)) { JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File file = new File(filePath$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); final File file = new File(filePath$); if (isTextFile(file)) { JMenuItem editItem = new JMenuItem("Edit"); popup.add(editItem); editItem.setHorizontalTextPosition(JMenuItem.RIGHT); editItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { InputStream is = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { bos.write(b, 0, bytesRead); } byte[] ba = bos.toByteArray(); is.close(); String text$ = new String(ba, "UTF-8"); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$); locator$ = Locator.append(locator$, JRequester.REQUESTER_ACTION, JFolderPanel.ACTION_EDIT_FILE); locator$ = Locator.append(locator$, JFolderPanel.FILE_PATH, file.getPath()); locator$ = Locator.append(locator$, BaseHandler.HANDLER_METHOD, "response"); locator$ = Locator.append(locator$, JEntityDigestDisplay.SELECTION, encodedSelection$); String requesterResponceLocator$ = Locator.compressText(locator$); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, requesterResponceLocator$); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); } } return popup; } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); return null; } }
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
private void createPopupMenus() { JMenuItem algorithmMenu = new JMenuItem("Change algorithm..."); algorithmMenu.addActionListener(new ActionListener() { @Override//w w w. j a va2 s . c om public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.ALGORITHM); } }); popupAlgorithm = new JPopupMenu(); popupAlgorithm.add(algorithmMenu); JMenuItem problemMenu = new JMenuItem("Change problem..."); problemMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.PROBLEM); } }); popupProblem = new JPopupMenu(); popupProblem.add(problemMenu); JMenuItem stopConditionAddMenu = new JMenuItem("Add stop condition..."); stopConditionAddMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.STOP_CONDITIONS); } }); JMenuItem stopConditionRemoveMenu = new JMenuItem("Remove stop condition..."); stopConditionRemoveMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { StopCondition stopCondition = (StopCondition) ((ExtendedTreeNode) tree .getLastSelectedPathComponent()).getUserObject(); algorithm.getStopConditions().remove(stopCondition); createNodes(); } }); popupStopCondition = new JPopupMenu(); popupStopCondition.add(stopConditionAddMenu); popupStopCondition.add(stopConditionRemoveMenu); JMenuItem measurementMenu = new JMenuItem("Add meassurement..."); measurementMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.MEASUREMENTS); } }); JMenuItem measurementRemoveMenu = new JMenuItem("Remove meassurement..."); measurementRemoveMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { Measurement measurement = (Measurement) ((ExtendedTreeNode) tree.getLastSelectedPathComponent()) .getUserObject(); algorithm.getMeasurements().remove(measurement); createNodes(); } }); popupMeassurement = new JPopupMenu(); popupMeassurement.add(measurementMenu); popupMeassurement.add(measurementRemoveMenu); // Add listener to components that can bring up popup menus. MouseListener popupListener = new PopupListener(); tree.addMouseListener(popupListener); }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionMappingTask.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);/*w w w . j av 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:me.philnate.textmanager.windows.MainWindow.java
/** * Initialize the contents of the frame. *//*from w ww. j a v a 2s . c o m*/ private void initialize() { changeListener = new ChangeListener(); frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Starter.shutdown(); } }); frame.setBounds(100, 100, 1197, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new MigLayout("", "[grow]", "[][grow][::16px]")); customers = new CustomerComboBox(); customers.addItemListener(changeListener); frame.getContentPane().add(customers, "flowx,cell 0 0,growx"); jScrollPane = new JScrollPane(); billLines = new BillingItemTable(frame, true); jScrollPane.setViewportView(billLines); frame.getContentPane().add(jScrollPane, "cell 0 1,grow"); // for each file added through drag&drop create a new lineItem new FileDrop(jScrollPane, new FileDrop.Listener() { @Override public void filesDropped(File[] files) { for (File file : files) { addNewBillingItem(Document.loadAndSave(file)); } } }); monthChooser = new JMonthChooser(); monthChooser.addPropertyChangeListener(changeListener); frame.getContentPane().add(monthChooser, "cell 0 0"); yearChooser = new JYearChooser(); yearChooser.addPropertyChangeListener(changeListener); frame.getContentPane().add(yearChooser, "cell 0 0"); JButton btnAddLine = new JButton(); btnAddLine.setIcon(ImageRegistry.getImage("load.gif")); btnAddLine.setToolTipText(getCaption("mw.tooltip.add")); btnAddLine.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addNewBillingItem(); } }); frame.getContentPane().add(btnAddLine, "cell 0 0"); JButton btnMassAdd = new JButton(); btnMassAdd.setIcon(ImageRegistry.getImage("load_all.gif")); btnMassAdd.setToolTipText(getCaption("mw.tooltip.massAdd")); btnMassAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JFileChooser file = new DocXFileChooser(); switch (file.showOpenDialog(frame)) { case JFileChooser.APPROVE_OPTION: File[] files = file.getSelectedFiles(); if (null != files) { for (File fl : files) { addNewBillingItem(Document.loadAndSave(fl)); } } break; default: return; } } }); frame.getContentPane().add(btnMassAdd, "cell 0 0"); billNo = new JTextField(); // enable/disable build button based upon text in billNo billNo.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent arg0) { setButtonStates(); } @Override public void insertUpdate(DocumentEvent arg0) { setButtonStates(); } @Override public void changedUpdate(DocumentEvent arg0) { setButtonStates(); } private void setButtonStates() { boolean notBlank = StringUtils.isNotBlank(billNo.getText()); build.setEnabled(notBlank); view.setEnabled(pdf.find(billNo.getText() + ".pdf").size() == 1); } }); frame.getContentPane().add(billNo, "cell 0 0"); billNo.setColumns(10); build = new JButton(); build.setEnabled(false);// disable build Button until there's some // billNo entered build.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (runningThread == null) { try { // check that billNo isn't empty or already used within // another Bill if (billNo.getText().trim().equals("")) { JOptionPane.showMessageDialog(frame, getCaption("mw.dialog.error.billNoBlank.msg"), getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE); return; } try { bill.setBillNo(billNo.getText()).save(); } catch (DuplicateKey e) { // unset the internal value as this is already used bill.setBillNo(""); JOptionPane.showMessageDialog(frame, format(getCaption("mw.error.billNoUsed.msg"), billNo.getText()), getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE); return; } PDFCreator pdf = new PDFCreator(bill); pdf.addListener(new ThreadCompleteListener() { @Override public void threadCompleted(NotifyingThread notifyingThread) { build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); runningThread = null; view.setEnabled(DB.pdf.find(billNo.getText() + ".pdf").size() == 1); } }); runningThread = new Thread(pdf); runningThread.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } build.setToolTipText(getCaption("mw.tooltip.build.cancel")); build.setIcon(ImageRegistry.getImage("cancel.gif")); } else { runningThread.interrupt(); runningThread = null; build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); } } }); build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); frame.getContentPane().add(build, "cell 0 0"); view = new JButton(); view.setToolTipText(getCaption("mw.tooltip.view")); view.setIcon(ImageRegistry.getImage("view.gif")); view.setEnabled(false); view.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File file = new File(System.getProperty("user.dir"), format("template/%s.tmp.pdf", billNo.getText())); try { pdf.findOne(billNo.getText() + ".pdf").writeTo(file); new ProcessBuilder(Setting.find("pdfViewer").getValue(), file.getAbsolutePath()).start() .waitFor(); file.delete(); } catch (IOException | InterruptedException e1) { // TODO Auto-generated catch block LOG.warn("Error while building PDF", e1); } } }); frame.getContentPane().add(view, "cell 0 0"); statusBar = new JPanel(); statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED)); statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS)); GitRepositoryState state = DB.state; JLabel statusLabel = new JLabel(String.format("textManager Version v%s build %s", state.getCommitIdDescribe(), state.getBuildTime())); statusLabel.setHorizontalAlignment(SwingConstants.LEFT); statusBar.add(statusLabel); frame.add(statusBar, "cell 0 2,growx"); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menu = new JMenu(getCaption("mw.menu.edit")); JMenuItem itemCust = new JMenuItem(getCaption("mw.menu.edit.customer")); itemCust.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new CustomerWindow(customers); } }); menu.add(itemCust); JMenuItem itemSetting = new JMenuItem(getCaption("mw.menu.edit.settings")); itemSetting.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new SettingWindow(); } }); menu.add(itemSetting); JMenuItem itemImport = new JMenuItem(getCaption("mw.menu.edit.import")); itemImport.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new ImportWindow(new ImportListener() { @Override public void entriesImported(List<BillingItem> items) { for (BillingItem item : items) { item.setCustomerId(customers.getSelectedCustomer().getId()) .setMonth(monthChooser.getMonth()).setYear(yearChooser.getYear()); item.save(); billLines.addRow(item); } } }, frame); } }); menu.add(itemImport); menuBar.add(menu); customers.loadCustomer(); fillTableModel(); }
From source file:edu.ku.brc.specify.tasks.CleanupToolsTask.java
@Override public List<MenuItemDesc> getMenuItems() { String menuDesc = "Specify.SYSTEM_MENU"; menuItems = new Vector<MenuItemDesc>(); if (permissions == null || permissions.canModify()) { String menuTitle = "CLNUP.ISOASSIGN_MENU"; //$NON-NLS-1$ String mneu = "CLNUP.ISOASSIGN_MNEU"; //$NON-NLS-1$ String desc = "CLNUP.ISOASSIGN_DESC"; //$NON-NLS-1$ JMenuItem mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override//from w ww . ja v a 2s.c o m public void actionPerformed(ActionEvent ae) { CleanupToolsTask.this.requestContext(); } }); MenuItemDesc rsMI = new MenuItemDesc(mi, menuDesc); rsMI.setPosition(MenuItemDesc.Position.After); rsMI.setSepPosition(MenuItemDesc.Position.Before); menuItems.add(rsMI); } return menuItems; }