Fixed possible name conflict when creating new themes.

This commit is contained in:
DieGurke 2019-12-25 21:43:59 +01:00
parent ded3782fea
commit 83ddbf5360

View File

@ -5,6 +5,7 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -118,7 +119,10 @@ public class ThemeCustomizationPanel extends SettingsPanel {
return (evt) -> {
if (themeChanged) {
try {
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
String name = "";
while (name == "") {
name = newName();
}
logger.log(Level.FINEST, name);
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
@ -229,4 +233,16 @@ public class ThemeCustomizationPanel extends SettingsPanel {
colorsPanel.add(button, gbc_button);
}
private String newName () {
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
for (Map.Entry<String, Theme> entry : Settings.getInstance().getThemes().entrySet()) {
System.out.println(entry.getKey().toString());
if(entry.getKey().equalsIgnoreCase(name)) {
JOptionPane.showMessageDialog(getParent(), "Name is already used! Please choose another one.");
return "";
}
}
return name;
}
}