Browse Source

Fix listeners not being notified.

pull/222/head
weisj 4 years ago
parent
commit
6cee4ac9b1
  1. 20
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java

20
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.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.swing.*; import javax.swing.*;
@ -74,6 +75,8 @@ public class ThemeSettingsPanel extends JPanel {
private ColoredRadioButton customSelection; private ColoredRadioButton customSelection;
private ColoredRadioButton defaultSelection; private ColoredRadioButton defaultSelection;
private final List<ChangeListener> listeners = new ArrayList<>();
public ThemeSettingsPanel() { public ThemeSettingsPanel() {
this.settingsConfiguration = new SettingsPanelConfiguration(); this.settingsConfiguration = new SettingsPanelConfiguration();
init(); init();
@ -104,7 +107,7 @@ public class ThemeSettingsPanel extends JPanel {
* @param listener the listener to add. * @param listener the listener to add.
*/ */
public void addChangeListener(final ChangeListener listener) { 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. * @param listener the listener to remove.
*/ */
public void removeChangeListener(final ChangeListener listener) { public void removeChangeListener(final ChangeListener listener) {
listenerList.remove(ChangeListener.class, listener); listeners.remove(listener);
} }
private void update() { private void update() {
@ -135,15 +138,10 @@ public class ThemeSettingsPanel extends JPanel {
themeComboBox.setEnabled(!settingsConfiguration.isThemeFollowsSystem()); themeComboBox.setEnabled(!settingsConfiguration.isThemeFollowsSystem());
fontSlider.setEnabled(!settingsConfiguration.isFontSizeFollowsSystem()); fontSlider.setEnabled(!settingsConfiguration.isFontSizeFollowsSystem());
Object[] listeners = listenerList.getListenerList(); if (!listeners.isEmpty()) {
ChangeEvent e = null; ChangeEvent e = new ChangeEvent(this);
for (ChangeListener listener : listeners) {
for (int i = listeners.length - 2; i >= 0; i -= 2) { listener.stateChanged(e);
if (listeners[i] == ChangeEvent.class) {
if (e == null) {
e = new ChangeEvent(this);
}
((ChangeListener) listeners[i + 1]).stateChanged(e);
} }
} }
} }

Loading…
Cancel
Save