mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Add Theme submenu to Layout menu
This commit is contained in:
@@ -218,20 +218,14 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
|
||||
private void initializeSkinsComboBox() {
|
||||
FPref userSetting = FPref.UI_SKIN;
|
||||
FComboBoxPanel<String> panel = this.view.getSkinsComboBoxPanel();
|
||||
String[] installedSkins = getSortedListOfInstalledSkins();
|
||||
validatePreferredSkinName(installedSkins);
|
||||
JComboBox<String> comboBox = createComboBox(installedSkins, userSetting);
|
||||
FComboBoxPanel<String> panel = this.view.getSkinsComboBoxPanel();
|
||||
String[] installedSkins = FSkin.getSkinNamesArray(true);
|
||||
validatePreferredSkinName(installedSkins);
|
||||
JComboBox<String> comboBox = createComboBox(installedSkins, userSetting);
|
||||
String selectedItem = this.prefs.getPref(userSetting);
|
||||
panel.setComboBox(comboBox, selectedItem);
|
||||
panel.setComboBox(comboBox, selectedItem);
|
||||
}
|
||||
|
||||
private String[] getSortedListOfInstalledSkins() {
|
||||
String[] skins = FSkin.getSkinNamesArray();
|
||||
java.util.Arrays.sort(skins);
|
||||
return skins;
|
||||
}
|
||||
|
||||
|
||||
private void validatePreferredSkinName(String[] installedSkins) {
|
||||
String preferredSkin = this.prefs.getPref(FPref.UI_SKIN);
|
||||
if (!Arrays.asList(installedSkins).contains(preferredSkin)) {
|
||||
|
||||
@@ -5,11 +5,15 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.control.RestartUtil;
|
||||
import forge.control.FControl.Screens;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.match.controllers.CDock;
|
||||
@@ -40,8 +44,9 @@ public final class LayoutMenu {
|
||||
if (currentScreen != Screens.HOME_SCREEN) {
|
||||
menu.add(getMenu_ViewOptions());
|
||||
menu.add(getMenu_FileOptions());
|
||||
menu.addSeparator();
|
||||
}
|
||||
menu.add(getMenu_ThemeOptions());
|
||||
menu.addSeparator();
|
||||
menu.add(getMenuItem_SetWindowSize());
|
||||
if (currentScreen != Screens.HOME_SCREEN) {
|
||||
menu.add(getMenuItem_RevertLayout());
|
||||
@@ -65,6 +70,49 @@ public final class LayoutMenu {
|
||||
return menu;
|
||||
}
|
||||
|
||||
private static JMenu getMenu_ThemeOptions() {
|
||||
JMenu menu = new JMenu("Theme");
|
||||
JRadioButtonMenuItem menuItem;
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
String currentSkin = prefs.getPref(FPref.UI_SKIN);
|
||||
String[] skins = FSkin.getSkinNamesArray(true);
|
||||
for (String skin : skins) {
|
||||
menuItem = new JRadioButtonMenuItem(skin);
|
||||
group.add(menuItem);
|
||||
if (skin.equals(currentSkin)) {
|
||||
menuItem.setSelected(true);
|
||||
}
|
||||
menuItem.setActionCommand(skin);
|
||||
menuItem.addActionListener(changeSkin);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
return menu;
|
||||
}
|
||||
|
||||
private static final ActionListener changeSkin = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String skin = e.getActionCommand();
|
||||
if (!skin.equals(prefs.getPref(FPref.UI_SKIN))) {
|
||||
prefs.setPref(FPref.UI_SKIN, skin);
|
||||
prefs.save();
|
||||
|
||||
Object[] options = {"Restart Now", "Restart Later"};
|
||||
int reply = JOptionPane.showOptionDialog(
|
||||
null,
|
||||
"You must restart Forge for " + skin + " theme to take effect.",
|
||||
"Change Theme",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (reply == JOptionPane.YES_OPTION) {
|
||||
RestartUtil.restartApplication(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static JMenuItem getMenuItem_ShowBackgroundImage() {
|
||||
final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem("Background Image");
|
||||
|
||||
@@ -786,12 +786,15 @@ public enum FSkin {
|
||||
return mySkins;
|
||||
}
|
||||
|
||||
public static String[] getSkinNamesArray() {
|
||||
public static String[] getSkinNamesArray(boolean sorted) {
|
||||
ArrayList<String> skinDirectoryNames = getSkinDirectoryNames();
|
||||
String[] prettySkinNames = new String[skinDirectoryNames.size()];
|
||||
for (int i = 0; i < skinDirectoryNames.size(); i++) {
|
||||
prettySkinNames[i] = WordUtils.capitalize(skinDirectoryNames.get(i).replace('_', ' '));
|
||||
}
|
||||
if (sorted) {
|
||||
java.util.Arrays.sort(prettySkinNames);
|
||||
}
|
||||
return prettySkinNames;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user