Java Code Examples for javax.swing.event.MenuEvent

The following examples show how to use javax.swing.event.MenuEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mzmine2   Source File: AddFilePopupMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see javax.swing.event.MenuListener#menuSelected(javax.swing.event.MenuEvent)
 */
public void menuSelected(MenuEvent event) {

  // remove all menu items
  removeAll();

  // get all project files
  RawDataFile[] openFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
  List<RawDataFile> visualizedFiles = Arrays.asList(visualizer.getRawDataFiles());

  menuItemFiles = new Hashtable<JMenuItem, RawDataFile>();
  for (RawDataFile file : openFiles) {

    // if this file is already added, skip it
    if (visualizedFiles.contains(file))
      continue;

    // add a menu item for each file
    JMenuItem newItem = new JMenuItem(file.getName());
    newItem.addActionListener(this);
    menuItemFiles.put(newItem, file);
    add(newItem);
  }

}
 
Example 2
Source Project: libreveris   Source File: StepMenu.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void menuSelected (MenuEvent e)
{
    Sheet sheet = SheetsController.getCurrentSheet();
    boolean isIdle = (sheet != null)
                     && (sheet.getCurrentStep() == null);

    for (int i = 0; i < menu.getItemCount(); i++) {
        JMenuItem menuItem = menu.getItem(i);

        // Adjust the status for each step
        if (menuItem instanceof StepItem) {
            StepItem item = (StepItem) menuItem;
            item.displayState(sheet, isIdle);
        }
    }
}
 
Example 3
Source Project: gcs   Source File: RecentFilesMenu.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void menuSelected(MenuEvent event) {
    Preferences prefs                        = Preferences.getInstance();
    int         lastRecentFilesUpdateCounter = prefs.getLastRecentFilesUpdateCounter();
    if (mLastSeenRecentFilesUpdateCounter != lastRecentFilesUpdateCounter) {
        mLastSeenRecentFilesUpdateCounter = lastRecentFilesUpdateCounter;
        removeAll();
        List<Path> list = new ArrayList<>();
        for (Path path : prefs.getRecentFiles()) {
            if (Files.isReadable(path)) {
                list.add(path);
                add(new JMenuItem(new OpenDataFileCommand(PathUtils.getLeafName(path, false), path)));
                if (list.size() == Preferences.MAX_RECENT_FILES) {
                    break;
                }
            }
        }
        prefs.setRecentFiles(list);
        if (!list.isEmpty()) {
            addSeparator();
        }
        JMenuItem item = new JMenuItem(ClearRecentFilesMenuCommand.INSTANCE);
        ClearRecentFilesMenuCommand.INSTANCE.adjust();
        add(item);
    }
}
 
Example 4
Source Project: audiveris   Source File: StepMenu.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void menuSelected (MenuEvent e)
{
    SheetStub stub = StubsController.getCurrentStub();
    boolean isIdle = (stub != null) && (stub.getCurrentStep() == null);

    for (int i = 0; i < menu.getItemCount(); i++) {
        JMenuItem menuItem = menu.getItem(i);

        // Adjust the status for each step
        if (menuItem instanceof StepItem) {
            StepItem item = (StepItem) menuItem;
            item.displayState(stub, isIdle);
        }
    }
}
 
Example 5
Source Project: wildfly-core   Source File: TabsMenu.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void menuSelected(MenuEvent e) {
    TabsMenu.this.removeAll();
    ExploreNodeAction exploreAction = new ExploreNodeAction(cliGuiCtx);
    JMenuItem exploreSelectedNode = new JMenuItem(exploreAction);
    exploreSelectedNode.setMnemonic(KeyEvent.VK_E);

    if ((exploreAction.getSelectedNode() == null) || exploreAction.getSelectedNode().isLeaf()) {
        exploreSelectedNode.setEnabled(false);
    }

    add(exploreSelectedNode);
    addSeparator();

    JTabbedPane tabs = cliGuiCtx.getTabs();
    for (int i=0; i < tabs.getTabCount(); i++) {
        GoToTabAction action = new GoToTabAction(i, tabs.getTitleAt(i));
        JMenuItem item = new JMenuItem(action);
        item.setToolTipText(tabs.getToolTipTextAt(i));
        add(item);
    }
}
 
Example 6
Source Project: mzmine2   Source File: WindowsMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void menuSelected(MenuEvent event) {

    // Remove all previous items
    while (getItemCount() > 2)
      remove(2);

    int windowsAdded = 0;
    // Create a menu item for each window
    for (Frame window : Frame.getFrames()) {

      if (window.isVisible()) {
        FrameMenuItem newItem = new FrameMenuItem(window, this);
        add(newItem);
        windowsAdded++;
      }
    }

    // Disable the Close all button if we only have the main window
    closeAllMenuItem.setEnabled(windowsAdded > 1);
  }
 
Example 7
Source Project: mars-sim   Source File: MainWindowMenu.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** MenuListener method overriding. */
@Override
public final void menuSelected(MenuEvent event) {
	MainDesktopPane desktop = mainWindow.getDesktop();
	marsNavigatorItem.setSelected(desktop.isToolWindowOpen(NavigatorWindow.NAME));
	searchToolItem.setSelected(desktop.isToolWindowOpen(SearchWindow.NAME));
	timeToolItem.setSelected(desktop.isToolWindowOpen(TimeWindow.NAME));
	monitorToolItem.setSelected(desktop.isToolWindowOpen(MonitorWindow.NAME));
	missionToolItem.setSelected(desktop.isToolWindowOpen(MissionWindow.NAME));
	settlementToolItem.setSelected(desktop.isToolWindowOpen(SettlementWindow.NAME));
	scienceToolItem.setSelected(desktop.isToolWindowOpen(ScienceWindow.NAME));
	resupplyToolItem.setSelected(desktop.isToolWindowOpen(ResupplyWindow.NAME));
	commanderDashboardItem.setSelected(desktop.isToolWindowOpen(CommanderWindow.NAME));
	
	showUnitBarItem.setSelected(desktop.getMainWindow().getUnitToolBar().isVisible());
	showToolBarItem.setSelected(desktop.getMainWindow().getToolToolBar().isVisible());

	musicVolumeSlider.setValue((int) Math.round(soundPlayer.getMusicVolume() * 10));
	musicVolumeSlider.setEnabled(!soundPlayer.isMusicMute());
	effectVolumeSlider.setValue((int) Math.round(soundPlayer.getEffectVolume() * 10));
	effectVolumeSlider.setEnabled(!soundPlayer.isSoundMute());
	musicMuteItem.setSelected(soundPlayer.isMusicMute());
	effectMuteItem.setSelected(soundPlayer.isSoundMute());
}
 
Example 8
@Override
public void menuSelected (MenuEvent e)
{
    // Clean up the whole menu
    menu.removeAll();

    // Rebuild the whole list of menu items on the fly
    buildItems();
}
 
Example 9
Source Project: gcs   Source File: DynamicMenuEnabler.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void menuSelected(MenuEvent event) {
    JMenu menu = (JMenu) event.getSource();
    for (Component component : menu.getMenuComponents()) {
        if (component instanceof JMenuItem) {
            JMenuItem item   = (JMenuItem) component;
            Action    action = item.getAction();
            if (action instanceof Command) {
                ((Command) action).adjust();
            }
        }
    }
}
 
Example 10
Source Project: consulo   Source File: ActionMenu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void menuCanceled(MenuEvent e) {
  if (isTopMenuBarAfterOpenJDKMemLeakFix()) {
    myMenuComponents = new Component[]{myStubItem};
  }
  else {
    clearItems();
  }
}
 
Example 11
Source Project: gcs   Source File: LibraryMenu.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void menuSelected(MenuEvent event) {
    removeAll();
    for (Library lib : Library.LIBRARIES) {
        if (lib != Library.USER) {
            LibraryUpdateCommand item = new LibraryUpdateCommand(lib);
            item.adjust();
            add(new JMenuItem(item));
        }
        add(new JMenuItem(new ShowLibraryFolderCommand(lib)));
        addSeparator();
    }
    add(new JMenuItem(ChangeLibraryLocationsCommand.INSTANCE));
}
 
Example 12
Source Project: audiveris   Source File: DynamicMenu.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void menuSelected (MenuEvent e)
{
    // Clean up the whole menu
    menu.removeAll();

    // Rebuild the whole list of menu items on the fly
    buildItems();
}
 
Example 13
Source Project: audiveris   Source File: NameSet.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Feed a menu with the dynamic content of this NameSet.
 *
 * @param menu         the menu to be fed, if null it is allocated by this method
 * @param itemListener the listener to be called on item selection
 * @return the menu properly dynamized
 */
public JMenu feedMenu (JMenu menu,
                       final ActionListener itemListener)
{
    final JMenu finalMenu = (menu != null) ? menu : new JMenu(setName);

    MenuListener menuListener = new AbstractMenuListener()
    {
        @Override
        public void menuSelected (MenuEvent e)
        {
            // Clean up the whole menu
            finalMenu.removeAll();

            // Rebuild the whole list of menu items on the fly
            synchronized (NameSet.this) {
                for (String f : names) {
                    JMenuItem menuItem = new JMenuItem(f);
                    menuItem.addActionListener(itemListener);
                    finalMenu.add(menuItem);
                }
            }
        }
    };

    // Listener to menu selection, to modify content on-the-fly
    finalMenu.addMenuListener(menuListener);

    return finalMenu;
}
 
Example 14
Source Project: tda   Source File: TDA.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * check file menu
 */
public void menuSelected(MenuEvent e) {
    JMenu source = (JMenu) e.getSource();
    if((source != null) && "File".equals(source.getText())) {
        // close menu item only active, if something is selected.
        getMainMenu().getCloseMenuItem().setEnabled(tree.getSelectionPath() != null);
        getMainMenu().getCloseToolBarButton().setEnabled(tree.getSelectionPath() != null);
    }
}
 
Example 15
Source Project: mars-sim   Source File: NotificationMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** MenuListener method overriding. */
@Override
public final void menuSelected(MenuEvent event) {
	//MainDesktopPane desktop = mainWindow.getDesktop();

	//notificationItem.setSelected(desktop.getMainWindow().getNotification());

	//volumeItem.setValue(Math.round(desktop.getSoundPlayer().getVolume() * 10F));
	//volumeItem.setEnabled(!desktop.getSoundPlayer().isMute());
	//muteItem.setSelected(desktop.getSoundPlayer().isMute());
}
 
Example 16
Source Project: zxpoly   Source File: MainFrame.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void menuEditMenuSelected(javax.swing.event.MenuEvent evt) {
  this.toolsButtonGroup.clearSelection();
  this.menuEditSelectArea.setEnabled(this.mainEditor.hasData());
  this.menuEditPasteImage.setEnabled(GfxUtils.doesClipboardHasImage());
  this.menuEditCopySelectedBaseAsImage.setEnabled(this.mainEditor.hasSelectedArea());
  this.menuEditCopySelectedZxPolyAsImage.setEnabled(this.mainEditor.hasSelectedArea());
}
 
Example 17
Source Project: consulo   Source File: ActionMenu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void menuSelected(MenuEvent e) {
  if (isTopMenuBarAfterOpenJDKMemLeakFix()) {
    myMenuComponents = null;
  }
  else {
    fillMenu(ActionMenu.this);
  }
}
 
Example 18
Source Project: zxpoly   Source File: MainForm.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void menuFileMenuSelected(final MenuEvent evt) {
  boolean hasChangedDisk = false;
  for (int i = 0; i < 4; i++) {
    final TrDosDisk disk = this.board.getBetaDiskInterface().getDiskInDrive(i);
    hasChangedDisk |= (disk != null && disk.isChanged());
  }
  this.menuFileFlushDiskChanges.setEnabled(hasChangedDisk);
}
 
Example 19
@Override
public void menuDeselected (MenuEvent e)
{
}
 
Example 20
Source Project: dragonwell8_jdk   Source File: bug4983388.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void menuSelected(MenuEvent e) {
    System.out.println("menuSelected");
    bMenuSelected = true;
}
 
Example 21
Source Project: wildfly-core   Source File: TabsMenu.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
public void menuCanceled(MenuEvent e) {
}
 
Example 22
Source Project: TencentKona-8   Source File: bug4983388.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void menuSelected(MenuEvent e) {
    System.out.println("menuSelected");
    bMenuSelected = true;
}
 
Example 23
Source Project: jdk8u60   Source File: bug4983388.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void menuSelected(MenuEvent e) {
    System.out.println("menuSelected");
    bMenuSelected = true;
}
 
Example 24
Source Project: libreveris   Source File: StepMenu.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void menuCanceled (MenuEvent e)
{
}
 
Example 25
Source Project: wildfly-core   Source File: TabsMenu.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
public void menuDeselected(MenuEvent e) {
}
 
Example 26
Source Project: mzmine2   Source File: AddFilePopupMenu.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.event.MenuListener#menuDeselected(javax.swing.event.MenuEvent)
 */
public void menuDeselected(MenuEvent arg0) {
  // do nothing
}
 
Example 27
Source Project: netbeans   Source File: AbstractMenuFactory.java    License: Apache License 2.0 4 votes vote down vote up
public void menuDeselected(MenuEvent e) {
}
 
Example 28
Source Project: netbeans   Source File: AbstractMenuFactory.java    License: Apache License 2.0 4 votes vote down vote up
public void menuSelected(MenuEvent e) {
}
 
Example 29
Source Project: org.alloytools.alloy   Source File: Runner.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This method is defined in javax.swing.event.MenuListener; (this
 * implementation calls this.run())
 */
@Override
public final void menuSelected(MenuEvent e) {
    run();
}
 
Example 30
public void menuSelected(MenuEvent e) {
    System.out.println("menuSelected");
    bMenuSelected = true;
}