diff --git a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java index c07bc56..19cceb0 100644 --- a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java +++ b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java @@ -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 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; + } } \ No newline at end of file