From 6032f55ede3c1b550cfd83b2f768926c992d9a98 Mon Sep 17 00:00:00 2001 From: Thog Date: Fri, 12 Aug 2016 19:59:54 +0200 Subject: Remoe JSON directory format support and clean up others things --- src/main/java/cuchaz/enigma/gui/Gui.java | 17 +++---- src/main/java/cuchaz/enigma/gui/GuiController.java | 16 ------- .../java/cuchaz/enigma/gui/elements/MenuBar.java | 54 ++++++---------------- .../java/cuchaz/enigma/gui/panels/PanelEditor.java | 2 + 4 files changed, 22 insertions(+), 67 deletions(-) (limited to 'src/main/java/cuchaz/enigma/gui') diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 2269476..262c8b6 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java @@ -79,7 +79,6 @@ public class Gui { public EntryReference m_reference; public JFileChooser jarFileChooser; - public JFileChooser jsonMappingsFileChooser; public JFileChooser enigmaMappingsFileChooser; public JFileChooser exportSourceFileChooser; @@ -107,7 +106,6 @@ public class Gui { // init file choosers this.jarFileChooser = new FileChooserFile(); - this.jsonMappingsFileChooser = new FileChooserFolder(); this.enigmaMappingsFileChooser = new FileChooserAny(); @@ -317,9 +315,7 @@ public class Gui { // update menu this.menuBar.closeJarMenu.setEnabled(true); this.menuBar.openEnigmaMappingsMenu.setEnabled(true); - this.menuBar.openMappingsJsonMenu.setEnabled(true); this.menuBar.saveMappingsMenu.setEnabled(false); - this.menuBar.saveMappingsJsonMenu.setEnabled(true); this.menuBar.saveMappingEnigmaFileMenu.setEnabled(true); this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(true); this.menuBar.saveMappingsSrgMenu.setEnabled(true); @@ -341,9 +337,7 @@ public class Gui { // update menu this.menuBar.closeJarMenu.setEnabled(false); this.menuBar.openEnigmaMappingsMenu.setEnabled(false); - this.menuBar.openMappingsJsonMenu.setEnabled(false); this.menuBar.saveMappingsMenu.setEnabled(false); - this.menuBar.saveMappingsJsonMenu.setEnabled(false); this.menuBar.saveMappingEnigmaFileMenu.setEnabled(false); this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(false); this.menuBar.saveMappingsSrgMenu.setEnabled(false); @@ -363,7 +357,7 @@ public class Gui { } public void setMappingsFile(File file) { - this.jsonMappingsFileChooser.setSelectedFile(file); + this.enigmaMappingsFileChooser.setSelectedFile(file); this.menuBar.saveMappingsMenu.setEnabled(file != null); } @@ -564,6 +558,8 @@ public class Gui { case KeyEvent.VK_ESCAPE: finishRename(text, false); break; + default: + break; } } }); @@ -668,7 +664,6 @@ public class Gui { } public void showCalls() { - if (m_reference == null) { return; } @@ -724,9 +719,9 @@ public class Gui { JOptionPane.QUESTION_MESSAGE, null, options, options[2]); switch (response) { case JOptionPane.YES_OPTION: // save and exit - if (this.jsonMappingsFileChooser.getSelectedFile() != null || this.jsonMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) { + if (this.enigmaMappingsFileChooser.getSelectedFile() != null || this.enigmaMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) { try { - this.controller.saveMappings(this.jsonMappingsFileChooser.getCurrentDirectory()); + this.controller.saveMappings(this.enigmaMappingsFileChooser.getCurrentDirectory()); this.frame.dispose(); } catch (IOException ex) { throw new Error(ex); @@ -738,6 +733,8 @@ public class Gui { // don't save, exit this.frame.dispose(); break; + default: + break; // cancel means do nothing } diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index d416345..68f7c56 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java @@ -72,14 +72,6 @@ public class GuiController { refreshCurrentClass(); } - public void openJsonMappings(File file) throws IOException { - this.deobfuscator.setMappings(new MappingsJsonReader().read(file)); - this.isDirty = false; - this.gui.setMappingsFile(file); - refreshClasses(); - refreshCurrentClass(); - } - public void saveMappings(File file) throws IOException { Mappings mappings = this.deobfuscator.getMappings(); switch (mappings.getOriginMappingFormat()) @@ -87,9 +79,6 @@ public class GuiController { case SRG_FILE: saveSRGMappings(file); break; - case JSON_DIRECTORY: - saveJsonMappings(file); - break; default: saveEnigmaMappings(file, Mappings.FormatType.ENIGMA_FILE != mappings.getOriginMappingFormat()); break; @@ -97,11 +86,6 @@ public class GuiController { } - public void saveJsonMappings(File file) throws IOException { - new MappingsJsonWriter().write(file, this.deobfuscator.getMappings()); - this.isDirty = false; - } - public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException { new MappingsEnigmaWriter().write(file, this.deobfuscator.getMappings(), isDirectoryFormat); this.isDirty = false; diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index e988d74..038698b 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -17,11 +17,9 @@ public class MenuBar extends JMenuBar { public final JMenuItem closeJarMenu; - public final JMenuItem openMappingsJsonMenu; public final JMenuItem openEnigmaMappingsMenu; public final JMenuItem saveMappingsMenu; - public final JMenuItem saveMappingsJsonMenu; public final JMenuItem saveMappingEnigmaFileMenu; public final JMenuItem saveMappingEnigmaDirectoryMenu; public final JMenuItem saveMappingsSrgMenu; @@ -64,6 +62,7 @@ public class MenuBar extends JMenuBar { } menu.addSeparator(); JMenu openMenu = new JMenu("Open Mappings..."); + menu.add(openMenu); { JMenuItem item = new JMenuItem("Enigma"); openMenu.add(item); @@ -80,27 +79,12 @@ public class MenuBar extends JMenuBar { }); this.openEnigmaMappingsMenu = item; } - menu.add(openMenu); - { - JMenuItem item = new JMenuItem("JSON (directory)"); - openMenu.add(item); - item.addActionListener(event -> { - if (this.gui.jsonMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - try { - this.gui.getController().openJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile()); - } catch (IOException ex) { - throw new Error(ex); - } - } - }); - this.openMappingsJsonMenu = item; - } { JMenuItem item = new JMenuItem("Save Mappings"); menu.add(item); item.addActionListener(event -> { try { - this.gui.getController().saveMappings(this.gui.jsonMappingsFileChooser.getSelectedFile()); + this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile()); } catch (IOException ex) { throw new Error(ex); } @@ -109,13 +93,15 @@ public class MenuBar extends JMenuBar { this.saveMappingsMenu = item; } JMenu saveMenu = new JMenu("Save Mappings As..."); + menu.add(saveMenu); { JMenuItem item = new JMenuItem("Enigma (single file)"); saveMenu.add(item); item.addActionListener(event -> { - if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + // TODO: Use a specific file chooser for it + if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { try { - this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), false); + this.gui.getController().saveEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile(), false); this.saveMappingsMenu.setEnabled(true); } catch (IOException ex) { throw new Error(ex); @@ -128,9 +114,10 @@ public class MenuBar extends JMenuBar { JMenuItem item = new JMenuItem("Enigma (directory)"); saveMenu.add(item); item.addActionListener(event -> { - if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + // TODO: Use a specific file chooser for it + if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { try { - this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), true); + this.gui.getController().saveEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile(), true); this.saveMappingsMenu.setEnabled(true); } catch (IOException ex) { throw new Error(ex); @@ -140,29 +127,14 @@ public class MenuBar extends JMenuBar { item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); this.saveMappingEnigmaDirectoryMenu = item; } - menu.add(saveMenu); - { - JMenuItem item = new JMenuItem("JSON (directory)"); - saveMenu.add(item); - item.addActionListener(event -> { - if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - try { - this.gui.getController().saveJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile()); - this.saveMappingsMenu.setEnabled(true); - } catch (IOException ex) { - throw new Error(ex); - } - } - }); - this.saveMappingsJsonMenu = item; - } { - JMenuItem item = new JMenuItem("SRG"); + JMenuItem item = new JMenuItem("SRG (single file)"); saveMenu.add(item); item.addActionListener(event -> { - if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + // TODO: Use a specific file chooser for it + if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { try { - this.gui.getController().saveSRGMappings(this.gui.jsonMappingsFileChooser.getSelectedFile()); + this.gui.getController().saveSRGMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile()); this.saveMappingsMenu.setEnabled(true); } catch (IOException ex) { throw new Error(ex); diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java index 6237710..1c0ee9e 100644 --- a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java +++ b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java @@ -50,6 +50,8 @@ public class PanelEditor extends JEditorPane { case KeyEvent.VK_T: gui.popupMenu.toggleMappingMenu.doClick(); break; + default: + break; } } }); -- cgit v1.2.3