44import club .bytecode .the .jda .FileContainer ;
55import club .bytecode .the .jda .JDA ;
66import club .bytecode .the .jda .Resources ;
7+ import club .bytecode .the .jda .api .JDAPlugin ;
78import club .bytecode .the .jda .decompilers .Decompilers ;
89import club .bytecode .the .jda .decompilers .JDADecompiler ;
910import club .bytecode .the .jda .gui .dialogs .AboutWindow ;
@@ -43,7 +44,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier, IPersis
4344 public JMenu viewMenu ;
4445 public JMenu fileMenu ;
4546 public JMenu windowMenu ;
46- public JMenu settingsMenu ;
47+ public JMenu editMenu ;
4748 public JMenu helpMenu ;
4849
4950 public boolean isMaximized = false ;
@@ -64,6 +65,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier, IPersis
6465 public JMenu mnRecentFiles = new JMenu ("Recent Files" );
6566 private JMenuItem spinnerMenu = new JMenuItem ("" );
6667 public FontOptionsDialog fontOptionsDialog = new FontOptionsDialog ();
68+ public JMenu settingsMenu ;
69+ public JMenu pluginsMenu ;
6770
6871 public MainViewerGUI () {
6972 initializeWindows ();
@@ -123,6 +126,7 @@ public void componentMoved(ComponentEvent e) {
123126 this .setIconImages (Resources .iconList );
124127
125128 initializeMenubar ();
129+ initializePanelGroup ();
126130
127131 if (JDA .previewCopy )
128132 setTitle ("JDA v" + JDA .version + " Preview" );
@@ -161,12 +165,15 @@ private void initializeMenubar() {
161165 fileMenu = new JMenu ("File" );
162166 viewMenu = new JMenu ("View" );
163167 windowMenu = new JMenu ("Window" );
164- settingsMenu = new JMenu ("Settings " );
168+ editMenu = new JMenu ("Edit " );
165169 helpMenu = new JMenu ("Help" );
166170 setJMenuBar (menuBar );
167171
168172 setDefaultCloseOperation (WindowConstants .EXIT_ON_CLOSE );
169173
174+ // ===========================================================================================
175+ // File menu
176+ // ===========================================================================================
170177 menuBar .add (fileMenu );
171178
172179 JMenuItem mntmLoadJar = new JMenuItem ("Add.." );
@@ -215,11 +222,74 @@ private void initializeMenubar() {
215222
216223 fileMenu .add (mntmExit );
217224
225+ // ===========================================================================================
226+ // Edit menu
227+ // ===========================================================================================
228+ menuBar .add (editMenu );
229+
230+ // -------------------------------------------------------------------------------------------
231+ // Settings menu
232+ settingsMenu = new JMenu ("Settings" );
233+ editMenu .add (settingsMenu );
234+
235+ refreshOnChange .addItemListener (e -> Settings .REFRESH_ON_VIEW_CHANGE .set (refreshOnChange .isSelected ()));
236+ refreshOnChange .setSelected (Settings .REFRESH_ON_VIEW_CHANGE .getBool ());
237+ settingsMenu .add (refreshOnChange );
238+
239+ mntmFontSettings .addActionListener (e -> fontOptionsDialog .display ());
240+ settingsMenu .add (mntmFontSettings );
241+
242+ settingsMenu .add (new JSeparator ());
243+
244+ mnShowContainer .setSelected (Settings .SHOW_CONTAINER_NAME .getBool ());
245+ mnShowContainer .addItemListener (e -> {
246+ JTabbedPane tabs = fileViewerPane .tabs ;
247+ Component [] components = tabs .getComponents ();
248+ for (int i = 0 ; i < components .length ; i ++) {
249+ Component c = components [i ];
250+ if (c instanceof Viewer ) {
251+ ((Viewer ) c ).updateName ();
252+ int idx = tabs .indexOfComponent (c );
253+ tabs .setTabComponentAt (idx , new TabbedPane (c .getName (), tabs ));
254+ fileViewerPane .tabs .setTitleAt (idx , c .getName ());
255+ }
256+ }
257+ Settings .SHOW_CONTAINER_NAME .set (mnShowContainer .isSelected ());
258+ });
259+ viewMenu .add (mnShowContainer );
260+ mntmSetOptionalLibrary .addActionListener (e -> setOptionalLibrary ());
261+ settingsMenu .add (mntmSetOptionalLibrary );
262+
263+ settingsMenu .add (new JSeparator ());
264+
265+ for (JDADecompiler decompiler : Decompilers .getAllDecompilers ()) {
266+ JMenuItem settingsButton = new JMenuItem (decompiler .getName ());
267+ settingsButton .addActionListener (e -> decompiler .getSettings ().displayDialog ());
268+ settingsMenu .add (settingsButton );
269+ }
270+
271+ // -------------------------------------------------------------------------------------------
272+ // Plugins menu
273+ pluginsMenu = new JMenu ("Plugins" );
274+ editMenu .add (pluginsMenu );
275+ for (JDAPlugin plugin : JDA .getLoadedPlugins ()) {
276+ JMenuItem button = new JMenuItem (plugin .getName ());
277+ button .addActionListener ((e ) -> plugin .onPluginButton ());
278+ pluginsMenu .add (button );
279+ }
280+
281+ // ===========================================================================================
282+ // View menu
283+ // ===========================================================================================
218284 menuBar .add (viewMenu );
219285 viewMenu .add (generatePane (0 ));
220286 viewMenu .add (generatePane (1 ));
221287 viewMenu .add (generatePane (2 ));
222-
288+
289+ // ===========================================================================================
290+ // Windows menu
291+ // ===========================================================================================
292+ menuBar .add (windowMenu );
223293 for (JDAWindow frame : windows ) {
224294 JMenuItem button = new JMenuItem (frame .getName ());
225295 button .addActionListener (e -> {
@@ -236,29 +306,11 @@ private void initializeMenubar() {
236306 mnSnapToEdges .setSelected (Settings .SNAP_TO_EDGES .getBool ());
237307 mnSnapToEdges .addItemListener (e -> Settings .SNAP_TO_EDGES .set (mnSnapToEdges .isSelected ()));
238308 windowMenu .add (mnSnapToEdges );
239-
240- menuBar .add (windowMenu );
241-
242- refreshOnChange .addItemListener (e -> Settings .REFRESH_ON_VIEW_CHANGE .set (refreshOnChange .isSelected ()));
243- refreshOnChange .setSelected (Settings .REFRESH_ON_VIEW_CHANGE .getBool ());
244- settingsMenu .add (refreshOnChange );
245-
246- settingsMenu .add (new JSeparator ());
247-
248- mntmSetOptionalLibrary .addActionListener (e -> setOptionalLibrary ());
249-
250- settingsMenu .add (mntmSetOptionalLibrary );
251-
252- settingsMenu .add (new JSeparator ());
253-
254- for (JDADecompiler decompiler : Decompilers .getAllDecompilers ()) {
255- JMenuItem settingsButton = new JMenuItem (decompiler .getName ());
256- settingsButton .addActionListener (e -> decompiler .getSettings ().displayDialog ());
257- settingsMenu .add (settingsButton );
258- }
259-
260- menuBar .add (settingsMenu );
261-
309+
310+ // ===========================================================================================
311+ // Help menu
312+ // ===========================================================================================
313+ menuBar .add (helpMenu );
262314 mntmAbout .addActionListener (arg0 -> aboutWindow .setVisible (true ));
263315 helpMenu .add (mntmAbout );
264316
@@ -269,30 +321,14 @@ private void initializeMenubar() {
269321 mntmUpdateCheck .setEnabled (false );
270322 mntmUpdateCheck .addActionListener (e -> Settings .DO_UPDATE_CHECK .set (mntmUpdateCheck .isSelected ()));
271323 helpMenu .add (mntmUpdateCheck );
272- menuBar .add (helpMenu );
273-
324+
325+ // ===========================================================================================
326+ // Spinner (must go last)
327+ // ===========================================================================================
274328 menuBar .add (spinnerMenu );
275-
276- mntmFontSettings .addActionListener (e -> fontOptionsDialog .display ());
277- viewMenu .add (mntmFontSettings );
278-
279- mnShowContainer .setSelected (Settings .SHOW_CONTAINER_NAME .getBool ());
280- mnShowContainer .addItemListener (e -> {
281- JTabbedPane tabs = fileViewerPane .tabs ;
282- Component [] components = tabs .getComponents ();
283- for (int i = 0 ; i < components .length ; i ++) {
284- Component c = components [i ];
285- if (c instanceof Viewer ) {
286- ((Viewer ) c ).updateName ();
287- int idx = tabs .indexOfComponent (c );
288- tabs .setTabComponentAt (idx , new TabbedPane (c .getName (), tabs ));
289- fileViewerPane .tabs .setTitleAt (idx , c .getName ());
290- }
291- }
292- Settings .SHOW_CONTAINER_NAME .set (mnShowContainer .isSelected ());
293- });
294- viewMenu .add (mnShowContainer );
295-
329+ }
330+
331+ private void initializePanelGroup () {
296332 panelGroup1 .setSelected (allDecompilersRev .get (panelGroup1 ).get (Decompilers .FERNFLOWER ).getModel (), true );
297333 panelGroup2 .setSelected (allDecompilersRev .get (panelGroup2 ).get (Decompilers .BYTECODE ).getModel (), true );
298334 panelGroup3 .setSelected (allDecompilersRev .get (panelGroup3 ).get (null ).getModel (), true );
0 commit comments