3434import javax .swing .*;
3535import javax .swing .border .TitledBorder ;
3636
37+ import com .github .weisj .darklaf .LafManager ;
38+ import com .github .weisj .darklaf .settings .ThemeSettings ;
3739import com .javadeobfuscator .deobfuscator .ui .component .SwingConfiguration ;
3840import com .javadeobfuscator .deobfuscator .ui .component .SwingConfiguration .ConfigItem ;
3941import 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