Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ commons-math3.version=3.6.1
commons-net.version=3.6
commons-pool2.version=2.8.0
commons-text.version=1.8
darklaf.version=2.4.2
darklaf.version=2.4.4
dec.version=0.1.2
dnsjava.version=2.1.9
equalsverifier.version=3.1.13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.jmeter.gui.action;

import java.awt.event.ActionEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -41,12 +40,6 @@

import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.theme.DarculaTheme;
import com.github.weisj.darklaf.theme.HighContrastDarkTheme;
import com.github.weisj.darklaf.theme.HighContrastLightTheme;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import com.github.weisj.darklaf.theme.OneDarkTheme;
import com.github.weisj.darklaf.theme.SolarizedDarkTheme;
import com.github.weisj.darklaf.theme.SolarizedLightTheme;
import com.github.weisj.darklaf.theme.Theme;

/**
Expand All @@ -70,9 +63,9 @@ public static class MenuItem {
final String title;
final String command;
final String lafClassName;
final Class<? extends Theme> lafTheme;
final Theme lafTheme;

private MenuItem(String title, String command, String lafClassName, Class<? extends Theme> lafTheme) {
private MenuItem(String title, String command, String lafClassName, Theme lafTheme) {
this.title = title;
this.command = command;
this.lafClassName = lafClassName;
Expand All @@ -88,14 +81,14 @@ public String getCommand() {
}

private static MenuItem of(String title, String lafClass) {
return new MenuItem(title,ActionNames.LAF_PREFIX + lafClass, lafClass, null);
return new MenuItem(title, ActionNames.LAF_PREFIX + lafClass, lafClass, null);
}

private static MenuItem ofDarklafTheme(Class<? extends Theme> lafTheme) {
return new MenuItem("Darklaf - " + lafTheme.getSimpleName().replace("Theme", ""),
JMeterMenuBar.DARKLAF_LAF_CLASS + ":" + lafTheme.getName(),
private static MenuItem ofDarklafTheme(Theme theme) {
return new MenuItem("Darklaf - " + theme.getName(),
JMeterMenuBar.DARKLAF_LAF_CLASS + ":" + theme.getThemeClass().getName(),
JMeterMenuBar.DARKLAF_LAF_CLASS,
lafTheme);
theme);
}
}

Expand All @@ -106,21 +99,17 @@ private static MenuItem ofDarklafTheme(Class<? extends Theme> lafTheme) {
if (System.getProperty("darklaf.allowNativeCode") == null) {
System.setProperty("darklaf.allowNativeCode", "false");
}
UIManager.installLookAndFeel(JMeterMenuBar.DARKLAF_LAF, JMeterMenuBar.DARKLAF_LAF_CLASS);
UIManager.installLookAndFeel(JMeterMenuBar.DARCULA_LAF, JMeterMenuBar.DARCULA_LAF_CLASS);

List<MenuItem> items = new ArrayList<>();
for (UIManager.LookAndFeelInfo laf : JMeterMenuBar.getAllLAFs()) {
if (!laf.getClassName().equals(JMeterMenuBar.DARKLAF_LAF_CLASS)) {
if (!laf.getClassName().equals(JMeterMenuBar.DARCULA_LAF_CLASS)) {
items.add(MenuItem.of(laf.getName(), laf.getClassName()));
continue;
} else {
for (Theme theme : LafManager.getRegisteredThemes()) {
items.add(MenuItem.ofDarklafTheme(theme));
}
}
items.add(MenuItem.ofDarklafTheme(DarculaTheme.class));
items.add(MenuItem.ofDarklafTheme(IntelliJTheme.class));
items.add(MenuItem.ofDarklafTheme(OneDarkTheme.class));
items.add(MenuItem.ofDarklafTheme(SolarizedDarkTheme.class));
items.add(MenuItem.ofDarklafTheme(SolarizedLightTheme.class));
items.add(MenuItem.ofDarklafTheme(HighContrastDarkTheme.class));
items.add(MenuItem.ofDarklafTheme(HighContrastLightTheme.class));
}
items.sort(Comparator.comparing(MenuItem::getTitle));
for (MenuItem item : items) {
Expand Down Expand Up @@ -184,7 +173,7 @@ public static String getPreferredLafCommand() {
String jMeterLaf = getJMeterLaf();
if (jMeterLaf.equals(JMeterMenuBar.DARCULA_LAF_CLASS)) {
// Convert old Darcula to new Darklaf-Darcula LaF
return MenuItem.ofDarklafTheme(DarculaTheme.class).command;
return MenuItem.ofDarklafTheme(new DarculaTheme()).command;
}

return MenuItem.of("default", jMeterLaf).command; // $NON-NLS-1$
Expand All @@ -208,37 +197,23 @@ public LookAndFeelCommand() {
public static boolean isDark() {
String lookAndFeelID = UIManager.getLookAndFeel().getID();
if (lookAndFeelID.equals("Darklaf")) { // $NON-NLS-1$
Theme lafTheme = LafManager.getTheme();
if (lafTheme == null) {
return false;
}
String name = lafTheme.getName();
return name.equals("darcula") || name.equals("solarized_dark"); // $NON-NLS-1$
return Theme.isDark(LafManager.getTheme());
}
return false;
}

public static void activateLookAndFeel(String command) {
MenuItem item = items.get(command);
String className = item.lafClassName;
try {
if (item.lafTheme != null) {
LafManager.setTheme(item.lafTheme.getConstructor().newInstance());
}
GuiPackage instance = GuiPackage.getInstance();
if (instance != null) {
instance.updateUIForHiddenComponents();
}
JFactory.refreshUI(className);
PREFS.put(USER_PREFS_KEY, item.command);
} catch ( InstantiationException
| NoSuchMethodException
| IllegalAccessException e) {
throw new IllegalArgumentException("Look and Feel unavailable:" + e.toString(), e);
} catch (InvocationTargetException e) {
Throwable c = e.getCause();
throw new IllegalArgumentException("Look and Feel unavailable:" + c.toString(), c);
if (item.lafTheme != null) {
LafManager.setTheme(item.lafTheme);
}
GuiPackage instance = GuiPackage.getInstance();
if (instance != null) {
instance.updateUIForHiddenComponents();
}
JFactory.refreshUI(className);
PREFS.put(USER_PREFS_KEY, item.command);
}

@Override
Expand Down