From 83ddbf5360999137e8861d0ef71039f92a633940 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Wed, 25 Dec 2019 21:43:59 +0100 Subject: [PATCH] Fixed possible name conflict when creating new themes. --- .../ui/settings/ThemeCustomizationPanel.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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