List of usage examples for javax.swing JMenu addMenuListener
public void addMenuListener(MenuListener l)
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewerControl.java
/** * Attaches a window listener to the view to discard the model when * the user closes the window. /*from www . j av a2s. c om*/ */ private void attachListeners() { if (UIUtilities.isMacOS()) { try { MacOSMenuHandler handler = new MacOSMenuHandler(view); handler.initialize(); view.addPropertyChangeListener(this); } catch (Throwable e) { } } Map browsers = model.getBrowsers(); Iterator i = browsers.values().iterator(); Browser browser; while (i.hasNext()) { browser = (Browser) i.next(); browser.addPropertyChangeListener(this); browser.addChangeListener(this); } view.addWindowFocusListener(this); model.addPropertyChangeListener(this); view.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); view.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { model.closeWindow(); } }); // JMenu menu = TreeViewerFactory.getWindowMenu(); menu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent e) { Object source = e.getSource(); if (source instanceof JMenu) createWindowsMenuItems((JMenu) source); } /** * Required by I/F but not actually needed in our case, * no-operation implementation. * @see MenuListener#menuCanceled(MenuEvent) */ public void menuCanceled(MenuEvent e) { } /** * Required by I/F but not actually needed in our case, * no-operation implementation. * @see MenuListener#menuDeselected(MenuEvent) */ public void menuDeselected(MenuEvent e) { } }); //Listen to keyboard selection menu.addMenuKeyListener(new MenuKeyListener() { public void menuKeyReleased(MenuKeyEvent e) { Object source = e.getSource(); if (source instanceof JMenu) createWindowsMenuItems((JMenu) source); } /** * Required by I/F but not actually needed in our case, * no-operation implementation. * @see MenuKeyListener#menuKeyPressed(MenuKeyEvent) */ public void menuKeyPressed(MenuKeyEvent e) { } /** * Required by I/F but not actually needed in our case, * no-operation implementation. * @see MenuKeyListener#menuKeyTyped(MenuKeyEvent) */ public void menuKeyTyped(MenuKeyEvent e) { } }); }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Copies the items from the specified menu and creates a new menu. * * @param original The menu to handle.// ww w .j a va 2 s. co m * @return See above. */ private JMenu copyItemsFromMenu(JMenu original) { Component[] comps = original.getPopupMenu().getComponents(); JMenu menu = new JMenu(); menu.setText(original.getText()); menu.setToolTipText(original.getToolTipText()); ActionListener[] al = original.getActionListeners(); for (int j = 0; j < al.length; j++) menu.addActionListener(al[j]); MenuKeyListener[] mkl = original.getMenuKeyListeners(); for (int j = 0; j < mkl.length; j++) menu.addMenuKeyListener(mkl[j]); MenuListener[] ml = original.getMenuListeners(); for (int j = 0; j < ml.length; j++) menu.addMenuListener(ml[j]); for (int i = 0; i < comps.length; i++) { if (comps[i] instanceof JMenu) { menu.add(copyItemsFromMenu((JMenu) comps[i])); } else if (comps[i] instanceof JMenuItem) { menu.add(copyItem((JMenuItem) comps[i])); } else if (comps[i] instanceof JSeparator) { menu.add(new JSeparator(JSeparator.HORIZONTAL)); } } return menu; }
From source file:org.openscience.jmol.app.Jmol.java
/** * Create a menu for the app. By default this pulls the * definition of the menu from the associated resource file. * @param key/*from w w w .j a v a 2 s .co m*/ * @return Menu created */ protected JMenu createMenu(String key) { // Get list of items from resource file: String[] itemKeys = tokenize(JmolResourceHandler.getStringX(key)); // Get label associated with this menu: JMenu menu = guimap.newJMenu(key); ImageIcon f = JmolResourceHandler.getIconX(key + "Image"); if (f != null) { menu.setHorizontalTextPosition(SwingConstants.RIGHT); menu.setIcon(f); } // Loop over the items in this menu: for (int i = 0; i < itemKeys.length; i++) { String item = itemKeys[i]; if (item.equals("-")) { menu.addSeparator(); continue; } if (item.endsWith("Menu")) { JMenu pm; if ("recentFilesMenu".equals(item)) { /*recentFilesMenu = */pm = createMenu(item); } else { pm = createMenu(item); } menu.add(pm); continue; } JMenuItem mi = createMenuItem(item); menu.add(mi); } menu.addMenuListener(display.getMenuListener()); return menu; }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from w ww .j a v a 2 s.c om } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }
From source file:org.rdv.ui.MainPanel.java
private void initMenuBar() { Application application = RDV.getInstance(); ApplicationContext context = application.getContext(); ResourceMap resourceMap = context.getResourceMap(); String platform = resourceMap.getString("platform"); boolean isMac = (platform != null && platform.equals("osx")); ActionFactory actionFactory = ActionFactory.getInstance(); Actions actions = Actions.getInstance(); ActionMap actionMap = context.getActionMap(actions); menuBar = new JMenuBar(); JMenuItem menuItem;//from www. j av a 2 s . com JMenu fileMenu = new JMenu(fileAction); menuItem = new JMenuItem(connectAction); fileMenu.add(menuItem); menuItem = new JMenuItem(disconnectAction); fileMenu.add(menuItem); fileMenu.addSeparator(); menuItem = new JMenuItem(loginAction); fileMenu.add(menuItem); menuItem = new JMenuItem(logoutAction); fileMenu.add(menuItem); fileMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { if (AuthenticationManager.getInstance().getAuthentication() == null) { loginAction.setEnabled(true); logoutAction.setEnabled(false); } else { loginAction.setEnabled(false); logoutAction.setEnabled(true); } } }); fileMenu.addSeparator(); menuItem = new JMenuItem(loadAction); fileMenu.add(menuItem); menuItem = new JMenuItem(saveAction); fileMenu.add(menuItem); fileMenu.addSeparator(); fileMenu.add(new JMenuItem(actionMap.get("addLocalChannel"))); fileMenu.addSeparator(); JMenu importSubMenu = new JMenu(importAction); menuItem = new JMenuItem(actionFactory.getDataImportAction()); importSubMenu.add(menuItem); menuItem = new JMenuItem(actionFactory.getOpenSeesDataImportAction()); importSubMenu.add(menuItem); importSubMenu.add(new JMenuItem(actionMap.get("importJPEGs"))); fileMenu.add(importSubMenu); JMenu exportSubMenu = new JMenu(exportAction); menuItem = new JMenuItem(actionFactory.getDataExportAction()); exportSubMenu.add(menuItem); menuItem = new JMenuItem(exportVideoAction); exportSubMenu.add(menuItem); fileMenu.add(exportSubMenu); fileMenu.addSeparator(); menuItem = new DataViewerCheckBoxMenuItem(actionFactory.getOfflineAction()); fileMenu.add(menuItem); if (!isMac) { menuItem = new JMenuItem(exitAction); fileMenu.add(menuItem); } menuBar.add(fileMenu); JMenu controlMenu = new JMenu(controlAction); menuItem = new SelectableCheckBoxMenuItem(realTimeAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(playAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(pauseAction); controlMenu.add(menuItem); controlMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { int state = rbnb.getState(); realTimeAction.setSelected(state == Player.STATE_MONITORING); playAction.setSelected(state == Player.STATE_PLAYING); pauseAction.setSelected(state == Player.STATE_STOPPED); } }); controlMenu.addSeparator(); menuItem = new JMenuItem(beginningAction); controlMenu.add(menuItem); menuItem = new JMenuItem(endAction); controlMenu.add(menuItem); menuItem = new JMenuItem(gotoTimeAction); controlMenu.add(menuItem); menuBar.add(controlMenu); controlMenu.addSeparator(); menuItem = new JMenuItem(updateChannelListAction); controlMenu.add(menuItem); controlMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(dropDataAction); controlMenu.add(menuItem); JMenu viewMenu = new JMenu(viewAction); menuItem = new JCheckBoxMenuItem(showChannelListAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMetadataPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showControlPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showAudioPlayerPanelAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMarkerPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(showHiddenChannelsAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(hideEmptyTimeAction); menuItem.setSelected(false); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(fullScreenAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuBar.add(viewMenu); JMenu windowMenu = new JMenu(windowAction); List<Extension> extensions = dataPanelManager.getExtensions(); for (final Extension extension : extensions) { Action action = new DataViewerAction("Add " + extension.getName(), "", KeyEvent.VK_J) { /** serialization version identifier */ private static final long serialVersionUID = 36998228704476723L; public void actionPerformed(ActionEvent ae) { try { dataPanelManager.createDataPanel(extension); } catch (Exception e) { log.error("Unable to open data panel provided by extension " + extension.getName() + " (" + extension.getID() + ")."); e.printStackTrace(); } } }; menuItem = new JMenuItem(action); windowMenu.add(menuItem); } windowMenu.addSeparator(); menuItem = new JMenuItem(closeAllDataPanelsAction); windowMenu.add(menuItem); windowMenu.addSeparator(); JMenu dataPanelSubMenu = new JMenu(dataPanelAction); ButtonGroup dataPanelLayoutGroup = new ButtonGroup(); menuItem = new JRadioButtonMenuItem(dataPanelHorizontalLayoutAction); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); menuItem = new JRadioButtonMenuItem(dataPanelVerticalLayoutAction); menuItem.setSelected(true); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); windowMenu.add(dataPanelSubMenu); menuBar.add(windowMenu); JMenu helpMenu = new JMenu(helpAction); menuItem = new JMenuItem(usersGuideAction); helpMenu.add(menuItem); menuItem = new JMenuItem(supportAction); helpMenu.add(menuItem); menuItem = new JMenuItem(releaseNotesAction); helpMenu.add(menuItem); if (!isMac) { helpMenu.addSeparator(); menuItem = new JMenuItem(aboutAction); helpMenu.add(menuItem); } menuBar.add(helpMenu); menuBar.add(Box.createHorizontalGlue()); throbberStop = DataViewer.getIcon("icons/throbber.png"); throbberAnim = DataViewer.getIcon("icons/throbber_anim.gif"); throbber = new JLabel(throbberStop); throbber.setBorder(new EmptyBorder(0, 0, 0, 4)); menuBar.add(throbber, BorderLayout.EAST); if (isMac) { registerMacOSXEvents(); } frame.setJMenuBar(menuBar); }
From source file:org.tinymediamanager.ui.MainWindow.java
/** * Create the application.//w ww. j a v a2 s. co m * * @param name * the name */ public MainWindow(String name) { super(name); setName("mainWindow"); setMinimumSize(new Dimension(1000, 700)); instance = this; JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnTmm = new JMenu("tinyMediaManager"); mnTmm.setMnemonic(KeyEvent.VK_T); menuBar.add(mnTmm); if (!Globals.isDonator()) { mnTmm.add(new RegisterDonatorVersionAction()); } mnTmm.add(new SettingsAction()); mnTmm.addSeparator(); mnTmm.add(new LaunchUpdaterAction()); mnTmm.addSeparator(); mnTmm.add(new ExitAction()); initialize(); // tools menu JMenu tools = new JMenu(BUNDLE.getString("tmm.tools")); //$NON-NLS-1$ tools.setMnemonic(KeyEvent.VK_O); tools.add(new ClearDatabaseAction()); JMenu cache = new JMenu(BUNDLE.getString("tmm.cache")); //$NON-NLS-1$ cache.setMnemonic(KeyEvent.VK_C); tools.add(cache); JMenuItem clearImageCache = new JMenuItem(new ClearImageCacheAction()); clearImageCache.setMnemonic(KeyEvent.VK_I); cache.add(clearImageCache); JMenuItem rebuildImageCache = new JMenuItem(new RebuildImageCacheAction()); rebuildImageCache.setMnemonic(KeyEvent.VK_R); cache.add(rebuildImageCache); JMenuItem tmmFolder = new JMenuItem(BUNDLE.getString("tmm.gotoinstalldir")); //$NON-NLS-1$ tmmFolder.setMnemonic(KeyEvent.VK_I); tools.add(tmmFolder); tmmFolder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { Path path = Paths.get(System.getProperty("user.dir")); try { // check whether this location exists if (Files.exists(path)) { TmmUIHelper.openFile(path); } } catch (Exception ex) { LOGGER.error("open filemanager", ex); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, path, "message.erroropenfolder", new String[] { ":", ex.getLocalizedMessage() })); } } }); JMenuItem tmmLogs = new JMenuItem(BUNDLE.getString("tmm.errorlogs")); //$NON-NLS-1$ tmmLogs.setMnemonic(KeyEvent.VK_L); tools.add(tmmLogs); tmmLogs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JDialog logDialog = new LogDialog(); logDialog.setLocationRelativeTo(MainWindow.getActiveInstance()); logDialog.setVisible(true); } }); JMenuItem tmmMessages = new JMenuItem(BUNDLE.getString("tmm.messages")); //$NON-NLS-1$ tmmMessages.setMnemonic(KeyEvent.VK_L); tools.add(tmmMessages); tmmMessages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JDialog messageDialog = MessageHistoryDialog.getInstance(); messageDialog.setVisible(true); } }); tools.addSeparator(); final JMenu menuWakeOnLan = new JMenu(BUNDLE.getString("tmm.wakeonlan")); //$NON-NLS-1$ menuWakeOnLan.setMnemonic(KeyEvent.VK_W); menuWakeOnLan.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent arg0) { } @Override public void menuDeselected(MenuEvent arg0) { } @Override public void menuSelected(MenuEvent arg0) { menuWakeOnLan.removeAll(); for (final WolDevice device : Globals.settings.getWolDevices()) { JMenuItem item = new JMenuItem(device.getName()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { Utils.sendWakeOnLanPacket(device.getMacAddress()); } }); menuWakeOnLan.add(item); } } }); tools.add(menuWakeOnLan); // activate/deactivate WakeOnLan menu item tools.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { if (Globals.settings.getWolDevices().size() > 0) { menuWakeOnLan.setEnabled(true); } else { menuWakeOnLan.setEnabled(false); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); if (Globals.isDebug()) { final JMenu debugMenu = new JMenu("Debug"); //$NON-NLS-1$ JMenuItem trace = new JMenuItem("set Logger to TRACE"); //$NON-NLS-1$ trace.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.getLogger("org.tinymediamanager").setLevel(Level.TRACE); MessageManager.instance.pushMessage(new Message("Trace levels set!", "")); LOGGER.trace("if you see that, we're now on TRACE logging level ;)"); } }); debugMenu.add(trace); tools.add(debugMenu); } menuBar.add(tools); mnTmm = new JMenu(BUNDLE.getString("tmm.contact")); //$NON-NLS-1$ mnTmm.setMnemonic(KeyEvent.VK_C); mnTmm.add(new FeedbackAction()).setMnemonic(KeyEvent.VK_F); mnTmm.add(new BugReportAction()).setMnemonic(KeyEvent.VK_B); menuBar.add(mnTmm); mnTmm = new JMenu(BUNDLE.getString("tmm.help")); //$NON-NLS-1$ mnTmm.setMnemonic(KeyEvent.VK_H); menuBar.add(mnTmm); mnTmm.add(new WikiAction()).setMnemonic(KeyEvent.VK_W); mnTmm.add(new FaqAction()).setMnemonic(KeyEvent.VK_F); mnTmm.add(new ForumAction()).setMnemonic(KeyEvent.VK_O); mnTmm.addSeparator(); mnTmm.add(new AboutAction()).setMnemonic(KeyEvent.VK_A); menuBar.add(Box.createGlue()); if (!Globals.isDonator()) { JButton btnDonate = new JButton(new DonateAction()); btnDonate.setBorderPainted(false); btnDonate.setFocusPainted(false); btnDonate.setContentAreaFilled(false); menuBar.add(btnDonate); } checkForUpdate(); }
From source file:org.tinymediamanager.ui.movies.MoviePanel.java
private void buildMenu() { menu.setMnemonic(KeyEvent.VK_M); // menu items JMenuItem menuItem = menu.add(actionUpdateDataSources2); menuItem.setMnemonic(KeyEvent.VK_U); menuItem.setAccelerator(/*from ww w .j av a 2 s. com*/ KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); final JMenu menuUpdateDatasources = new JMenu(BUNDLE.getString("update.datasource")); //$NON-NLS-1$ final JMenu menuFindMissingMovies = new JMenu(BUNDLE.getString("movie.findmissing")); //$NON-NLS-1$ menuUpdateDatasources.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent arg0) { } @Override public void menuDeselected(MenuEvent arg0) { } @Override public void menuSelected(MenuEvent arg0) { menuUpdateDatasources.removeAll(); menuFindMissingMovies.removeAll(); for (String ds : MovieModuleManager.MOVIE_SETTINGS.getMovieDataSource()) { JMenuItem item = new JMenuItem(new MovieUpdateSingleDatasourceAction(ds)); menuUpdateDatasources.add(item); item = new JMenuItem(new MovieFindMissingAction(ds)); menuFindMissingMovies.add(item); } } }); menu.add(menuUpdateDatasources); menu.add(new MovieFindMissingAction()); menu.add(menuFindMissingMovies); menu.add(new MovieCreateOfflineAction(true)); menu.addSeparator(); JMenu menuScrape = new JMenu(BUNDLE.getString("Button.scrape")); //$NON-NLS-1$ menuScrape.setMnemonic(KeyEvent.VK_S); menuItem = menuScrape.add(actionScrape2); menuItem.setMnemonic(KeyEvent.VK_S); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuScrape.add(actionScrapeSelected); menuItem.setMnemonic(KeyEvent.VK_F); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuScrape.add(actionScrapeUnscraped); menuItem.setMnemonic(KeyEvent.VK_U); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuScrape.add(actionScrapeMetadataSelected); menuItem.setMnemonic(KeyEvent.VK_M); menuScrape.add(actionAssignMovieSets); menu.add(menuScrape); JMenu menuEdit = new JMenu(BUNDLE.getString("Button.edit")); //$NON-NLS-1$ menuEdit.setMnemonic(KeyEvent.VK_E); menuItem = menuEdit.add(actionEditMovie2); menuItem.setMnemonic(KeyEvent.VK_E); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuEdit.add(actionBatchEdit); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuEdit.add(actionSetWatchedFlag); menuItem.setMnemonic(KeyEvent.VK_W); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuEdit.add(actionRename2); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menuEdit.add(actionRenamerPreview); menuItem.setMnemonic(KeyEvent.VK_P); menu.add(menuEdit); menuItem = menu.add(actionRewriteNfo); menuItem.setMnemonic(KeyEvent.VK_N); menuItem = menu.add(actionTrailerDownload); menuItem = menu.add(actionSearchSubtitle); menuItem = menu.add(actionDownloadSubtitle); menu.addSeparator(); menuItem = menu.add(actionMediaInformation2); menuItem.setMnemonic(KeyEvent.VK_M); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menu.add(actionExport); menuItem.setMnemonic(KeyEvent.VK_X); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK)); menuItem = menu.add(actionRemove2); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.setAccelerator(KeyStroke.getKeyStroke((char) KeyEvent.VK_DELETE)); menuItem = menu.add(actionDelete2); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, ActionEvent.SHIFT_MASK)); menu.addSeparator(); menuItem = menu.add(actionSyncTrakt); menuItem.setMnemonic(KeyEvent.VK_T); menuItem = menu.add(actionSyncWatchedTrakt); menuItem.setMnemonic(KeyEvent.VK_W); menuItem = menu.add(actionSyncSelectedTrakt); menu.addSeparator(); menuItem = menu.add(actionClearImageCache); menuItem.setMnemonic(KeyEvent.VK_C); // popup menu JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(actionScrape2); popupMenu.add(actionScrapeSelected); popupMenu.add(actionScrapeUnscraped); popupMenu.add(actionScrapeMetadataSelected); popupMenu.add(actionAssignMovieSets); popupMenu.addSeparator(); popupMenu.add(actionEditMovie2); popupMenu.add(actionBatchEdit); popupMenu.add(actionSetWatchedFlag); popupMenu.add(actionRewriteNfo); popupMenu.add(actionRename2); popupMenu.add(actionRenamerPreview); popupMenu.add(actionMediaInformation2); popupMenu.add(actionExport); popupMenu.add(actionTrailerDownload); popupMenu.add(actionSearchSubtitle); popupMenu.add(actionDownloadSubtitle); popupMenu.addSeparator(); popupMenu.add(actionSyncTrakt); popupMenu.add(actionSyncWatchedTrakt); popupMenu.add(actionSyncSelectedTrakt); popupMenu.addSeparator(); popupMenu.add(actionClearImageCache); popupMenu.addSeparator(); popupMenu.add(actionRemove2); popupMenu.add(actionDelete2); if (Globals.isDebug()) { JMenu menuDebug = new JMenu("Debug"); //$NON-NLS-1$ menuDebug.add(debugDumpMovie); menuDebug.addSeparator(); menuDebug.add(new FakeTmmTaskAction("download", 1, 10)); menuDebug.add(new FakeTmmTaskAction("download", 10, 10)); menuDebug.add(new FakeTmmTaskAction("image", 1, 10)); menuDebug.add(new FakeTmmTaskAction("image", 10, 10)); menuDebug.add(new FakeTmmTaskAction("unnamed", 1, 10)); menuDebug.add(new FakeTmmTaskAction("unnamed", 10, 10)); popupMenu.add(menuDebug); } MouseListener mouseListener = new MovieTableMouseListener(popupMenu, table); table.addMouseListener(mouseListener); }
From source file:processing.app.Editor.java
protected void buildMenuBar() throws Exception { JMenuBar menubar = new JMenuBar(); final JMenu fileMenu = buildFileMenu(); fileMenu.addMenuListener(new StubMenuListener() { @Override/*from www .j a v a2s . c o m*/ public void menuSelected(MenuEvent e) { List<Component> components = Arrays.asList(fileMenu.getComponents()); if (!components.contains(sketchbookMenu)) { fileMenu.insert(sketchbookMenu, 2); } if (!components.contains(sketchbookMenu)) { fileMenu.insert(examplesMenu, 3); } fileMenu.revalidate(); validate(); } }); menubar.add(fileMenu); menubar.add(buildEditMenu()); final JMenu sketchMenu = new JMenu(_("Sketch")); sketchMenu.addMenuListener(new StubMenuListener() { @Override public void menuSelected(MenuEvent e) { buildSketchMenu(sketchMenu); sketchMenu.revalidate(); validate(); } }); buildSketchMenu(sketchMenu); menubar.add(sketchMenu); final JMenu toolsMenu = buildToolsMenu(); toolsMenu.addMenuListener(new StubMenuListener() { @Override public void menuSelected(MenuEvent e) { List<Component> components = Arrays.asList(fileMenu.getComponents()); int offset = 0; for (JMenu menu : base.getBoardsCustomMenus()) { if (!components.contains(menu)) { toolsMenu.insert(menu, numTools + offset); offset++; } } if (!components.contains(serialMenu)) { toolsMenu.insert(serialMenu, numTools + offset); } toolsMenu.revalidate(); validate(); } }); menubar.add(toolsMenu); menubar.add(buildHelpMenu()); setJMenuBar(menubar); }
From source file:savant.view.swing.FrameCommandBar.java
/** * Create Tools menu for commandBar. This is common to all track types. *//*from ww w . j a v a2 s . co m*/ private JMenu createToolsMenu() { JMenu menu = new JMenu("Tools"); JMenuItem item = new JCheckBoxMenuItem("Lock X Axis"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { graphPane.setLocked(!graphPane.isLocked()); } }); menu.add(item); // TODO: experimental feature which doesn't quite work yet final JMenuItem itemy = new JCheckBoxMenuItem("Lock Y Axis"); itemy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Trying to locking Y max: " + !itemy.isSelected()); graphPane.setYMaxLocked(itemy.isSelected()); } }); //menu.add(itemy); item = new JMenuItem("Copy URL to Clipboard"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(mainTrack.getDataSource().getURI().toString()), null); } }); menu.add(item); DataFormat df = mainTrack.getDataFormat(); if (df == DataFormat.SEQUENCE) { menu.add(new JSeparator()); JMenuItem copyItem = new JMenuItem("Copy Sequence to Clipboard"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { LocationController lc = LocationController.getInstance(); byte[] seq = ((SequenceTrack) mainTrack).getSequence(lc.getReferenceName(), lc.getRange()); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(new String(seq)), null); } catch (Throwable x) { LOG.error(x); DialogUtils.displayError("Unable to copy sequence to clipboard."); } } }); menu.add(copyItem); setAsGenomeButton = new JCheckBoxMenuItem("Set as Genome"); setAsGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Genome newGenome = Genome.createFromTrack(mainTrack); GenomeController.getInstance().setGenome(newGenome); } }); menu.add(setAsGenomeButton); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { Track seqTrack = (Track) GenomeController.getInstance().getGenome().getSequenceTrack(); if (seqTrack == mainTrack) { setAsGenomeButton.setSelected(true); setAsGenomeButton.setEnabled(false); setAsGenomeButton.setToolTipText("This track is already the reference sequence"); } else { setAsGenomeButton.setSelected(false); setAsGenomeButton.setEnabled(true); setAsGenomeButton.setToolTipText("Use this track as the reference sequence"); } } }); } else if (df == DataFormat.ALIGNMENT) { menu.add(new JSeparator()); item = new JMenuItem("Filter..."); item.setToolTipText("Control how records are filtered"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new BAMFilterDialog(DialogUtils.getMainWindow(), (BAMTrack) mainTrack).setVisible(true); } }); menu.add(item); } else if (df == DataFormat.RICH_INTERVAL) { menu.add(new JSeparator()); final JMenuItem bookmarkAll = new JMenuItem("Bookmark All Features"); bookmarkAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DataSource ds = (DataSource) mainTrack.getDataSource(); if (DialogUtils.askYesNo("Bookmark All Features ", String.format("This will create %d bookmarks. Are you sure you want to do this?", ds.getDictionaryCount())) == DialogUtils.YES) { ds.addDictionaryToBookmarks(); Savant.getInstance().displayBookmarksPanel(); } } }); menu.add(bookmarkAll); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { bookmarkAll.setEnabled(mainTrack.getDataSource() instanceof DataSource && ((DataSource) mainTrack.getDataSource()).getDictionaryCount() > 0); } }); } return menu; }
From source file:savant.view.swing.FrameCommandBar.java
private JMenu createAppearanceMenu() { JMenu menu = new JMenu("Appearance"); JMenuItem item = new JMenuItem("Colour Settings..."); item.addActionListener(new ActionListener() { @Override// w w w . jav a 2 s . co m public void actionPerformed(ActionEvent e) { SettingsDialog dlg = new SettingsDialog(DialogUtils.getMainWindow(), "Colour Settings", new TrackColourSchemePanel(mainTrack)); dlg.setVisible(true); } }); menu.add(item); DataFormat df = mainTrack.getDataFormat(); if (df != DataFormat.SEQUENCE) { scaleToFitItem = new JCheckBoxMenuItem("Scale to Fit"); scaleToFitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (scaleToFitItem.isSelected()) { graphPane.setScaledToFit(true); } else { // This check is kinda ugly, but we only want to set the interval height from the slider // if we're showing intervals (i.e. not arc mode and not coverage). if (intervalSlider != null && mainTrack.getDrawingMode() != DrawingMode.ARC && mainTrack.getDrawingMode() != DrawingMode.ARC_PAIRED && mainTrack.getResolution( LocationController.getInstance().getRange()) == Resolution.HIGH) { int h = getIntervalHeight(); graphPane.setUnitHeight(h); } graphPane.setScaledToFit(false); } } }); scaleToFitItem .setToolTipText("If selected, the track's display will be scaled to fit the available height."); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { scaleToFitItem.setSelected(graphPane.isScaledToFit()); } }); menu.add(scaleToFitItem); } if (df == DataFormat.RICH_INTERVAL) { menu.add(new JSeparator()); JCheckBoxMenuItem itemRGB = new JCheckBoxMenuItem("Enable ItemRGB"); itemRGB.setState(false); itemRGB.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleItemRGBEnabled(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(itemRGB); JCheckBoxMenuItem score = new JCheckBoxMenuItem("Enable Score"); score.setState(false); score.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleScoreEnabled(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(score); JCheckBoxMenuItem alternate = new JCheckBoxMenuItem("Display Alternate Name"); alternate.setState(((RichIntervalTrack) mainTrack).isUsingAlternateName()); alternate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleAlternateName(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(alternate); } else if (df == DataFormat.ALIGNMENT) { menu.add(new JSeparator()); baseQualityItem = new JCheckBoxMenuItem("Enable Base Quality"); baseQualityItem.setState(false); baseQualityItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (((BAMTrack) mainTrack).toggleBaseQualityEnabled()) { mappingQualityItem.setState(false); } graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(baseQualityItem); mappingQualityItem = new JCheckBoxMenuItem("Enable Mapping Quality"); mappingQualityItem.setState(false); mappingQualityItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (((BAMTrack) mainTrack).toggleMappingQualityEnabled()) { baseQualityItem.setState(false); } graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(mappingQualityItem); } return menu; }