Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark theme #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
91 changes: 88 additions & 3 deletions src/main/java/me/cortex/jarscanner/Gui.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.cortex.jarscanner;

import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.RejectedExecutionException;
import java.util.function.Function;
Expand All @@ -17,11 +19,34 @@ public class Gui {
private static Thread scanThread;

public static void main(String[] args) {
createAndDisplayGui();
boolean darkTheme = true;
for (String arg : args) {
if ("--lightTheme".equals(arg)) {
darkTheme = false;
break;
}
}

createAndDisplayGui(darkTheme);
}

private static void createAndDisplayGui() {
private static void setToDarkTheme() {
try {
UIManager.put("swing.boldMetal", Boolean.FALSE);
UIManager.put("creditsBackground", new ColorUIResource(0x3c3f41));
MetalLookAndFeel.setCurrentTheme(new DarkTheme());
// Force metal look and feel
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Throwable e) {
System.err.println("Unsupported dark theme look and feel");
}
}

private static void createAndDisplayGui(boolean darkTheme) {
USING_GUI = true;
if (darkTheme) {
setToDarkTheme();
}
textArea = new JTextArea(20, 40);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -182,6 +207,10 @@ private static void showCredits() {
JFrame frame = new JFrame("Credits");
JTextArea credits = new JTextArea();
credits.setEditable(false);
Color creditsBackground = UIManager.getColor("creditsBackground");
if (creditsBackground != null) {
credits.setBackground(creditsBackground);
}
for (String string : Gui.credits) {
credits.append(string + "\n");
}
Expand All @@ -198,4 +227,60 @@ private static JScrollPane createTextArea() {

return scrollPane;
}

private static class DarkTheme extends DefaultMetalTheme {
private static final ColorUIResource PRIMARY_1 = new ColorUIResource(0x808080);
private static final ColorUIResource PRIMARY_2 = new ColorUIResource(0x606060);
private static final ColorUIResource PRIMARY_3 = new ColorUIResource(0x4d4d4d);
private static final ColorUIResource SECONDARY_1 = new ColorUIResource(102, 102, 102);
private static final ColorUIResource SECONDARY_2 = new ColorUIResource(85, 85, 85);
private static final ColorUIResource SECONDARY_3 = new ColorUIResource(0x3c3f41);
private static final ColorUIResource WHITE = new ColorUIResource(0x2b2b2b);
private static final ColorUIResource BLACK = new ColorUIResource(255, 255, 255);

@Override
public String getName() {
return "Dark theme";
}

@Override
protected ColorUIResource getPrimary1() {
return PRIMARY_1;
}

@Override
protected ColorUIResource getPrimary2() {
return PRIMARY_2;
}

@Override
protected ColorUIResource getPrimary3() {
return PRIMARY_3;
}

@Override
public ColorUIResource getSecondary1() {
return SECONDARY_1;
}

@Override
public ColorUIResource getSecondary2() {
return SECONDARY_2;
}

@Override
public ColorUIResource getSecondary3() {
return SECONDARY_3;
}

@Override
protected ColorUIResource getWhite() {
return WHITE;
}

@Override
protected ColorUIResource getBlack() {
return BLACK;
}
}
}