Skip to content

Commit

Permalink
Docking UI extension settings icon color can now be set to a differen…
Browse files Browse the repository at this point in the history
…t UIManager property. (#154)
  • Loading branch information
andrewauclair authored Dec 16, 2023
1 parent 57c8615 commit 2af17b0
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions docking-ui/src/ModernDocking/ext/ui/DockingUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ of this software and associated documentation files (the "Software"), to deal

import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeListener;

public class DockingUI {
private static boolean initialized = false;
private static PropertyChangeListener propertyChangeListener;
private static FlatSVGIcon settingsIcon = new FlatSVGIcon(DockingUI.class.getResource("/ui_ext_icons/settings.svg"));

/**
* Initialize the FlatLaf UI extension. This reconfigures the docking framework to use FlatLaf SVG icons and color filters.
Expand All @@ -42,8 +45,6 @@ public static void initialize() {

DockingInternal.createHeaderUI = FlatLafHeaderUI::new;

FlatSVGIcon settingsIcon = new FlatSVGIcon(DockingUI.class.getResource("/ui_ext_icons/settings.svg"));

if (!settingsIcon.hasFound()) {
throw new RuntimeException("settings.svg icon not found");
}
Expand All @@ -54,13 +55,40 @@ public static void initialize() {

settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground));

UIManager.addPropertyChangeListener(e -> {
propertyChangeListener = e -> {
if ("lookAndFeel".equals(e.getPropertyName())) {
SwingUtilities.invokeLater(() -> {
Color newForeground = UIManager.getColor("TableHeader.foreground");
settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> newForeground));
});
}
};
UIManager.addPropertyChangeListener(propertyChangeListener);
}

public static void setSettingsIconColorProperty(String property) {
if (!initialized) {
return;
}

Color foreground = UIManager.getColor(property);

if (foreground == null) {
throw new RuntimeException("Color for UI property '" + property + "' not found");
}

settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground));

UIManager.removePropertyChangeListener(propertyChangeListener);

propertyChangeListener = e -> {
if ("lookAndFeel".equals(e.getPropertyName())) {
SwingUtilities.invokeLater(() -> {
Color newForeground = UIManager.getColor("TableHeader.foreground");
settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> newForeground));
});
}
});
};
UIManager.addPropertyChangeListener(propertyChangeListener);
}
}

0 comments on commit 2af17b0

Please sign in to comment.