Java Code Examples for javax.swing.JRadioButtonMenuItem

The following examples show how to use javax.swing.JRadioButtonMenuItem. 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
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 2
Source Project: jdk8u-jdk   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 3
Source Project: TencentKona-8   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 4
Source Project: jdk8u60   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 5
Source Project: visualvm   Source File: ButtonBuilders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JButton.class.getName())) {
        return new JButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBox.class.getName())) {
        return new JCheckBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButton.class.getName())) {
        return new JRadioButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToggleButton.class.getName())) {
        return new JToggleButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBoxMenuItem.class.getName())) {
        return new JCheckBoxMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButtonMenuItem.class.getName())) {
        return new JRadioButtonMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenu.class.getName())) {
        return new JMenuBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuBar.class.getName())) {
        return new JMenuBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuItem.class.getName())) {
        return new JMenuItemBuilder(instance, heap);
    }
    return null;
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 7
Source Project: netbeans   Source File: DropTargetLayer.java    License: Apache License 2.0 6 votes vote down vote up
private static int getIconLeft(JMenuItem item) {
    if(Utilities.isWindows()) {
        if(isVista()) {
            return 1;
        }
        if(hasRadioOrCheckSibling(item)) {
            return 20;
        } else {
            return 20;
        }
    }
    
    if(isAqua()) {
        if(item instanceof JRadioButtonMenuItem) {
            return 11;
        }
        return 14;
    }
    
    //metal or other (hopefully) basic derived L&Fs
    if(isRadioOrCheck(item)) {
        return 20;
    }
    return 10;
}
 
Example 8
Source Project: netbeans   Source File: DebuggingActionsProvider.java    License: Apache License 2.0 6 votes vote down vote up
public JMenuItem getPopupPresenter() {
    JMenu displayAsPopup = new JMenu();
    Mnemonics.setLocalizedText(displayAsPopup, NbBundle.getMessage(DebuggingActionsProvider.class, "CTL_Session_Popup_Language"));

    String [] languages = session.getSupportedLanguages();
    String currentLanguage = session.getCurrentLanguage();
    for (int i = 0; i < languages.length; i++) {
        final String language = languages[i];
        JRadioButtonMenuItem langItem = new JRadioButtonMenuItem(new AbstractAction(language) {
            public void actionPerformed(ActionEvent e) {
                session.setCurrentLanguage(language);
            }
        });
        if (currentLanguage.equals(language)) langItem.setSelected(true);
        displayAsPopup.add(langItem);
    }
    return displayAsPopup;
}
 
Example 9
Source Project: Shuffle-Move   Source File: ShuffleMenuBar.java    License: GNU General Public License v3.0 6 votes vote down vote up
private JMenu makeGradingMenu() {
   JMenu menu = new JMenu(getString(KEY_GRADING_MENU));
   buttonToi18nKeyMap.put(menu, () -> getString(KEY_GRADING_MENU));
   GradingMode selectedMode = getUser().getCurrentGradingMode();
   ButtonGroup group = new ButtonGroup();
   modeMap = new HashMap<GradingMode, AbstractButton>();
   for (GradingMode mode : getUser().getGradingModeManager().getGradingModeValues()) {
      String text = mode.geti18nString();
      JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(new AbstractAction(text) {
         @Override
         public void actionPerformed(ActionEvent e) {
            getUser().setGradingMode(mode);
         }
      });
      if (mode.equals(selectedMode)) {
         menuItem.setSelected(true);
      }
      group.add(menuItem);
      menu.add(menuItem);
      modeMap.put(mode, menuItem);
      buttonToi18nKeyMap.put(menuItem, () -> mode.geti18nString());
   }
   return menu;
}
 
Example 10
Source Project: netbeans   Source File: ButtonBuilders.java    License: Apache License 2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JButton.class.getName())) {
        return new JButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBox.class.getName())) {
        return new JCheckBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButton.class.getName())) {
        return new JRadioButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToggleButton.class.getName())) {
        return new JToggleButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBoxMenuItem.class.getName())) {
        return new JCheckBoxMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButtonMenuItem.class.getName())) {
        return new JRadioButtonMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenu.class.getName())) {
        return new JMenuBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuBar.class.getName())) {
        return new JMenuBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuItem.class.getName())) {
        return new JMenuItemBuilder(instance, heap);
    }
    return null;
}
 
Example 11
protected void processAction(TGActionContext context) {
	final AWTEvent awtEvent = context.getAttribute(AWTEvent.class.getName());
	
	final Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
	final JButton button = (JButton) awtEvent.getSource();
	final JPopupMenu menu = new JPopupMenu();
	Iterator<?> it = TuxGuitar.instance().getTablatureEditor().getTablature().getSong().getTracks();
	while( it.hasNext() ){
		final TGTrack track = (TGTrack) it.next();
		JMenuItem item = new JRadioButtonMenuItem( track.getName() , (track.getNumber() == caret.getTrack().getNumber()) );
		item.setFont( TGConfig.FONT_WIDGETS );
		item.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				caret.update( track.getNumber() );
				TuxGuitar.instance().updateCache( true );
			}
		});
		menu.add( item );
	}
	menu.show(button, 0, button.getHeight() );
}
 
Example 12
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 13
Source Project: hottub   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 14
Source Project: openjdk-jdk9   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 15
Source Project: jdk8u-jdk   Source File: MetalThemeMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 16
@SuppressWarnings("LeakingThisInConstructor")
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themes = themeArray;
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < themes.length; i++) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].
                getName());
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);
        if (i == 0) {
            item.setSelected(true);
        }
    }

}
 
Example 17
Source Project: Carcassonne   Source File: MainMenuBar.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void buildHandMenu() {
    JMenuItem[] itemTiles = new JRadioButtonMenuItem[GameSettings.MAXIMAL_TILES_ON_HAND];
    menuHand = new JMenu(HAND_SETTINGS);
    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < itemTiles.length; i++) {
        int numberOfTiles = i + 1;
        String itemText = numberOfTiles + TILES_PER_PLAYER;
        if (numberOfTiles == 1) {
            itemText += CLASSIC;
        }
        itemTiles[i] = new JRadioButtonMenuItem(itemText);
        itemTiles[i].addActionListener(event -> settings.setTilesPerPlayer(numberOfTiles));
        group.add(itemTiles[i]);
        menuHand.add(itemTiles[i]);
    }
    itemTiles[settings.getTilesPerPlayer() - 1].setSelected(true);
}
 
Example 18
Source Project: material-ui-swing   Source File: MaterialRadioButtonMenuItemUI.java    License: MIT License 5 votes vote down vote up
@Override
protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
	JRadioButtonMenuItem j = (JRadioButtonMenuItem) c;
	if (j.isSelected ()) {
		super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), c, UIManager.getIcon ("RadioButtonMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap);
		return;
	}
	super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), c, UIManager.getIcon ("RadioButtonMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap);
}
 
Example 19
Source Project: raccoon4   Source File: ProfilesMenuBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onDataSetChange(DatasetEvent event) {
	if (event instanceof PlayProfileEvent) {
		PlayProfileEvent ppe = (PlayProfileEvent) event;
		if (ppe.isConnection()) {
			boolean a = ppe.isActivation();
			edit.setEnabled(a);
			delete.setEnabled(a);
		}
		menu.removeAll();
		PlayProfileDao dao = (PlayProfileDao) event.getSource();
		List<PlayProfile> profiles = dao.list();
		PlayProfile def = dao.get();
		ButtonGroup bg = new ButtonGroup();

		for (PlayProfile profile : profiles) {
			ProfileAction pa = new ProfileAction(globals, profile);
			JRadioButtonMenuItem item = new JRadioButtonMenuItem(pa);
			bg.add(item);
			menu.add(item);
			item.setSelected(def != null
					&& def.getAlias().equals(profile.getAlias()));
		}
		menu.add(new JSeparator());
		menu.add(add);
		menu.add(edit);
		menu.add(delete);
	}
}
 
Example 20
Source Project: JCEditor   Source File: JCEditor.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
* Método que cria os JRadioButtonMenuItem(s)
* @param nome String - nome do menu
* @param ev ActionListener - evento que será executado ao pressionar o menu
* @param bg ButtonGroup - grupo a qual o menu pertence (não é possível ter mais de um selecionado)
* @param mPrincipal - menu ao qual o menu de rádio pertence
*/
private JRadioButtonMenuItem configRadioMenus(String nome, ActionListener ev, ButtonGroup bg, JMenu mPrincipal) {
	JRadioButtonMenuItem menu = new JRadioButtonMenuItem(nome);
	menu.addActionListener(ev);
	menu.setFont(roboto);
	bg.add(menu);

	mPrincipal.add(menu);
	return menu;
}
 
Example 21
Source Project: netbeans   Source File: MenuEditLayer.java    License: Apache License 2.0 5 votes vote down vote up
private String getComponentDefaultsPrefix(JComponent c) {
    if(c instanceof JMenuBar) {
        return "MenuBar"; // NOI18N
    }
    if(c instanceof JMenu) {
        return "Menu"; // NOI18N
    }
    if(c instanceof JCheckBoxMenuItem) {
        return "CheckBoxMenuItem"; // NOI18N
    }
    if(c instanceof JRadioButtonMenuItem) {
        return "RadioButtonMenuItem"; // NOI18N
    }
    return "MenuItem"; // NOI18N
}
 
Example 22
Source Project: netbeans   Source File: VariablesSwitchViewAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenu viewAsPopup = new JMenu(NbBundle.getMessage(SwitchViewAction.class, "CTL_ViewAs_Popup"));
    JRadioButtonMenuItem tableView = new ViewAsMenuItem(VIEW_TYPE_TABLE);
    JRadioButtonMenuItem treeView = new ViewAsMenuItem(VIEW_TYPE_TREE);
    String type = preferences.get(VIEW_TYPE, null);
    if (type == null || type.equals(VIEW_TYPE_TABLE)) {
        tableView.setSelected(true);
    } else {
        treeView.setSelected(true);
    }
    viewAsPopup.add(tableView);
    viewAsPopup.add(treeView);
    return viewAsPopup;
}
 
Example 23
Source Project: triplea   Source File: JMenuItemBuilder.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Constructs a Swing JRadioButtonMenuItem using current builder values. */
public JRadioButtonMenuItem buildRadio(final ButtonGroup group) {
  final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(title, selected);
  buildImpl(menuItem);
  group.add(menuItem);
  return menuItem;
}
 
Example 24
Source Project: beautyeye   Source File: SwingSet2.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a radio button menu menu item for items that are part of a
 * button group.
 *
 * @param menu the menu
 * @param label the label
 * @param mnemonic the mnemonic
 * @param accessibleDescription the accessible description
 * @param action the action
 * @param buttonGroup the button group
 * @return the j menu item
 */
private JMenuItem createButtonGroupMenuItem(JMenu menu, String label,
		String mnemonic,
		String accessibleDescription,
		Action action,
		ButtonGroup buttonGroup) {
	JRadioButtonMenuItem mi = (JRadioButtonMenuItem)menu.add(
			new JRadioButtonMenuItem(getString(label)));
	buttonGroup.add(mi);
	mi.setMnemonic(getMnemonic(mnemonic));
	mi.getAccessibleContext().setAccessibleDescription(getString(
			accessibleDescription));
	mi.addActionListener(action);
	return mi;
}
 
Example 25
Source Project: netbeans   Source File: WorkspaceSwitchAction.java    License: Apache License 2.0 5 votes vote down vote up
/** Frees all listeners etc from given workspace. */
void detachWorkspace(
    Workspace workspace, Hashtable workspace2Menu, Hashtable menu2Workspace, Hashtable workspace2Listener,
    JMenu menu
) {
    JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) workspace2Menu.get(workspace);
    workspace2Menu.remove(workspace);
    menu2Workspace.remove(workspace2Listener.get(workspace));
    workspace2Listener.remove(workspace);
    menu.remove(menuItem);
}
 
Example 26
Source Project: netbeans   Source File: KarmaChildrenList.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JComponent[] getMenuPresenters() {
    removeAll();
    // #238803
    File configDir = KarmaUtils.getKarmaConfigDir(project);
    List<File> configs = KarmaUtils.findKarmaConfigs(configDir);
    if (configs.isEmpty()) {
        configs = KarmaUtils.findJsFiles(configDir);
    }
    configs = FileUtils.sortFiles(configs);
    if (!configs.isEmpty()) {
        String activeConfig = KarmaPreferences.getConfig(project);
        for (final File config : configs) {
            boolean selected = config.getAbsolutePath().equals(activeConfig);
            JRadioButtonMenuItem configItem = new JRadioButtonMenuItem(config.getName(), selected);
            configItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    KarmaPreferences.setConfig(project, config.getAbsolutePath());
                }
            });
            add(configItem);
        }
    } else {
        setEnabled(false);
    }
    return new JComponent[] {this};
}
 
Example 27
Source Project: pumpernickel   Source File: ContextualMenuHelper.java    License: MIT License 5 votes vote down vote up
/**
 * 
 * @param popupName
 * @param property
 * @param runnable
 *            an optional runnable to invoke when the property changes. This
 *            may be null.
 * @return
 */
public JMenu addPopupMenu(String popupName, final EnumProperty property,
		final Runnable runnable) {
	Object[] values = property.getValues();
	JMenu myPopup = new JMenu(popupName);
	for (int a = 0; a < values.length; a++) {
		final Object currentValue = values[a];
		final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(
				currentValue.toString());
		myPopup.add(menuItem);
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				property.setValue(currentValue);
				if (runnable != null)
					SwingUtilities.invokeLater(runnable);
			}
		});

		property.addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent evt) {
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						menuItem.setSelected(currentValue.equals(property
								.getValue()));
					}
				});
				if (runnable != null)
					SwingUtilities.invokeLater(runnable);
			}
		});
		menuItem.setSelected(currentValue.equals(property.getValue()));
	}
	popup.add(myPopup);
	return myPopup;
}
 
Example 28
Source Project: netbeans   Source File: ActionPopupButton.java    License: Apache License 2.0 5 votes vote down vote up
protected void populatePopup(JPopupMenu popup) {
    for (final Action _action : actions) {
        if (_action != null) {
            popup.add(new JRadioButtonMenuItem(_action.getValue(Action.NAME).toString(), _action == action) {
                protected void fireActionPerformed(ActionEvent e) {
                    selectAction(_action);
                    _action.actionPerformed(e);
                }
            });
        } else {
            popup.addSeparator();
        }
    }
}
 
Example 29
Source Project: netbeans   Source File: SetMainProject.java    License: Apache License 2.0 5 votes vote down vote up
private void checkProjectNames() {
    for(Component componentIter : subMenu.getMenuComponents()) {
        if(componentIter instanceof JRadioButtonMenuItem) {
            JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) componentIter;
            Project projectIter = getItemProject(menuItem);
            if(projectIter != null && !ProjectUtils.getInformation(projectIter).getDisplayName().equals(menuItem.getText())) {
                menuItem.setText(ProjectUtils.getInformation(projectIter).getDisplayName());
            }
        }
    }
}
 
Example 30
Source Project: triplea   Source File: ViewMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addMapSkinsMenu() {
  final JMenu mapSubMenu = new JMenu("Map Skins");
  mapSubMenu.setMnemonic(KeyEvent.VK_K);
  add(mapSubMenu);
  final ButtonGroup mapButtonGroup = new ButtonGroup();
  final Map<String, String> skins = AbstractUiContext.getSkins(frame.getGame().getData());
  mapSubMenu.setEnabled(skins.size() > 1);
  for (final String key : skins.keySet()) {
    final JMenuItem mapMenuItem = new JRadioButtonMenuItem(key);
    mapButtonGroup.add(mapMenuItem);
    mapSubMenu.add(mapMenuItem);
    if (skins.get(key).equals(AbstractUiContext.getMapDir())) {
      mapMenuItem.setSelected(true);
    }
    mapMenuItem.addActionListener(
        e -> {
          try {
            frame.updateMap(skins.get(key));
            if (uiContext.getMapData().getHasRelief()) {
              showMapDetails.setSelected(true);
            }
            showMapDetails.setEnabled(uiContext.getMapData().getHasRelief());
          } catch (final Exception exception) {
            log.log(Level.SEVERE, "Error Changing Map Skin2", exception);
          }
        });
  }
}