From 9a3e5a9d132735f818c379ba72c554362650690d Mon Sep 17 00:00:00 2001 From: lclc98 Date: Sun, 3 Jul 2016 00:05:04 +1000 Subject: Started Gui Refactor --- src/main/java/cuchaz/enigma/gui/AboutDialog.java | 70 --- src/main/java/cuchaz/enigma/gui/CrashDialog.java | 86 ---- src/main/java/cuchaz/enigma/gui/Gui.java | 561 ++++++--------------- src/main/java/cuchaz/enigma/gui/GuiController.java | 1 + .../java/cuchaz/enigma/gui/ProgressDialog.java | 100 ---- .../java/cuchaz/enigma/gui/dialog/AboutDialog.java | 70 +++ .../java/cuchaz/enigma/gui/dialog/CrashDialog.java | 87 ++++ .../cuchaz/enigma/gui/dialog/ProgressDialog.java | 101 ++++ .../java/cuchaz/enigma/gui/elements/MenuBar.java | 169 +++++++ .../cuchaz/enigma/gui/elements/PopupMenuBar.java | 82 +++ .../enigma/gui/filechooser/FileChooserFile.java | 8 + .../enigma/gui/filechooser/FileChooserFolder.java | 11 + .../java/cuchaz/enigma/gui/panels/PanelDeobf.java | 28 + .../java/cuchaz/enigma/gui/panels/PanelEditor.java | 60 +++ .../cuchaz/enigma/gui/panels/PanelIdentifier.java | 34 ++ .../java/cuchaz/enigma/gui/panels/PanelObf.java | 27 + 16 files changed, 825 insertions(+), 670 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/gui/AboutDialog.java delete mode 100644 src/main/java/cuchaz/enigma/gui/CrashDialog.java delete mode 100644 src/main/java/cuchaz/enigma/gui/ProgressDialog.java create mode 100644 src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java create mode 100644 src/main/java/cuchaz/enigma/gui/dialog/CrashDialog.java create mode 100644 src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java create mode 100644 src/main/java/cuchaz/enigma/gui/elements/MenuBar.java create mode 100644 src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java create mode 100644 src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFile.java create mode 100644 src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFolder.java create mode 100644 src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java create mode 100644 src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java create mode 100644 src/main/java/cuchaz/enigma/gui/panels/PanelIdentifier.java create mode 100644 src/main/java/cuchaz/enigma/gui/panels/PanelObf.java (limited to 'src') diff --git a/src/main/java/cuchaz/enigma/gui/AboutDialog.java b/src/main/java/cuchaz/enigma/gui/AboutDialog.java deleted file mode 100644 index bb12466..0000000 --- a/src/main/java/cuchaz/enigma/gui/AboutDialog.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *
- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.gui; - -import java.awt.Color; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.FlowLayout; -import java.io.IOException; - -import javax.swing.*; - -import cuchaz.enigma.Constants; -import cuchaz.enigma.Util; - -public class AboutDialog { - - public static void show(JFrame parent) { - // init frame - final JFrame frame = new JFrame(Constants.NAME + " - About"); - final Container pane = frame.getContentPane(); - pane.setLayout(new FlowLayout()); - - // load the content - try { - String html = Util.readResourceToString("/about.html"); - html = String.format(html, Constants.NAME, Constants.VERSION); - JLabel label = new JLabel(html); - label.setHorizontalAlignment(JLabel.CENTER); - pane.add(label); - } catch (IOException ex) { - throw new Error(ex); - } - - // show the link - String html = "%s"; - html = String.format(html, Constants.URL, Constants.URL); - JButton link = new JButton(html); - link.addActionListener(event -> Util.openUrl(Constants.URL)); - link.setBorderPainted(false); - link.setOpaque(false); - link.setBackground(Color.WHITE); - link.setCursor(new Cursor(Cursor.HAND_CURSOR)); - link.setFocusable(false); - JPanel linkPanel = new JPanel(); - linkPanel.add(link); - pane.add(linkPanel); - - // show ok button - JButton okButton = new JButton("Ok"); - pane.add(okButton); - okButton.addActionListener(arg0 -> frame.dispose()); - - // show the frame - pane.doLayout(); - frame.setSize(400, 220); - frame.setResizable(false); - frame.setLocationRelativeTo(parent); - frame.setVisible(true); - frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - } -} diff --git a/src/main/java/cuchaz/enigma/gui/CrashDialog.java b/src/main/java/cuchaz/enigma/gui/CrashDialog.java deleted file mode 100644 index 3806f54..0000000 --- a/src/main/java/cuchaz/enigma/gui/CrashDialog.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *
- * Contributors:
- * Jeff Martin - initial API and implementation
- ******************************************************************************/
-package cuchaz.enigma.gui;
-
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.FlowLayout;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import javax.swing.*;
-
-import cuchaz.enigma.Constants;
-
-public class CrashDialog {
-
- private static CrashDialog m_instance = null;
-
- private JFrame m_frame;
- private JTextArea m_text;
-
- private CrashDialog(JFrame parent) {
- // init frame
- m_frame = new JFrame(Constants.NAME + " - Crash Report");
- final Container pane = m_frame.getContentPane();
- pane.setLayout(new BorderLayout());
-
- JLabel label = new JLabel(Constants.NAME + " has crashed! =(");
- label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- pane.add(label, BorderLayout.NORTH);
-
- // report panel
- m_text = new JTextArea();
- m_text.setTabSize(2);
- pane.add(new JScrollPane(m_text), BorderLayout.CENTER);
-
- // buttons panel
- JPanel buttonsPanel = new JPanel();
- FlowLayout buttonsLayout = new FlowLayout();
- buttonsLayout.setAlignment(FlowLayout.RIGHT);
- buttonsPanel.setLayout(buttonsLayout);
- buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work.")));
- JButton ignoreButton = new JButton("Ignore");
- ignoreButton.addActionListener(event -> {
- // close (hide) the dialog
- m_frame.setVisible(false);
- });
- buttonsPanel.add(ignoreButton);
- JButton exitButton = new JButton("Exit");
- exitButton.addActionListener(event -> {
- // exit enigma
- System.exit(1);
- });
- buttonsPanel.add(exitButton);
- pane.add(buttonsPanel, BorderLayout.SOUTH);
-
- // show the frame
- m_frame.setSize(600, 400);
- m_frame.setLocationRelativeTo(parent);
- m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- }
-
- public static void init(JFrame parent) {
- m_instance = new CrashDialog(parent);
- }
-
- public static void show(Throwable ex) {
- // get the error report
- StringWriter buf = new StringWriter();
- ex.printStackTrace(new PrintWriter(buf));
- String report = buf.toString();
-
- // show it!
- m_instance.m_text.setText(report);
- m_instance.m_frame.doLayout();
- m_instance.m_frame.setVisible(true);
- }
-}
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index fee9c9f..623e12e 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -20,7 +20,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
-import java.util.jar.JarFile;
import javax.swing.*;
import javax.swing.text.BadLocationException;
@@ -32,21 +31,33 @@ import javax.swing.tree.TreePath;
import cuchaz.enigma.Constants;
import cuchaz.enigma.ExceptionIgnorer;
import cuchaz.enigma.analysis.*;
+import cuchaz.enigma.gui.dialog.CrashDialog;
+import cuchaz.enigma.gui.elements.MenuBar;
+import cuchaz.enigma.gui.elements.PopupMenuBar;
+import cuchaz.enigma.gui.filechooser.FileChooserFile;
+import cuchaz.enigma.gui.filechooser.FileChooserFolder;
+import cuchaz.enigma.gui.panels.PanelDeobf;
+import cuchaz.enigma.gui.panels.PanelEditor;
+import cuchaz.enigma.gui.panels.PanelIdentifier;
+import cuchaz.enigma.gui.panels.PanelObf;
import cuchaz.enigma.mapping.*;
import de.sciss.syntaxpane.DefaultSyntaxKit;
public class Gui {
- private GuiController m_controller;
+ private GuiController controller;
- // controls
- private JFrame m_frame;
- private ClassSelector m_obfClasses;
- private ClassSelector m_deobfClasses;
- private JEditorPane m_editor;
- private JPanel m_classesPanel;
+ private final PanelObf obfPanel;
+ private final PanelDeobf deobfPanel;
+
+ private final MenuBar menuBar;
+ public final PopupMenuBar popupMenu;
+
+ private JFrame frame;
+ private PanelEditor editor;
+ private JPanel classesPanel;
private JSplitPane m_splitClasses;
- private JPanel m_infoPanel;
+ private PanelIdentifier m_infoPanel;
private ObfuscatedHighlightPainter m_obfuscatedHighlightPainter;
private DeobfuscatedHighlightPainter m_deobfuscatedHighlightPainter;
private OtherHighlightPainter m_otherHighlightPainter;
@@ -57,42 +68,26 @@ public class Gui {
private JList
- * Contributors:
- * Jeff Martin - initial API and implementation
- ******************************************************************************/
-package cuchaz.enigma.gui;
-
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-
-import javax.swing.*;
-
-import cuchaz.enigma.Constants;
-import cuchaz.enigma.Deobfuscator.ProgressListener;
-
-public class ProgressDialog implements ProgressListener, AutoCloseable {
-
- private JFrame frame;
- private JLabel labelTitle;
- private JLabel labelText;
- private JProgressBar progress;
-
- public ProgressDialog(JFrame parent) {
-
- // init frame
- this.frame = new JFrame(Constants.NAME + " - Operation in progress");
- final Container pane = this.frame.getContentPane();
- FlowLayout layout = new FlowLayout();
- layout.setAlignment(FlowLayout.LEFT);
- pane.setLayout(layout);
-
- this.labelTitle = new JLabel();
- pane.add(this.labelTitle);
-
- // set up the progress bar
- JPanel panel = new JPanel();
- pane.add(panel);
- panel.setLayout(new BorderLayout());
- this.labelText = GuiTricks.unboldLabel(new JLabel());
- this.progress = new JProgressBar();
- this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
- panel.add(this.labelText, BorderLayout.NORTH);
- panel.add(this.progress, BorderLayout.CENTER);
- panel.setPreferredSize(new Dimension(360, 50));
-
- // show the frame
- pane.doLayout();
- this.frame.setSize(400, 120);
- this.frame.setResizable(false);
- this.frame.setLocationRelativeTo(parent);
- this.frame.setVisible(true);
- this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- }
-
- public void close() {
- this.frame.dispose();
- }
-
- @Override
- public void init(int totalWork, String title) {
- this.labelTitle.setText(title);
- this.progress.setMinimum(0);
- this.progress.setMaximum(totalWork);
- this.progress.setValue(0);
- }
-
- @Override
- public void onProgress(int numDone, String message) {
- this.labelText.setText(message);
- this.progress.setValue(numDone);
-
- // update the frame
- this.frame.validate();
- this.frame.repaint();
- }
-
- public interface ProgressRunnable {
- void run(ProgressListener listener) throws Exception;
- }
-
- public static void runInThread(final JFrame parent, final ProgressRunnable runnable) {
- new Thread() {
- @Override
- public void run() {
- try (ProgressDialog progress = new ProgressDialog(parent)) {
- runnable.run(progress);
- } catch (Exception ex) {
- throw new Error(ex);
- }
- }
- }.start();
- }
-}
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java
new file mode 100644
index 0000000..da4f5fb
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/dialog/AboutDialog.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jeff Martin.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public
+ * License v3.0 which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma.gui.dialog;
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.FlowLayout;
+import java.io.IOException;
+
+import javax.swing.*;
+
+import cuchaz.enigma.Constants;
+import cuchaz.enigma.Util;
+
+public class AboutDialog {
+
+ public static void show(JFrame parent) {
+ // init frame
+ final JFrame frame = new JFrame(Constants.NAME + " - About");
+ final Container pane = frame.getContentPane();
+ pane.setLayout(new FlowLayout());
+
+ // load the content
+ try {
+ String html = Util.readResourceToString("/about.html");
+ html = String.format(html, Constants.NAME, Constants.VERSION);
+ JLabel label = new JLabel(html);
+ label.setHorizontalAlignment(JLabel.CENTER);
+ pane.add(label);
+ } catch (IOException ex) {
+ throw new Error(ex);
+ }
+
+ // show the link
+ String html = "%s";
+ html = String.format(html, Constants.URL, Constants.URL);
+ JButton link = new JButton(html);
+ link.addActionListener(event -> Util.openUrl(Constants.URL));
+ link.setBorderPainted(false);
+ link.setOpaque(false);
+ link.setBackground(Color.WHITE);
+ link.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ link.setFocusable(false);
+ JPanel linkPanel = new JPanel();
+ linkPanel.add(link);
+ pane.add(linkPanel);
+
+ // show ok button
+ JButton okButton = new JButton("Ok");
+ pane.add(okButton);
+ okButton.addActionListener(arg0 -> frame.dispose());
+
+ // show the frame
+ pane.doLayout();
+ frame.setSize(400, 220);
+ frame.setResizable(false);
+ frame.setLocationRelativeTo(parent);
+ frame.setVisible(true);
+ frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/CrashDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/CrashDialog.java
new file mode 100644
index 0000000..71aab01
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/dialog/CrashDialog.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jeff Martin.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public
+ * License v3.0 which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma.gui.dialog;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.FlowLayout;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.swing.*;
+
+import cuchaz.enigma.Constants;
+import cuchaz.enigma.gui.GuiTricks;
+
+public class CrashDialog {
+
+ private static CrashDialog m_instance = null;
+
+ private JFrame m_frame;
+ private JTextArea m_text;
+
+ private CrashDialog(JFrame parent) {
+ // init frame
+ m_frame = new JFrame(Constants.NAME + " - Crash Report");
+ final Container pane = m_frame.getContentPane();
+ pane.setLayout(new BorderLayout());
+
+ JLabel label = new JLabel(Constants.NAME + " has crashed! =(");
+ label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ pane.add(label, BorderLayout.NORTH);
+
+ // report panel
+ m_text = new JTextArea();
+ m_text.setTabSize(2);
+ pane.add(new JScrollPane(m_text), BorderLayout.CENTER);
+
+ // buttons panel
+ JPanel buttonsPanel = new JPanel();
+ FlowLayout buttonsLayout = new FlowLayout();
+ buttonsLayout.setAlignment(FlowLayout.RIGHT);
+ buttonsPanel.setLayout(buttonsLayout);
+ buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work.")));
+ JButton ignoreButton = new JButton("Ignore");
+ ignoreButton.addActionListener(event -> {
+ // close (hide) the dialog
+ m_frame.setVisible(false);
+ });
+ buttonsPanel.add(ignoreButton);
+ JButton exitButton = new JButton("Exit");
+ exitButton.addActionListener(event -> {
+ // exit enigma
+ System.exit(1);
+ });
+ buttonsPanel.add(exitButton);
+ pane.add(buttonsPanel, BorderLayout.SOUTH);
+
+ // show the frame
+ m_frame.setSize(600, 400);
+ m_frame.setLocationRelativeTo(parent);
+ m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ }
+
+ public static void init(JFrame parent) {
+ m_instance = new CrashDialog(parent);
+ }
+
+ public static void show(Throwable ex) {
+ // get the error report
+ StringWriter buf = new StringWriter();
+ ex.printStackTrace(new PrintWriter(buf));
+ String report = buf.toString();
+
+ // show it!
+ m_instance.m_text.setText(report);
+ m_instance.m_frame.doLayout();
+ m_instance.m_frame.setVisible(true);
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java
new file mode 100644
index 0000000..dc4d91e
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jeff Martin.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public
+ * License v3.0 which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma.gui.dialog;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+
+import javax.swing.*;
+
+import cuchaz.enigma.Constants;
+import cuchaz.enigma.Deobfuscator.ProgressListener;
+import cuchaz.enigma.gui.GuiTricks;
+
+public class ProgressDialog implements ProgressListener, AutoCloseable {
+
+ private JFrame frame;
+ private JLabel labelTitle;
+ private JLabel labelText;
+ private JProgressBar progress;
+
+ public ProgressDialog(JFrame parent) {
+
+ // init frame
+ this.frame = new JFrame(Constants.NAME + " - Operation in progress");
+ final Container pane = this.frame.getContentPane();
+ FlowLayout layout = new FlowLayout();
+ layout.setAlignment(FlowLayout.LEFT);
+ pane.setLayout(layout);
+
+ this.labelTitle = new JLabel();
+ pane.add(this.labelTitle);
+
+ // set up the progress bar
+ JPanel panel = new JPanel();
+ pane.add(panel);
+ panel.setLayout(new BorderLayout());
+ this.labelText = GuiTricks.unboldLabel(new JLabel());
+ this.progress = new JProgressBar();
+ this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
+ panel.add(this.labelText, BorderLayout.NORTH);
+ panel.add(this.progress, BorderLayout.CENTER);
+ panel.setPreferredSize(new Dimension(360, 50));
+
+ // show the frame
+ pane.doLayout();
+ this.frame.setSize(400, 120);
+ this.frame.setResizable(false);
+ this.frame.setLocationRelativeTo(parent);
+ this.frame.setVisible(true);
+ this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ }
+
+ public void close() {
+ this.frame.dispose();
+ }
+
+ @Override
+ public void init(int totalWork, String title) {
+ this.labelTitle.setText(title);
+ this.progress.setMinimum(0);
+ this.progress.setMaximum(totalWork);
+ this.progress.setValue(0);
+ }
+
+ @Override
+ public void onProgress(int numDone, String message) {
+ this.labelText.setText(message);
+ this.progress.setValue(numDone);
+
+ // update the frame
+ this.frame.validate();
+ this.frame.repaint();
+ }
+
+ public interface ProgressRunnable {
+ void run(ProgressListener listener) throws Exception;
+ }
+
+ public static void runInThread(final JFrame parent, final ProgressRunnable runnable) {
+ new Thread() {
+ @Override
+ public void run() {
+ try (ProgressDialog progress = new ProgressDialog(parent)) {
+ runnable.run(progress);
+ } catch (Exception ex) {
+ throw new Error(ex);
+ }
+ }
+ }.start();
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
new file mode 100644
index 0000000..233d55e
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
@@ -0,0 +1,169 @@
+package cuchaz.enigma.gui.elements;
+
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.io.IOException;
+import java.util.jar.JarFile;
+
+import javax.swing.*;
+
+import cuchaz.enigma.gui.Gui;
+import cuchaz.enigma.gui.dialog.AboutDialog;
+import cuchaz.enigma.mapping.MappingParseException;
+
+public class MenuBar extends JMenuBar {
+
+ private final Gui gui;
+
+ public final JMenuItem closeJarMenu;
+
+ public final JMenuItem openMappingsMenu;
+ public final JMenuItem openOldMappingsMenu;
+
+ public final JMenuItem saveMappingsMenu;
+ public final JMenuItem saveMappingsAsMenu;
+ public final JMenuItem closeMappingsMenu;
+
+
+ public final JMenuItem exportSourceMenu;
+ public final JMenuItem exportJarMenu;
+
+ public MenuBar(Gui gui) {
+ this.gui = gui;
+
+ {
+ JMenu menu = new JMenu("File");
+ this.add(menu);
+ {
+ JMenuItem item = new JMenuItem("Open Jar...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.jarFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ // load the jar in a separate thread
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ gui.getController().openJar(new JarFile(gui.jarFileChooser.getSelectedFile()));
+ } catch (IOException ex) {
+ throw new Error(ex);
+ }
+ }
+ }.start();
+ }
+ });
+ }
+ {
+ JMenuItem item = new JMenuItem("Close Jar");
+ menu.add(item);
+ item.addActionListener(event -> this.gui.getController().closeJar());
+ this.closeJarMenu = item;
+ }
+ menu.addSeparator();
+ {
+ JMenuItem item = new JMenuItem("Open Mappings...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.mappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ try {
+ this.gui.getController().openMappings(this.gui.mappingsFileChooser.getSelectedFile());
+ } catch (IOException ex) {
+ throw new Error(ex);
+ } catch (MappingParseException ex) {
+ JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
+ }
+ }
+ });
+ this.openMappingsMenu = item;
+ }
+ {
+ JMenuItem item = new JMenuItem("Open Old Mappings...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.oldMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ try {
+ this.gui.getController().openOldMappings(this.gui.oldMappingsFileChooser.getSelectedFile());
+ } catch (IOException ex) {
+ throw new Error(ex);
+ } catch (MappingParseException ex) {
+ JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
+ }
+ }
+ });
+ this.openOldMappingsMenu = item;
+ }
+ menu.addSeparator();
+ {
+ JMenuItem item = new JMenuItem("Save Mappings");
+ menu.add(item);
+ item.addActionListener(event -> {
+ try {
+ this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile());
+ } catch (IOException ex) {
+ throw new Error(ex);
+ }
+ });
+ item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
+ this.saveMappingsMenu = item;
+ }
+ {
+ JMenuItem item = new JMenuItem("Save Mappings As...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ try {
+ this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile());
+ this.saveMappingsMenu.setEnabled(true);
+ } catch (IOException ex) {
+ throw new Error(ex);
+ }
+ }
+ });
+ item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
+ this.saveMappingsAsMenu = item;
+ }
+ {
+ JMenuItem item = new JMenuItem("Close Mappings");
+ menu.add(item);
+ item.addActionListener(event -> this.gui.getController().closeMappings());
+ this.closeMappingsMenu = item;
+ }
+ menu.addSeparator();
+ {
+ JMenuItem item = new JMenuItem("Export Source...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile());
+ }
+ });
+ this.exportSourceMenu = item;
+ }
+ {
+ JMenuItem item = new JMenuItem("Export Jar...");
+ menu.add(item);
+ item.addActionListener(event -> {
+ if (this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
+ this.gui.getController().exportJar(this.gui.exportJarFileChooser.getSelectedFile());
+ }
+ });
+ this.exportJarMenu = item;
+ }
+ menu.addSeparator();
+ {
+ JMenuItem item = new JMenuItem("Exit");
+ menu.add(item);
+ item.addActionListener(event -> this.gui.close());
+ }
+ }
+ {
+ JMenu menu = new JMenu("Help");
+ this.add(menu);
+ {
+ JMenuItem item = new JMenuItem("About");
+ menu.add(item);
+ item.addActionListener(event -> AboutDialog.show(this.gui.getFrame()));
+ }
+ }
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java
new file mode 100644
index 0000000..07c8a32
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java
@@ -0,0 +1,82 @@
+package cuchaz.enigma.gui.elements;
+
+import java.awt.event.KeyEvent;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.KeyStroke;
+
+import cuchaz.enigma.gui.Gui;
+
+public class PopupMenuBar extends JPopupMenu {
+
+ private final Gui gui;
+
+ public final JMenuItem renameMenu;
+ public final JMenuItem showInheritanceMenu;
+ public final JMenuItem showImplementationsMenu;
+ public final JMenuItem showCallsMenu;
+ public final JMenuItem openEntryMenu;
+ public final JMenuItem openPreviousMenu;
+ public final JMenuItem toggleMappingMenu;
+
+ public PopupMenuBar(Gui gui) {
+ this.gui = gui;
+ {
+ JMenuItem menu = new JMenuItem("Rename");
+ menu.addActionListener(event -> gui.startRename());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.renameMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Show Inheritance");
+ menu.addActionListener(event -> gui.showInheritance());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.showInheritanceMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Show Implementations");
+ menu.addActionListener(event -> gui.showImplementations());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.showImplementationsMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Show Calls");
+ menu.addActionListener(event -> gui.showCalls());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.showCallsMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Go to Declaration");
+ menu.addActionListener(event -> gui.navigateTo(gui.m_reference.entry));
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.openEntryMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Go to previous");
+ menu.addActionListener(event -> gui.getController().openPreviousReference());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.openPreviousMenu = menu;
+ }
+ {
+ JMenuItem menu = new JMenuItem("Mark as deobfuscated");
+ menu.addActionListener(event -> gui.toggleMapping());
+ menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0));
+ menu.setEnabled(false);
+ this.add(menu);
+ this.toggleMappingMenu = menu;
+ }
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFile.java b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFile.java
new file mode 100644
index 0000000..62a0f20
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFile.java
@@ -0,0 +1,8 @@
+package cuchaz.enigma.gui.filechooser;
+
+import javax.swing.JFileChooser;
+
+public class FileChooserFile extends JFileChooser {
+ public FileChooserFile() {
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFolder.java b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFolder.java
new file mode 100644
index 0000000..bd8f0f0
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserFolder.java
@@ -0,0 +1,11 @@
+package cuchaz.enigma.gui.filechooser;
+
+import javax.swing.JFileChooser;
+
+public class FileChooserFolder extends JFileChooser{
+
+ public FileChooserFolder() {
+ this.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ this.setAcceptAllFileFilterUsed(false);
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java b/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java
new file mode 100644
index 0000000..d89de36
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java
@@ -0,0 +1,28 @@
+package cuchaz.enigma.gui.panels;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import cuchaz.enigma.gui.ClassSelector;
+import cuchaz.enigma.gui.Gui;
+
+public class PanelDeobf extends JPanel {
+
+ public final ClassSelector deobfClasses;
+ private final Gui gui;
+
+ public PanelDeobf(Gui gui) {
+ this.gui = gui;
+
+ this.deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator);
+ this.deobfClasses.setListener(gui::navigateTo);
+
+ this.setLayout(new BorderLayout());
+ this.add(new JLabel("De-obfuscated Classes"), BorderLayout.NORTH);
+ this.add(new JScrollPane(this.deobfClasses), BorderLayout.CENTER);
+
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java
new file mode 100644
index 0000000..6237710
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java
@@ -0,0 +1,60 @@
+package cuchaz.enigma.gui.panels;
+
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.JEditorPane;
+
+import cuchaz.enigma.gui.BrowserCaret;
+import cuchaz.enigma.gui.Gui;
+import de.sciss.syntaxpane.DefaultSyntaxKit;
+
+public class PanelEditor extends JEditorPane {
+ private final Gui gui;
+
+ public PanelEditor(Gui gui) {
+ this.gui = gui;
+
+ this.setEditable(false);
+ this.setCaret(new BrowserCaret());
+ this.setContentType("text/java");
+ this.addCaretListener(event -> gui.onCaretMove(event.getDot()));
+ this.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent event) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.VK_R:
+ gui.popupMenu.renameMenu.doClick();
+ break;
+
+ case KeyEvent.VK_I:
+ gui.popupMenu.showInheritanceMenu.doClick();
+ break;
+
+ case KeyEvent.VK_M:
+ gui.popupMenu.showImplementationsMenu.doClick();
+ break;
+
+ case KeyEvent.VK_N:
+ gui.popupMenu.openEntryMenu.doClick();
+ break;
+
+ case KeyEvent.VK_P:
+ gui.popupMenu.openPreviousMenu.doClick();
+ break;
+
+ case KeyEvent.VK_C:
+ gui.popupMenu.showCallsMenu.doClick();
+ break;
+
+ case KeyEvent.VK_T:
+ gui.popupMenu.toggleMappingMenu.doClick();
+ break;
+ }
+ }
+ });
+
+ DefaultSyntaxKit kit = (DefaultSyntaxKit) this.getEditorKit();
+ kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker");
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelIdentifier.java b/src/main/java/cuchaz/enigma/gui/panels/PanelIdentifier.java
new file mode 100644
index 0000000..4261eb5
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/panels/PanelIdentifier.java
@@ -0,0 +1,34 @@
+package cuchaz.enigma.gui.panels;
+
+import java.awt.Dimension;
+import java.awt.GridLayout;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import cuchaz.enigma.gui.Gui;
+import cuchaz.enigma.gui.GuiTricks;
+
+public class PanelIdentifier extends JPanel {
+
+ private final Gui gui;
+
+ public PanelIdentifier(Gui gui) {
+ this.gui = gui;
+
+ this.setLayout(new GridLayout(4, 1, 0, 0));
+ this.setPreferredSize(new Dimension(0, 100));
+ this.setBorder(BorderFactory.createTitledBorder("Identifier Info"));
+ }
+
+ public void clearReference() {
+ this.removeAll();
+ JLabel label = new JLabel("No identifier selected");
+ GuiTricks.unboldLabel(label);
+ label.setHorizontalAlignment(JLabel.CENTER);
+ this.add(label);
+
+ gui.redraw();
+ }
+}
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java b/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java
new file mode 100644
index 0000000..745cb2e
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java
@@ -0,0 +1,27 @@
+package cuchaz.enigma.gui.panels;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import cuchaz.enigma.gui.ClassSelector;
+import cuchaz.enigma.gui.Gui;
+
+public class PanelObf extends JPanel {
+
+ private final Gui gui;
+ public final ClassSelector obfClasses;
+
+ public PanelObf(Gui gui) {
+ this.gui = gui;
+
+ this.obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator);
+ this.obfClasses.setListener(gui::navigateTo);
+
+ this.setLayout(new BorderLayout());
+ this.add(new JLabel("Obfuscated Classes"), BorderLayout.NORTH);
+ this.add(new JScrollPane(this.obfClasses), BorderLayout.CENTER);
+ }
+}
--
cgit v1.2.3