List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:ffx.ui.MainMenu.java
private JCheckBoxMenuItem addCBMenuItem(JMenu menu, String icon, String actionCommand, int mnemonic, int accelerator, final ActionListener actionListener) { final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(); Action a = new AbstractAction() { @Override//from w w w . j a v a 2 s .c o m public void actionPerformed(ActionEvent e) { /** * If the ActionEvent is from a ToolBar button, pass it through * the JCheckBoxMenuItem. */ if (e.getSource() != menuItem) { menuItem.doClick(); return; } actionListener.actionPerformed(e); } }; configureAction(a, icon, actionCommand, mnemonic, accelerator); menuItem.setAction(a); menu.add(menuItem); return menuItem; }
From source file:edu.clemson.cs.nestbed.client.gui.ConfigManagerFrame.java
private final JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem close = new JMenuItem("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ConfigManagerFrame.this.setVisible(false); }/* www.j av a 2s . co m*/ }); menu.add(close); return menu; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Build menu./*from w w w. j a v a 2 s .c om*/ */ public void makeMenu() { JMenuItem menuItem; JMenu menu; JMenu submenu; menuBar = new JMenuBar(); setJMenuBar(menuBar); menu = new JMenu(Menu.MENU_FILE); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.EXPORT_MENU); menu.add(submenu); //submenu.setMnemonic( KeyEvent.VK_E ); SchemeExporter.makeSchemeExportMenu(submenu, getActionListener()); // Export window graphics submenu.add(GraphicsExporter.getExportMenu()); menu.addSeparator(); menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu = new JMenu(Menu.MENU_EDIT); menu.setMnemonic(KeyEvent.VK_E); menu.add(undoAction); menu.add(redoAction); menu.add(cloneAction); menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true); painterEnabled.addActionListener(getActionListener()); menu.add(painterEnabled); menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas = Editor.getInstance().getCurrentCanvas(); if (canvas == null || !canvas.getPackage().hasPainters()) { painterEnabled.setVisible(false); } else { painterEnabled.setVisible(true); painterEnabled.setSelected(canvas.isEnableClassPainter()); } } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_VIEW); menu.setMnemonic(KeyEvent.VK_V); gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid()); gridCheckBox.setMnemonic('G'); gridCheckBox.addActionListener(getActionListener()); menu.add(gridCheckBox); ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls()); ctrlCheckBox.setMnemonic('C'); ctrlCheckBox.addActionListener(getActionListener()); menu.add(ctrlCheckBox); showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true); showPortCheckBox.addActionListener(getActionListener()); menu.add(showPortCheckBox); showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false); showObjectNamesCheckBox.addActionListener(getActionListener()); menu.add(showObjectNamesCheckBox); //sync View with current canvas menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas; if ((canvas = getCurrentCanvas()) == null) return; gridCheckBox.setSelected(canvas.isGridVisible()); ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible()); showPortCheckBox.setSelected(canvas.isDrawPorts()); showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_PACKAGE); menu.setMnemonic(KeyEvent.VK_P); menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (Desktop.isDesktopSupported()) { menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLOSE_ALL); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu.add(new JSeparator()); final JMenu submenuRecent = new JMenu(Menu.RECENT); submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { final JMenuItem empty = new JMenuItem("Empty"); @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeRecentSubMenu(submenuRecent); if (submenuRecent.getMenuComponentCount() == 0) { submenuRecent.add(empty); empty.setEnabled(false); } else { if (!((submenuRecent.getMenuComponentCount() == 1) && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) { submenuRecent.remove(empty); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menu.add(submenuRecent); final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME); menuScheme.setMnemonic(KeyEvent.VK_S); makeSchemeMenu(menuScheme); menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeSchemeMenu(menuScheme); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); /* * menuItem = new JMenuItem("Planner"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); * menuItem = new JMenuItem("Plan, compile, run"); * menuItem.setActionCommand("Run"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); */ // menuScheme.setMnemonic(KeyEvent.VK_A); menuBar.add(menuScheme); menu = new JMenu(Menu.MENU_OPTIONS); menu.setMnemonic(KeyEvent.VK_O); menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.FONTS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SETTINGS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.MENU_LAF); submenu.setMnemonic(KeyEvent.VK_L); Look.getInstance().createMenuItems(submenu); menu.add(submenu); menuBar.add(menu); makeToolsMenu(menuBar); menu = new JMenu(Menu.MENU_HELP); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:ffx.ui.MainMenu.java
private JRadioButtonMenuItem addBGMI(ButtonGroup buttonGroup, JMenu menu, String icon, String actionCommand, int mnemonic, int accelerator, final ActionListener actionListener) { final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(); Action a = new AbstractAction() { @Override/*from w ww. j a va2 s.c o m*/ public void actionPerformed(ActionEvent e) { /** * If the ActionEvent is from a ToolBar button, pass it through * the JRadioButtonMenuItem. */ if (e.getSource() != menuItem) { menuItem.doClick(); return; } actionListener.actionPerformed(e); } }; this.configureAction(a, icon, actionCommand, mnemonic, accelerator); menuItem.setAction(a); buttonGroup.add(menuItem); menu.add(menuItem); return menuItem; }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * /*from ww w .j av a2 s . co m*/ */ protected void doStart() { frame = new JFrame(); JMenuBar mb = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu rptMenu = new JMenu("Reports"); //JMenu chrtMenu = new JMenu("Charts"); frame.setTitle(title); JMenuItem doISARegReportMI = new JMenuItem("ISA Reg Report"); rptMenu.add(doISARegReportMI); JMenuItem doStatsMI = new JMenuItem("Registration"); rptMenu.add(doStatsMI); //JMenuItem doMiscMI = new JMenuItem("Misc"); //chrtMenu.add(doMiscMI); //menu.addSeparator(); JMenuItem doSetVersionMI = new JMenuItem("Set Version"); fileMenu.add(doSetVersionMI); if (!UIHelper.isMacOS()) { fileMenu.addSeparator(); JMenuItem doExitMI = new JMenuItem("Exit"); fileMenu.add(doExitMI); doExitMI.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doExit(true); } }); } mb.add(fileMenu); mb.add(rptMenu); //mb.add(chrtMenu); frame.setJMenuBar(mb); frame.setContentPane(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(0, 0, 600, 768); UIHelper.centerAndShow(frame); doISARegReportMI.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { createRegReport(); } }); doStatsMI.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { createStatsReport(); } }); doSetVersionMI.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doSetVersion(); } }); }
From source file:gdt.jgui.entity.contact.JContactEditor.java
@Override public JMenu getContextMenu() { final JMenu menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override//from ww w. j a va 2s.co m public void menuSelected(MenuEvent e) { // System.out.println("EntityEditor:getConextMenu:menu selected"); menu.removeAll(); JMenuItem facetsItem = new JMenuItem("Facets"); facetsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); JEntityFacetPanel erm = new JEntityFacetPanel(); String locator$ = erm.getLocator(); locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$); locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, locator$); } }); menu.add(facetsItem); JMenuItem digestItem = new JMenuItem("Digest"); digestItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); String locator$ = getLocator(); JEntityDigestDisplay edd = new JEntityDigestDisplay(); edd.instantiate(console, locator$); String eddLocator$ = edd.getLocator(); eddLocator$ = Locator.append(eddLocator$, Entigrator.ENTIHOME, entihome$); eddLocator$ = Locator.append(eddLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, eddLocator$); } }); menu.add(digestItem); JMenuItem structureItem = new JMenuItem("Structure"); structureItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); String locator$ = getLocator(); JEntityStructurePanel esp = new JEntityStructurePanel(); esp.instantiate(console, locator$); String espLocator$ = esp.getLocator(); espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$); espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, espLocator$); } }); menu.add(structureItem); menu.addSeparator(); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Entigrator entigrator = console.getEntigrator(entihome$); Sack contact = entigrator.getEntityAtKey(entityKey$); String entityLabel$ = contact.getProperty("label"); String title$ = title.getText(); if (!entityLabel$.equals(title$)) { contact = entigrator.ent_assignLabel(contact, title$); contact = entigrator.ent_assignProperty(contact, "contact", contact.getProperty("label")); } contact = entigrator.ent_assignProperty(contact, "phone", phone.getText()); contact = entigrator.ent_assignProperty(contact, "email", email.getText()); if (requesterResponseLocator$ != null) { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); // System.out.println("TextEditor:done:response locator="+responseLocator$); JConsoleHandler.execute(console, responseLocator$); } else console.back(); } catch (Exception ee) { Logger.getLogger(JContactEditor.class.getName()).severe(ee.toString()); } } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); } @Override public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub } @Override public void menuCanceled(MenuEvent e) { // TODO Auto-generated method stub } }); return menu; }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
private JMenuBar createMenuBar() { JMenuBar bar = new JMenuBar(); JMenu menu = null; /*/*from ww w . j a va 2 s.co m*/ * 'File' Menue */ menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); bar.add(menu); JMenuItem item = new JMenuItem("Save database"); item.setAccelerator(KeyStroke.getKeyStroke("control S")); item.setMnemonic(KeyEvent.VK_S); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveDatabase(); } }); menu.add(item); item = new JMenuItem("Download database"); item.setMnemonic(KeyEvent.VK_L); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { downloadAndMergeData(); } }); menu.add(item); item = new JMenuItem("Edit sync account"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editSyncAccount(); } }); menu.add(item); menu.add(new JSeparator()); JMenu submenu = new JMenu("Import"); menu.add(submenu); item = new JMenuItem("From CSV"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { importCSV(); } }); submenu.add(item); submenu = new JMenu("Export"); menu.add(submenu); item = new JMenuItem("As CSV"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportCSV(); } }); submenu.add(item); item = new JMenuItem("Change passphrase"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changePassword(); } }); /* * 'Edit' Menue */ menu = new JMenu("Edit"); menu.setMnemonic(KeyEvent.VK_E); bar.add(menu); item = menu.add(mainPanel.getNewEntryAction()); item.setMnemonic(KeyEvent.VK_N); item = menu.add(mainPanel.getDeleteEntryAction()); item.setMnemonic(KeyEvent.VK_D); menu.add(new JSeparator()); menu = new JMenu("Tools"); // item = new JMenuItem("Passwort generator"); // menu.add(item); // item.addActionListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // passGenerator.setVisible(false); // passGenerator.setLocationRelativeTo(getMainFrame()); // passGenerator.setVisible(true); // } // }); item = new JMenuItem("Screen keyboard"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { screenKeyboard.setLocationRelativeTo(getMainFrame()); screenKeyboard.setVisible(true); } }); item = new JMenuItem("File digester"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { digester.setLocationRelativeTo(getMainFrame()); digester.setVisible(true); } }); bar.add(menu); /* * 'Help' Menue */ menu = new JMenu("Help"); menu.setMnemonic(KeyEvent.VK_H); bar.add(menu); item = new JMenuItem("Performance test"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { measurePerformance(); } }); item = new JMenuItem("System info"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showSystemInfo(); } }); item = new JMenuItem("About"); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = "<html>Ultracipher 6.1<br>(C) Copyright 2015 Paul Burlov<br><br>" + "Encryption strength: 768Bit (6 x 128Bit keys)<br>Cipher cascade: AES/Twofish/Serpent/CAST6/SEED/Camellia" + "<br>Encryption mode: Two pass CBC" + "<br>Key derivation algorithm: SCrypt with N=2^14,P=8,R=1<br><br> " + "This product includes software developed by the<br>" + "<ul><li>Apache Software Foundation " + "<a href='http://www.apache.org'>http://www.apache.org</a>" + "<li>Legion of the Bouncy Castle <a href='http://bouncycastle.org/'>http://bouncycastle.org</a>" + "<li>Project SwingX" + "<li>Bytecode Pty Ltd." + "</ul></html>"; JOptionPane.showMessageDialog(getMainFrame(), text, "", JOptionPane.INFORMATION_MESSAGE, getAppIcon()); } }); bar.add(Box.createHorizontalGlue()); menu = new JMenu("Keyboard"); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem("System"); radioitem.setSelected(true); group.add(radioitem); radioitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { translator.resetMapping(); } }); menu.add(radioitem); radioitem = new JRadioButtonMenuItem("Futhark runes"); group.add(radioitem); radioitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { translator.initForFuthark(); } }); menu.add(radioitem); radioitem = new JRadioButtonMenuItem("Anglo-Saxon runes"); group.add(radioitem); radioitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { translator.initForAngloSaxon(); } }); menu.add(radioitem); bar.add(menu); // bar.add(Box.createHorizontalGlue()); // bar.add(new PassGeneratorPanel()); return bar; }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initMenus() { final JMenuBar menuBar = new JMenuBar(); class AddSpace { void add() { JMenu dummy = new JMenu(); dummy.setEnabled(false);/*from w w w.j a v a2s . com*/ menuBar.add(dummy); } } AddSpace addSpace = new AddSpace(); // add file menu ... build on the fly for recent files.. setJMenuBar(menuBar); final JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); mnFile.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { initFileMenu(mnFile); } @Override public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub } @Override public void menuCanceled(MenuEvent e) { // TODO Auto-generated method stub } }); initFileMenu(mnFile); menuBar.add(mnFile); addSpace.add(); // add edit menu JMenu mnEdit = new JMenu("Edit"); mnEdit.setMnemonic('E'); menuBar.add(mnEdit); addSpace.add(); for (MyAction action : editActions) { JMenuItem item = mnEdit.add(action); if (action.accelerator != null) { item.setAccelerator(action.accelerator); } } // add run scripts menu (hidden until a datastore is loaded) mnScripts = new JMenu("Run script"); mnScripts.setMnemonic('R'); mnScripts.setVisible(false); mnScripts.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { mnScripts.removeAll(); for (final ScriptNode item : scriptsPanel.getScripts()) { if (item.isAvailable() == false) { continue; } if (item.isRunnable()) { mnScripts.add(new AbstractAction(item.getDisplayName(), item.getIcon()) { @Override public void actionPerformed(ActionEvent e) { scriptManager.executeScript(item.getFile(), item.getLaunchExecutorId()); } }); } else if (item.getChildCount() > 0) { JMenu popup = new JMenu(item.getDisplayName()); mnScripts.add(popup); for (int i = 0; i < item.getChildCount(); i++) { final ScriptNode child = (ScriptNode) item.getChildAt(i); if (child.isRunnable()) { popup.add(new AbstractAction(child.getDisplayName(), child.getIcon()) { @Override public void actionPerformed(ActionEvent e) { scriptManager.executeScript(child.getFile(), child.getLaunchExecutorId()); } }); } } } } mnScripts.validate(); } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); menuBar.add(mnScripts); addSpace.add(); // add create script menu menuBar.add(initCreateScriptsMenu()); addSpace.add(); // add window menu JMenu mnWindow = new JMenu("Window"); mnWindow.setMnemonic('W'); menuBar.add(mnWindow); addSpace.add(); initWindowMenus(mnWindow); menuBar.add(initHelpMenu()); addSpace.add(); }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
private JPopupMenu createPopupMenuForSeries(final Series series) { if (series == null) return new JPopupMenu(); final JPopupMenu menu = new JPopupMenu(series.getName()); menu.removeAll();/*from w w w.ja va 2 s . com*/ menu.add(new AbstractAction() { { putValue(NAME, "Renommer la srie"); } @Override public void actionPerformed(ActionEvent e) { menu.setVisible(false); String newName = ""; while (newName == null || newName.equals("")) { newName = (String) JOptionPane.showInputDialog(application, "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null, series.getName()); } series.setName(newName); } }); if (series.hasOwnAxis()) { menu.add(new AbstractAction() { { putValue(NAME, "Supprimer l'axe spcifique"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { series.setAxis(null); } } }); } else { menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, "Crer un axe spcifique pour la srie"); } @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?", series.getAxis().getLabel()); if (name == null || "".equals(name)) return; // User has canceled series.setAxis(new NumberAxis(name)); } })); } menu.add(new SetTypeMenu(series)); if (series.isWater()) { menu.addSeparator(); menu.add(new SumOnPeriodAction(series)); menu.add(new CreateCumulAction(series)); } if (series.isWaterCumul()) { menu.addSeparator(); menu.add(new SamplingAction(series)); } if (series.isPressure()) { menu.addSeparator(); menu.add(new CorrelateAction(series)); menu.add(new WaterHeightAction(series)); } menu.addSeparator(); menu.add(new AbstractAction() { { String name; if (series.canUndo()) name = "Annuler " + series.getItemsName(); else name = series.getLastUndoName(); putValue(NAME, name); if (series.canUndo()) setEnabled(true); else { setEnabled(false); } } @Override public void actionPerformed(ActionEvent e) { series.undo(); } }); menu.add(new AbstractAction() { { String name; if (series.canRedo()) { name = "Refaire " + series.getNextRedoName(); setEnabled(true); } else { name = series.getNextRedoName(); setEnabled(false); } putValue(NAME, name); } @Override public void actionPerformed(ActionEvent e) { series.redo(); } }); menu.add(new AbstractAction() { { putValue(NAME, I18nSupport.translate("menus.serie.resetSerie")); if (series.canUndo()) setEnabled(true); else setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { series.reset(); } }); menu.add(new LimitDateRangeAction(series)); menu.add(new HourSettingAction(series)); menu.addSeparator(); { JMenuItem deleteItem = new JMenuItem("Supprimer la srie"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir supprimer cette srie ?\n" + "Cette action est dfinitive.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { series.delete(); } } }); menu.add(deleteItem); } menu.addSeparator(); { final JMenuItem up = new JMenuItem("Remonter dans la liste"), down = new JMenuItem("Descendre dans la liste"); ActionListener listener = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(up)) { series.upSeriesInList(); } else { series.downSeriesInList(); } } }; up.addActionListener(listener); down.addActionListener(listener); if (series.isFirst()) { menu.add(down); } else if (series.isLast()) { menu.add(up); } else { menu.add(up); menu.add(down); } } menu.addSeparator(); { menu.add(new SeriesInfoAction(series)); } { JMenuItem colorItem = new JMenuItem("Couleur de la srie"); colorItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { series.setColor(JColorChooser.showDialog(application, I18nSupport.translate("actions.selectColorForSeries"), series.getColor())); } }); menu.add(colorItem); } { JMenu plotRenderer = new JMenu("Affichage de la srie"); final ButtonGroup modes = new ButtonGroup(); java.util.List<DrawStyle> availableStyles; if (series.isMinMax()) { availableStyles = DrawStyles.getDrawableStylesForHighLow(); } else { availableStyles = DrawStyles.getDrawableStyles(); } for (final DrawStyle s : availableStyles) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s)); item.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (item.isSelected()) series.setStyle(s); } }); modes.add(item); if (s.equals(series.getStyle())) { modes.setSelected(item.getModel(), true); } plotRenderer.add(item); } menu.add(plotRenderer); } menu.addSeparator(); menu.add(new AbstractAction() { { putValue(Action.NAME, "Fermer le fichier"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { final File f = series.getOrigin(); for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) { if (s.getOrigin().equals(f)) s.delete(); } } } }); return menu; }
From source file:edu.brown.gui.CatalogViewer.java
/** * // w w w . jav a 2 s .c o m */ protected void viewerInit() { // ---------------------------------------------- // MENU // ---------------------------------------------- JMenu menu; JMenuItem menuItem; // // File Menu // menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menu.setMnemonic(KeyEvent.VK_F); menu.getAccessibleContext().setAccessibleDescription("File Menu"); menuBar.add(menu); menuItem = new JMenuItem("Open Catalog From File"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE); menu.add(menuItem); menuItem = new JMenuItem("Open Catalog From Jar"); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Quit", KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Quit Program"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT); menu.add(menuItem); // ---------------------------------------------- // CATALOG TREE PANEL // ---------------------------------------------- this.catalogTree = new JTree(); this.catalogTree.setEditable(false); this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer()); this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree .getLastSelectedPathComponent(); if (node == null) return; Object user_obj = node.getUserObject(); String new_text = ""; // <html>"; boolean text_mode = true; if (user_obj instanceof WrapperNode) { CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType(); new_text += CatalogViewer.this.getAttributesText(catalog_obj); } else if (user_obj instanceof AttributesNode) { AttributesNode wrapper = (AttributesNode) user_obj; new_text += wrapper.getAttributes(); } else if (user_obj instanceof PlanTreeCatalogNode) { final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj; text_mode = false; CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER); CatalogViewer.this.mainPanel.validate(); CatalogViewer.this.mainPanel.repaint(); if (SwingUtilities.isEventDispatchThread() == false) { SwingUtilities.invokeLater(new Runnable() { public void run() { wrapper.centerOnRoot(); } }); } else { wrapper.centerOnRoot(); } } else { new_text += CatalogViewer.this.getSummaryText(); } // Text Mode if (text_mode) { if (CatalogViewer.this.text_mode == false) { CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel); } CatalogViewer.this.textInfoTextArea.setText(new_text); // Scroll to top CatalogViewer.this.textInfoTextArea.grabFocus(); } CatalogViewer.this.text_mode = text_mode; } }); this.generateCatalogTree(this.catalog, this.catalog_file_path.getName()); // // Text Information Panel // this.textInfoPanel = new JPanel(); this.textInfoPanel.setLayout(new BorderLayout()); this.textInfoTextArea = new JTextArea(); this.textInfoTextArea.setEditable(false); this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); this.textInfoTextArea.setText(this.getSummaryText()); this.textInfoTextArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusGained(FocusEvent e) { CatalogViewer.this.scrollTextInfoToTop(); } }); this.textInfoScroller = new JScrollPane(this.textInfoTextArea); this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER); this.mainPanel = new JPanel(new BorderLayout()); this.mainPanel.add(textInfoPanel, BorderLayout.CENTER); // // Search Toolbar // JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout()); JPanel innerSearchPanel = new JPanel(); innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS)); innerSearchPanel.add(new JLabel("Search: ")); this.searchField = new JTextField(30); innerSearchPanel.add(this.searchField); searchPanel.add(innerSearchPanel, BorderLayout.EAST); this.searchField.addKeyListener(new KeyListener() { private String last = null; @Override public void keyReleased(KeyEvent e) { String value = CatalogViewer.this.searchField.getText().toLowerCase().trim(); if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) { CatalogViewer.this.search(value); } this.last = value; } @Override public void keyTyped(KeyEvent e) { // Do nothing... } @Override public void keyPressed(KeyEvent e) { // Do nothing... } }); // Putting it all together JScrollPane scrollPane = new JScrollPane(this.catalogTree); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); topPanel.add(searchPanel, BorderLayout.NORTH); topPanel.add(scrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel); splitPane.setDividerLocation(400); this.add(splitPane, BorderLayout.CENTER); }