From 4e57bd03e4c96ce2abf6db0674119baa8e61c5fb Mon Sep 17 00:00:00 2001 From: Konloch Date: Wed, 21 Jul 2021 03:53:46 -0700 Subject: [PATCH] JHexEditor Dark Theme Support --- .../gui/hexviewer/JHexEditorHEX.java | 22 ++++++++++++++----- .../bytecodeviewer/gui/theme/LAFTheme.java | 14 ++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditorHEX.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditorHEX.java index 1f223bd5..40b6b20f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditorHEX.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditorHEX.java @@ -1,5 +1,7 @@ package the.bytecode.club.bytecodeviewer.gui.hexviewer; +import the.bytecode.club.bytecodeviewer.Configuration; + import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; @@ -39,10 +41,18 @@ public class JHexEditorHEX extends JComponent implements MouseListener, KeyListe { debug("paint(" + g + ")"); debug("cursor=" + he.cursor + " buff.length=" + he.buff.length); - Dimension d = getMinimumSize(); - g.setColor(Color.white); - g.fillRect(0, 0, d.width, d.height); - g.setColor(Color.black); + + if(!Configuration.lafTheme.isDark()) + { + //TODO if you want a background for the hex-text uncomment this + //g.setColor(Color.white); + //g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.black); + } + else + { + g.setColor(Color.white); + } g.setFont(JHexEditor.font); @@ -70,9 +80,9 @@ public class JHexEditorHEX extends JComponent implements MouseListener, KeyListe if (hasFocus()) g.setColor(Color.white); else - g.setColor(Color.black); + g.setColor(Configuration.lafTheme.isDark() ? Color.white : Color.black); } else { - g.setColor(Color.black); + g.setColor(Configuration.lafTheme.isDark() ? Color.white : Color.black); } String s = ("0" + Integer.toHexString(he.buff[n])); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java index 4fce72cc..11f07d2a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java @@ -54,6 +54,20 @@ public enum LAFTheme return translation; } + public boolean isDark() + { + switch(this) + { + case DARK: + case ONE_DARK: + case SOLARIZED_DARK: + case HIGH_CONTRAST_DARK: + return true; + } + + return false; + } + public void setLAF() throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException { boolean darkLAF = true;