This is an automated email from the ASF dual-hosted git repository. pmouawad pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push: new 1bc58f4 Use theme from darklaf extensions for RSyntaxTextArea. (#617) 1bc58f4 is described below commit 1bc58f4c65b812751439d94ce4f31bbb4923d132 Author: Jannis Weis <31143295+we...@users.noreply.github.com> AuthorDate: Wed Sep 9 18:01:27 2020 +0200 Use theme from darklaf extensions for RSyntaxTextArea. (#617) --- gradle.properties | 3 +- src/bom/build.gradle.kts | 1 + src/core/build.gradle.kts | 1 + .../jmeter/gui/action/LookAndFeelCommand.java | 10 ++--- .../apache/jmeter/gui/util/JSyntaxTextArea.java | 44 ++++++++++++++-------- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4744760..a9b6c4f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -71,7 +71,8 @@ commons-math3.version=3.6.1 commons-net.version=3.7 commons-pool2.version=2.8.1 commons-text.version=1.9 -darklaf.version=2.4.5 +darklaf.version=2.4.7 +darklaf.extensions.version=0.3.4 dec.version=0.1.2 dnsjava.version=2.1.9 equalsverifier.version=3.4.2 diff --git a/src/bom/build.gradle.kts b/src/bom/build.gradle.kts index 4c4fc13..ee209e7 100644 --- a/src/bom/build.gradle.kts +++ b/src/bom/build.gradle.kts @@ -74,6 +74,7 @@ dependencies { apiv("com.github.weisj:darklaf-core", "darklaf") apiv("com.github.weisj:darklaf-theme", "darklaf") apiv("com.github.weisj:darklaf-property-loader", "darklaf") + apiv("com.github.weisj:darklaf-extensions-rsyntaxarea", "darklaf.extensions") apiv("com.helger:ph-commons") apiv("com.helger:ph-css") apiv("com.jayway.jsonpath:json-path") diff --git a/src/core/build.gradle.kts b/src/core/build.gradle.kts index fdfec49..100eca7 100644 --- a/src/core/build.gradle.kts +++ b/src/core/build.gradle.kts @@ -74,6 +74,7 @@ dependencies { implementation("com.github.weisj:darklaf-core") implementation("com.github.weisj:darklaf-theme") implementation("com.github.weisj:darklaf-property-loader") + implementation("com.github.weisj:darklaf-extensions-rsyntaxarea") implementation("com.miglayout:miglayout-swing") implementation("commons-codec:commons-codec") { because("DigestUtils") diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java b/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java index 007f976..e30dc55 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java @@ -200,12 +200,12 @@ public class LookAndFeelCommand extends AbstractAction { // NOOP } + public static boolean isDarklafTheme() { + return "Darklaf".equals(UIManager.getLookAndFeel().getID()); // $NON-NLS-1$ + } + public static boolean isDark() { - String lookAndFeelID = UIManager.getLookAndFeel().getID(); - if (lookAndFeelID.equals("Darklaf")) { // $NON-NLS-1$ - return Theme.isDark(LafManager.getTheme()); - } - return false; + return isDarklafTheme() && Theme.isDark(LafManager.getTheme()); } public static void activateLookAndFeel(String command) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java index 0d8801d..775e7bb 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java @@ -20,9 +20,12 @@ package org.apache.jmeter.gui.util; import java.awt.Color; import java.awt.Font; import java.awt.HeadlessException; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; import java.io.IOException; import java.util.Properties; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import org.apache.jmeter.gui.action.LookAndFeelCommand; @@ -36,6 +39,8 @@ import org.fife.ui.rtextarea.RUndoManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.github.weisj.darklaf.extensions.rsyntaxarea.DarklafRSyntaxTheme; + /** * Utility class to handle RSyntaxTextArea code * It's not currently possible to instantiate the RSyntaxTextArea class when running headless. @@ -44,20 +49,26 @@ import org.slf4j.LoggerFactory; public class JSyntaxTextArea extends RSyntaxTextArea { private static final long serialVersionUID = 211L; - private static final Logger log = LoggerFactory.getLogger(JSyntaxTextArea.class); + private static final Logger log = LoggerFactory.getLogger(JSyntaxTextArea.class); private static final Theme DEFAULT_THEME = loadTheme(Theme.class, "themes/default.xml"); - private static final Theme DARCULA_THEME = loadTheme(JSyntaxTextArea.class, "theme/darcula_theme.xml"); private final Properties languageProperties = JMeterUtils.loadProperties("org/apache/jmeter/gui/util/textarea.properties"); //$NON-NLS-1$ private final boolean disableUndo; private static final boolean WRAP_STYLE_WORD = JMeterUtils.getPropDefault("jsyntaxtextarea.wrapstyleword", true); - private static final boolean LINE_WRAP = JMeterUtils.getPropDefault("jsyntaxtextarea.linewrap", true); - private static final boolean CODE_FOLDING = JMeterUtils.getPropDefault("jsyntaxtextarea.codefolding", true); - private static final int MAX_UNDOS = JMeterUtils.getPropDefault("jsyntaxtextarea.maxundos", 50); + private static final boolean LINE_WRAP = JMeterUtils.getPropDefault("jsyntaxtextarea.linewrap", true); + private static final boolean CODE_FOLDING = JMeterUtils.getPropDefault("jsyntaxtextarea.codefolding", true); + private static final int MAX_UNDOS = JMeterUtils.getPropDefault("jsyntaxtextarea.maxundos", 50); private static final String USER_FONT_FAMILY = JMeterUtils.getPropDefault("jsyntaxtextarea.font.family", null); - private static final int USER_FONT_SIZE = JMeterUtils.getPropDefault("jsyntaxtextarea.font.size", -1); + private static final int USER_FONT_SIZE = JMeterUtils.getPropDefault("jsyntaxtextarea.font.size", -1); + + private static final HierarchyListener GUTTER_THEME_PATCHER = e -> { + if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0 + && e.getChanged() instanceof JSyntaxTextArea) { + SwingUtilities.invokeLater(() -> applyTheme((JSyntaxTextArea) e.getChanged())); + } + }; /** * Creates the default syntax highlighting text area. The following are set: @@ -81,6 +92,8 @@ public class JSyntaxTextArea extends RSyntaxTextArea { try { JSyntaxTextArea jSyntaxTextArea = new JSyntaxTextArea(rows, cols, disableUndo); JFactory.withDynamic(jSyntaxTextArea, JSyntaxTextArea::applyTheme); + // Gutter styling is only applied if the text area is contained in a scroll pane. + jSyntaxTextArea.addHierarchyListener(GUTTER_THEME_PATCHER); return jSyntaxTextArea; } catch (HeadlessException e) { // Allow override for unit testing only @@ -118,12 +131,8 @@ public class JSyntaxTextArea extends RSyntaxTextArea { * @param jSyntaxTextArea */ private static void applyTheme(JSyntaxTextArea jSyntaxTextArea) { - Theme theme; - if (LookAndFeelCommand.isDark()) { - theme = DARCULA_THEME; - } else { - theme = DEFAULT_THEME; - } + final boolean isDarklafTheme = LookAndFeelCommand.isDarklafTheme(); + final Theme theme = isDarklafTheme ? new DarklafRSyntaxTheme(jSyntaxTextArea) : DEFAULT_THEME; if (theme != null) { theme.apply(jSyntaxTextArea); Font font = jSyntaxTextArea.getFont(); @@ -133,10 +142,13 @@ public class JSyntaxTextArea extends RSyntaxTextArea { jSyntaxTextArea.setFont(font); } } - Color color = UIManager.getColor("TextArea.background"); - if (color != null) { - // Pretend syntax textarea theme was designed for the current LaF - jSyntaxTextArea.setBackground(color); + if (!isDarklafTheme) { + // Darklaf themes provide a custom background color for editors, so we don't overwrite it. + Color color = UIManager.getColor("TextArea.background"); + if (color != null) { + // Pretend syntax textarea theme was designed for the current LaF + jSyntaxTextArea.setBackground(color); + } } }