From 6cee4ac9b17ee051eea8fe6ade6f95dfa75b94d4 Mon Sep 17 00:00:00 2001 From: weisj Date: Mon, 30 Nov 2020 23:16:55 +0100 Subject: [PATCH] Fix listeners not being notified. --- .../darklaf/settings/ThemeSettingsPanel.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java index 1b174196..e167107c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.settings; import java.awt.*; import java.awt.event.MouseEvent; import java.util.*; +import java.util.List; import java.util.function.Supplier; import javax.swing.*; @@ -74,6 +75,8 @@ public class ThemeSettingsPanel extends JPanel { private ColoredRadioButton customSelection; private ColoredRadioButton defaultSelection; + private final List listeners = new ArrayList<>(); + public ThemeSettingsPanel() { this.settingsConfiguration = new SettingsPanelConfiguration(); init(); @@ -104,7 +107,7 @@ public class ThemeSettingsPanel extends JPanel { * @param listener the listener to add. */ public void addChangeListener(final ChangeListener listener) { - listenerList.add(ChangeListener.class, listener); + listeners.add(listener); } /** @@ -113,7 +116,7 @@ public class ThemeSettingsPanel extends JPanel { * @param listener the listener to remove. */ public void removeChangeListener(final ChangeListener listener) { - listenerList.remove(ChangeListener.class, listener); + listeners.remove(listener); } private void update() { @@ -135,15 +138,10 @@ public class ThemeSettingsPanel extends JPanel { themeComboBox.setEnabled(!settingsConfiguration.isThemeFollowsSystem()); fontSlider.setEnabled(!settingsConfiguration.isFontSizeFollowsSystem()); - Object[] listeners = listenerList.getListenerList(); - ChangeEvent e = null; - - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ChangeEvent.class) { - if (e == null) { - e = new ChangeEvent(this); - } - ((ChangeListener) listeners[i + 1]).stateChanged(e); + if (!listeners.isEmpty()) { + ChangeEvent e = new ChangeEvent(this); + for (ChangeListener listener : listeners) { + listener.stateChanged(e); } } }