JHexEditor Dark Theme Support

This commit is contained in:
Konloch 2021-07-21 03:53:46 -07:00
parent cbb826d586
commit 4e57bd03e4
2 changed files with 30 additions and 6 deletions

View file

@ -1,5 +1,7 @@
package the.bytecode.club.bytecodeviewer.gui.hexviewer; package the.bytecode.club.bytecodeviewer.gui.hexviewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
@ -39,10 +41,18 @@ public class JHexEditorHEX extends JComponent implements MouseListener, KeyListe
{ {
debug("paint(" + g + ")"); debug("paint(" + g + ")");
debug("cursor=" + he.cursor + " buff.length=" + he.buff.length); debug("cursor=" + he.cursor + " buff.length=" + he.buff.length);
Dimension d = getMinimumSize();
g.setColor(Color.white); if(!Configuration.lafTheme.isDark())
g.fillRect(0, 0, d.width, d.height); {
g.setColor(Color.black); //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); g.setFont(JHexEditor.font);
@ -70,9 +80,9 @@ public class JHexEditorHEX extends JComponent implements MouseListener, KeyListe
if (hasFocus()) if (hasFocus())
g.setColor(Color.white); g.setColor(Color.white);
else else
g.setColor(Color.black); g.setColor(Configuration.lafTheme.isDark() ? Color.white : Color.black);
} else { } else {
g.setColor(Color.black); g.setColor(Configuration.lafTheme.isDark() ? Color.white : Color.black);
} }
String s = ("0" + Integer.toHexString(he.buff[n])); String s = ("0" + Integer.toHexString(he.buff[n]));

View file

@ -54,6 +54,20 @@ public enum LAFTheme
return translation; 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 public void setLAF() throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException
{ {
boolean darkLAF = true; boolean darkLAF = true;