Skip to content

Commit 1683c5b

Browse files
committed
Add DarkLaf theme. Closes #38
1 parent 0d6696e commit 1683c5b

File tree

3 files changed

+142
-17
lines changed

3 files changed

+142
-17
lines changed

pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
<version>4.0</version>
77
<name>deobfuscator-gui</name>
88
<description>UI front-end for deobfuscator</description>
9+
<repositories>
10+
<repository> <!-- TODO Remove when com.github.weisj:swing-extensions-laf-support (dep from darklaf) is no longer a snapshot -->
11+
<id>sonatype-snapshots</id>
12+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
13+
</repository>
14+
</repositories>
915
<dependencies>
1016
<!-- Functionality -->
1117
<!-- EMPTY -->
1218

1319
<!--- User interface -->
14-
<!-- https://mvnrepository.com/artifact/org.controlsfx/controlsfx -->
15-
<dependency>
16-
<groupId>org.controlsfx</groupId>
17-
<artifactId>controlsfx</artifactId>
18-
<version>8.40.14</version>
19-
</dependency>
20+
<dependency>
21+
<groupId>com.github.weisj</groupId>
22+
<artifactId>darklaf-core</artifactId>
23+
<version>2.7.0</version>
24+
</dependency>
2025
</dependencies>
2126
<build>
2227
<sourceDirectory>src/java</sourceDirectory>

src/java/com/javadeobfuscator/deobfuscator/ui/GuiConfig.java

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.javadeobfuscator.deobfuscator.ui;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
5-
import java.io.FileOutputStream;
6-
import java.io.IOException;
7-
import java.io.InputStreamReader;
8-
import java.io.OutputStreamWriter;
3+
import java.io.*;
94
import java.nio.charset.StandardCharsets;
5+
import java.util.Base64;
106
import java.util.Properties;
117

128
import javax.swing.JOptionPane;
139

10+
import com.github.weisj.darklaf.settings.SettingsConfiguration;
11+
import com.github.weisj.darklaf.settings.ThemeSettings;
12+
1413
public class GuiConfig
1514
{
1615
private static final File PROPERTY_FILE = new File("deobfuscator-gui.properties");
@@ -19,6 +18,8 @@ public class GuiConfig
1918
private static final String LIMIT_CONSOLE_LINES = "limit_console_lines";
2019
private static final String STORE_CONFIG_ON_CLOSE = "store_config_on_close";
2120
private static final String CONFIG = "config";
21+
private static final String DARKLAF_ENABLED = "darklaf_enabled";
22+
private static final String DARKLAF_SETTINGS = "darklaf_settings";
2223

2324
static
2425
{
@@ -80,6 +81,60 @@ public static void setStoreConfigOnClose(boolean state)
8081
PROPERTIES.setProperty(STORE_CONFIG_ON_CLOSE, Boolean.toString(state));
8182
}
8283

84+
public static boolean isDarkLaf()
85+
{
86+
return Boolean.parseBoolean(PROPERTIES.getProperty(DARKLAF_ENABLED));
87+
}
88+
89+
public static void setDarkLaf(boolean state)
90+
{
91+
PROPERTIES.setProperty(DARKLAF_ENABLED, Boolean.toString(state));
92+
}
93+
94+
public static SettingsConfiguration getDarklafSettings()
95+
{
96+
String property = PROPERTIES.getProperty(DARKLAF_SETTINGS);
97+
if (property == null)
98+
{
99+
return ThemeSettings.getInstance().exportConfiguration();
100+
}
101+
try
102+
{
103+
byte[] decode = Base64.getDecoder().decode(property);
104+
ByteArrayInputStream bain = new ByteArrayInputStream(decode);
105+
try (ObjectInputStream objectInputStream = new ObjectInputStream(bain))
106+
{
107+
Object obj = objectInputStream.readObject();
108+
if (obj instanceof SettingsConfiguration)
109+
{
110+
return (SettingsConfiguration) obj;
111+
}
112+
} catch (IOException | ClassNotFoundException e)
113+
{
114+
e.printStackTrace();
115+
PROPERTIES.remove(DARKLAF_SETTINGS);
116+
}
117+
} catch (Throwable t)
118+
{
119+
t.printStackTrace();
120+
}
121+
return ThemeSettings.getInstance().exportConfiguration();
122+
}
123+
124+
public static void setDarklafSettings(SettingsConfiguration state)
125+
{
126+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
127+
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(baos))
128+
{
129+
objectOutputStream.writeObject(state);
130+
objectOutputStream.flush();
131+
PROPERTIES.setProperty(DARKLAF_SETTINGS, Base64.getEncoder().encodeToString(baos.toByteArray()));
132+
} catch (IOException e)
133+
{
134+
e.printStackTrace();
135+
}
136+
}
137+
83138
public static String getConfig()
84139
{
85140
return PROPERTIES.getProperty(CONFIG);

src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import javax.swing.*;
3535
import javax.swing.border.TitledBorder;
3636

37+
import com.github.weisj.darklaf.LafManager;
38+
import com.github.weisj.darklaf.settings.ThemeSettings;
3739
import com.javadeobfuscator.deobfuscator.ui.component.SwingConfiguration;
3840
import com.javadeobfuscator.deobfuscator.ui.component.SwingConfiguration.ConfigItem;
3941
import com.javadeobfuscator.deobfuscator.ui.component.SwingConfiguration.ItemType;
@@ -56,8 +58,10 @@ public class SwingWindow
5658
public static Transformers trans;
5759
private static Config config;
5860
private static List<Class<?>> transformers;
61+
private static JMenu menu;
5962
private static JCheckBoxMenuItem shouldLimitLines;
6063
private static JCheckBoxMenuItem storeConfigOnClose;
64+
private static JCheckBoxMenuItem enableDarkLaf;
6165
private static final Map<Class<?>, String> TRANSFORMER_TO_NAME = new HashMap<>();
6266
private static final Map<String, Class<?>> NAME_TO_TRANSFORMER = new HashMap<>();
6367

@@ -81,12 +85,19 @@ public static void main(String[] args)
8185
System.exit(1);
8286
return;
8387
}
88+
GuiConfig.read();
8489
try
8590
{
8691
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
87-
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e)
92+
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e2)
8893
{
89-
e.printStackTrace();
94+
e2.printStackTrace();
95+
}
96+
ThemeSettings.getInstance().setConfiguration(GuiConfig.getDarklafSettings());
97+
if (GuiConfig.isDarkLaf())
98+
{
99+
LafManager.install();
100+
ThemeSettings.getInstance().apply();
90101
}
91102
loadWrappers();
92103
List<ConfigItem> fields = new SwingConfiguration(config.get()).fieldsList;
@@ -99,18 +110,71 @@ public static void main(String[] args)
99110

100111
//Menu
101112
JMenuBar menuBar = new JMenuBar();
102-
JMenu menu = new JMenu("Options");
113+
menu = new JMenu(GuiConfig.isDarkLaf() ? " Options" : "Options");
103114
menuBar.add(menu);
104115
shouldLimitLines = new JCheckBoxMenuItem("Limit Console Lines");
105116
menu.add(shouldLimitLines);
106-
storeConfigOnClose = new JCheckBoxMenuItem("Store config on close", true);
117+
storeConfigOnClose = new JCheckBoxMenuItem("Store transformer config on close", true);
107118
menu.add(storeConfigOnClose);
119+
enableDarkLaf = new JCheckBoxMenuItem(new AbstractAction("Enable DarkLaf Theme")
120+
{
121+
@Override
122+
public void actionPerformed(ActionEvent e)
123+
{
124+
if (enableDarkLaf.getState())
125+
{
126+
LafManager.install();
127+
menu.setText(" Options");
128+
ThemeSettings.getInstance().apply();
129+
GuiConfig.setDarkLaf(true);
130+
} else
131+
{
132+
int i = JOptionPane.showConfirmDialog(frame, "Disabling DarkLaf requires application restart.\n" +
133+
"Close Deobfuscator now?", "Close Deobfuscator?",
134+
JOptionPane.YES_NO_OPTION);
135+
if (i != JOptionPane.YES_OPTION)
136+
{
137+
enableDarkLaf.setState(true);
138+
return;
139+
}
140+
GuiConfig.setDarkLaf(false);
141+
GuiConfig.setDarklafSettings(ThemeSettings.getInstance().exportConfiguration());
142+
GuiConfig.save();
143+
System.exit(0);
144+
}
145+
}
146+
});
147+
enableDarkLaf.setState(GuiConfig.isDarkLaf());
148+
menu.add(enableDarkLaf);
149+
JMenuItem theme = new JMenuItem(new AbstractAction("DarkLaf Theme Options")
150+
{
151+
@Override
152+
public void actionPerformed(ActionEvent e)
153+
{
154+
if (!enableDarkLaf.getState())
155+
{
156+
int i = JOptionPane.showConfirmDialog(frame, "To see DarkLaf Theme Options, DarkLaf Theme needs to be enabled first.\n" +
157+
"Enable DarkLaf Theme?", "Enable DarkLaf Theme?", JOptionPane.YES_NO_OPTION);
158+
if (i != JOptionPane.YES_OPTION)
159+
{
160+
return;
161+
}
162+
LafManager.install();
163+
menu.setText(" Options");
164+
ThemeSettings.getInstance().apply();
165+
enableDarkLaf.setState(true);
166+
GuiConfig.setDarkLaf(true);
167+
}
168+
ThemeSettings.showSettingsDialog(frame, Dialog.ModalityType.APPLICATION_MODAL);
169+
}
170+
});
171+
menu.add(theme);
108172
frame.setJMenuBar(menuBar);
109173

110174
//GuiConfig
111-
GuiConfig.read();
112175
shouldLimitLines.setState(GuiConfig.isLimitConsoleLines());
113176
storeConfigOnClose.setState(GuiConfig.getStoreConfigOnClose());
177+
enableDarkLaf.setState(GuiConfig.isDarkLaf());
114178

115179
//Deobfuscator Input
116180
JPanel inputPnl = new JPanel();
@@ -1043,6 +1107,7 @@ public void windowClosing(WindowEvent e)
10431107
GuiConfig.setLimitConsoleLines(shouldLimitLines.getState());
10441108
GuiConfig.setStoreConfigOnClose(storeConfigOnClose.getState());
10451109
GuiConfig.setConfig(createConfig(fields, transformerSelected));
1110+
GuiConfig.setDarklafSettings(ThemeSettings.getInstance().exportConfiguration());
10461111
GuiConfig.save();
10471112
}
10481113
});

0 commit comments

Comments
 (0)