List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates file menu with save/exit options * * @return file menu/*from ww w . ja v a 2s . c om*/ */ private JMenu createFileMenu() { JMenu menu = new JMenu("File"); // file menu JMenuItem item = new JMenuItem("Exit"); item.addActionListener(e -> System.exit(0)); menu.add(item); return menu; }
From source file:gdt.jgui.entity.bookmark.JBookmarksFacetOpenItem.java
/** * Get the popup menu for the child node of the facet node * in the digest view.//from w ww . j av a 2 s. c om * @return the popup menu. */ @Override public JPopupMenu getPopupMenu(final String digestLocator$) { JPopupMenu popup = new JPopupMenu(); JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JBookmarkFacetOpenItem:open:digest locator="+digestLocator$); Properties locator = Locator.toProperties(digestLocator$); String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION); byte[] ba = Base64.decodeBase64(encodedSelection$); String selection$ = new String(ba, "UTF-8"); // System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$); locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String type$ = locator.getProperty(Locator.LOCATOR_TYPE); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(type$)) { String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File file = new File(filePath$); Desktop.getDesktop().open(file); return; } if (JEntityDigestDisplay.LOCATOR_FACET_COMPONENT.equals(type$)) { String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); JBookmarksEditor be = new JBookmarksEditor(); String beLocator$ = be.getLocator(); beLocator$ = Locator.append(beLocator$, Entigrator.ENTIHOME, entihome$); beLocator$ = Locator.append(beLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, beLocator$); return; } String bookmarkKey$ = locator.getProperty(JBookmarksEditor.BOOKMARK_KEY); Entigrator entigrator = console.getEntigrator(entihome$); String componentKey$ = locator.getProperty(JEntityDigestDisplay.COMPONENT_KEY); Sack entity = entigrator.getEntityAtKey(componentKey$); Core bookmark = entity.getElementItem("jbookmark", bookmarkKey$); // System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$); JConsoleHandler.execute(console, bookmark.value); } catch (Exception ee) { Logger.getLogger(JBookmarksFacetOpenItem.class.getName()).info(ee.toString()); } } }); return popup; }
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. *//*from w w w. j av a 2s . com*/ private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }
From source file:com.qawaa.gui.EventWebScanGUI.java
/** * ??// w w w .j a v a 2s . c om */ private static void setConsoleRight() { consoleRight = new JPopupMenu(); consoleRight.setBorderPainted(true); consoleRight.setPopupSize(new Dimension(105, 135)); JMenuItem clear = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.clear", null, Locale.CHINA), KeyEvent.VK_L); JMenuItem copy = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.copy", null, Locale.CHINA), KeyEvent.VK_C); JMenuItem cut = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.cut", null, Locale.CHINA), KeyEvent.VK_X); JMenuItem font = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.font", null, Locale.CHINA), KeyEvent.VK_F); JMenuItem choose = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.choose", null, Locale.CHINA), KeyEvent.VK_O); JMenuItem saveas = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.saveas", null, Locale.CHINA), KeyEvent.VK_S); consoleRight.add(clear); consoleRight.add(copy); consoleRight.add(cut); consoleRight.add(font); consoleRight.add(choose); consoleRight.add(saveas); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { consolePane.setText(""); jConsole.clear(); } }); copy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } } }); cut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } consolePane.setText(""); jConsole.clear(); } }); saveas.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showSaveDialog(null); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { if (file.exists() == false) { file.createNewFile(); } FileWriter writer = new FileWriter(file); char[] arry = consolePane.getText().toCharArray(); writer.write(arry); writer.flush(); writer.close(); LOG.info(CONTEXT.getMessage("gobal.right.menu.saveas.success", null, Locale.CHINA)); } catch (IOException ioe) { } } } }); }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates new help menu with help/about options * * @return help menu/*from www. j ava2s . c o m*/ */ private JMenu createHelpMenu() { JMenu menu = new JMenu("Help"); // help menu JMenuItem item = new JMenuItem("Help"); // help menu -> help item.addActionListener(e -> showHelpDialogOrFail()); menu.add(item); item = new JMenuItem("About"); // help menu -> about item.addActionListener(e -> showAboutDialogOrFail()); menu.add(item); return menu; }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates new edit menu/*from ww w .j a va 2s. co m*/ * * @return edit menu */ private JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); // file menu JMenuItem item = new JMenuItem("Test submissions seconds wait"); item.addActionListener(e -> { String userInput = JOptionPane.showInputDialog("Test submissions seconds wait", SECONDS_WAIT_BETWEEN_SUBMISSIONS); SECONDS_WAIT_BETWEEN_SUBMISSIONS = Integer.parseInt(userInput); // update }); menu.add(item); return menu; }
From source file:com.jidesoft.spring.richclient.docking.JideApplicationLifecycleAdvisor.java
@Override public void onPostStartup() { initializeRepaintManager();// w w w. j av a 2 s . co m if (devOption == false) { JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar(); for (int i = 0; i < menuBar.getMenuCount(); i++) { //TODO:I18N if (menuBar.getMenu(i).getText().equals("Admin")) { menuBar.getMenu(i).setVisible(false); } } } JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar(); for (int i = 0; i < menuBar.getMenuCount(); i++) { // recent games //TODO: I18N if (menuBar.getMenu(i).getText().equals("Game")) { for (int j = 0; j < menuBar.getMenu(i).getItemCount(); j++) { if (menuBar.getMenu(i).getItem(j) != null && menuBar.getMenu(i).getItem(j).getText() != null && menuBar.getMenu(i).getItem(j).getText().equals("Recent Games")) { JMenu menu = (JMenu) menuBar.getMenu(i).getItem(j); RecentGames rg = new RecentGames(); ArrayList<RecentGames.RecentGameInfo> rgis = rg.getRecentGameInfo(); for (RecentGameInfo rgi : rgis) { final RecentGameInfo frgi = rgi; JMenuItem mu = new JMenuItem(); mu.setText("Game " + String.valueOf(rgi.getNumber())); mu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LoadGame loadGame = new LoadGame(frgi.getFile()); loadGame.execute(); } }); menu.add(mu); } } } } // user guide //TODO:I18N if (menuBar.getMenu(i).getText().equals("Help")) { try { final File f = new File("JOverseerUserGuide.pdf"); if (f.exists()) { //TODO:I18N JMenuItem mi = new JMenuItem("User's Guide"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Runtime.getRuntime() .exec("rundll32 url.dll,FileProtocolHandler " + f.getAbsolutePath()); } catch (Exception exc) { // do nothing } } }); menuBar.getMenu(i).add(new JSeparator()); menuBar.getMenu(i).add(mi); } } catch (Exception exc) { // do nothing } } } if (JOverseerJIDEClient.cmdLineArgs != null && JOverseerJIDEClient.cmdLineArgs.length == 1 && JOverseerJIDEClient.cmdLineArgs[0].endsWith(".jov")) { String fname = JOverseerJIDEClient.cmdLineArgs[0]; File f = new File(fname); if (f.exists()) { LoadGame lg = new LoadGame(fname); lg.loadGame(); } } }
From source file:hermes.browser.components.ClasspathGroupTable.java
private void init() { final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem addItem = new JMenuItem("Add Group"); final JMenuItem removeItem = new JMenuItem("Remove Group"); final JMenuItem renameItem = new JMenuItem("Rename"); popupMenu.add(addItem);/*from w w w.j a v a 2s . c o m*/ popupMenu.add(removeItem); popupMenu.add(renameItem); addItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { doAddGroup(); dialog.setDirty(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } }); removeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (getSelectedRowCount() > 0) { for (int row : getSelectedRows()) { getClasspathGroupTableModel().removeRow(row); } dialog.setDirty(); } } }); renameItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (getSelectedRow() != -1) { doRename(); } } }); mouseAdapter = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { removeItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0); renameItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }; addMouseListener(mouseAdapter); getTableHeader().addMouseListener(mouseAdapter); if (dialog != null) { addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // // Think this is ok, seems 2 do the job. if (evt.getPropertyName().equals("tableCellEditor")) { dialog.setDirty(); } } }); } }
From source file:es.emergya.ui.gis.HistoryMapViewer.java
@Override protected JPopupMenu getContextMenu() { JPopupMenu menu = new JPopupMenu(); // Centrar aqui JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C); cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar")); cent.addActionListener(new ActionListener() { @Override//from www.j ava 2s. c o m public void actionPerformed(ActionEvent e) { mapView.zoomToFactor(mapView.getEastNorth(eventOriginal.getX(), eventOriginal.getY()), mapView.zoomFactor); } }); menu.add(cent); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { eventOriginal = HistoryMapViewer.this.mapView.lastMEvent; } @Override public void popupMenuCanceled(PopupMenuEvent arg0) { } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } }); return menu; }
From source file:com.qspin.qtaste.ui.MainPanel.java
protected void genMenu(final TestCaseTree tct) { final JFrame owner = this; JMenuBar menuBar = new JMenuBar(); JMenu tools = new JMenu("Tools"); tools.setMnemonic(KeyEvent.VK_T); // Tools|Config menu item JMenuItem config = new JMenuItem("Config", KeyEvent.VK_D); config.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //ATEConfigEditPanel configPanel = new ATEConfigEditPanel(null); //configPanel.setVisible(true); MainConfigFrame configFrame = new MainConfigFrame(); configFrame.launch();/*from w w w . jav a2 s. c o m*/ configFrame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowClosed(WindowEvent e) { // refresh the Configuration information display refreshParams(); } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); } }); tools.add(config); // Tools|delete results menu item JMenuItem deleteResults = new JMenuItem("Delete Results", KeyEvent.VK_D); final MainPanel ui = this; deleteResults.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String baseDir = TestEngineConfiguration.getInstance().getString("reporting.generated_report_path"); new File(baseDir, baseDir); // TO DO : delete really the files JOptionPane.showMessageDialog(ui, "Results have been deleted"); } }); tools.add(deleteResults); JMenu fileMenu = new JMenu("File"); JMenuItem importTestSuites = new JMenuItem("Import TestSuites"); importTestSuites.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // mTestCasePanel.importTestSuites(); } }); fileMenu.add(importTestSuites); JMenu help = new JMenu("Help"); help.setMnemonic(KeyEvent.VK_H); JMenuItem about = new JMenuItem("About", KeyEvent.VK_A); about.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new AboutDialog(owner); } }); help.add(about); JMenuItem ateUserManuel = new JMenuItem("User Manual"); ateUserManuel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewQTasteUserManuel(); } }); help.add(ateUserManuel); //menuBar.add(tools); // not to be used at this time!!!!!!!!! //menuBar.add(fileMenu); menuBar.add(help); setJMenuBar(menuBar); }