From 493fc21c1cca6487be0d630adfe67ca95e6ae872 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 7 Jun 2017 16:15:55 +0100 Subject: Move to awt FileDialog --- src/main/java/cuchaz/enigma/gui/Gui.java | 13 ++++++------- src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'src/main/java/cuchaz') diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 71bf5dc..cac6ca1 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java @@ -20,7 +20,6 @@ import cuchaz.enigma.gui.dialog.CrashDialog; import cuchaz.enigma.gui.elements.MenuBar; import cuchaz.enigma.gui.elements.PopupMenuBar; import cuchaz.enigma.gui.filechooser.FileChooserAny; -import cuchaz.enigma.gui.filechooser.FileChooserFile; import cuchaz.enigma.gui.filechooser.FileChooserFolder; import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter; import cuchaz.enigma.gui.highlight.ObfuscatedHighlightPainter; @@ -63,11 +62,11 @@ public class Gui { private final MenuBar menuBar; // state public EntryReference reference; - public JFileChooser jarFileChooser; - public JFileChooser tinyMappingsFileChooser; + public FileDialog jarFileChooser; + public FileDialog tinyMappingsFileChooser; public JFileChooser enigmaMappingsFileChooser; public JFileChooser exportSourceFileChooser; - public JFileChooser exportJarFileChooser; + public FileDialog exportJarFileChooser; private GuiController controller; private JFrame frame; public PanelEditor editor; @@ -105,12 +104,12 @@ public class Gui { this.controller = new GuiController(this); // init file choosers - this.jarFileChooser = new FileChooserFile(); + this.jarFileChooser = new FileDialog(getFrame(), "Open Jar", FileDialog.LOAD); - this.tinyMappingsFileChooser = new FileChooserFile(); + this.tinyMappingsFileChooser = new FileDialog(getFrame(), "Open tiny Mappings", FileDialog.LOAD); this.enigmaMappingsFileChooser = new FileChooserAny(); this.exportSourceFileChooser = new FileChooserFolder(); - this.exportJarFileChooser = new FileChooserFile(); + this.exportJarFileChooser = new FileDialog(getFrame(), "Export jar", FileDialog.SAVE); this.obfPanel = new PanelObf(this); this.deobfPanel = new PanelDeobf(this); diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index c0568bf..68742f4 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -9,6 +9,7 @@ import cuchaz.enigma.throwables.MappingParseException; import javax.swing.*; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.io.File; import java.io.IOException; import java.util.jar.JarFile; @@ -37,12 +38,14 @@ public class MenuBar extends JMenuBar { JMenuItem item = new JMenuItem("Open Jar..."); menu.add(item); item.addActionListener(event -> { - if (this.gui.jarFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + this.gui.jarFileChooser.setVisible(true); + File file = new File(this.gui.jarFileChooser.getDirectory() + File.separator + this.gui.jarFileChooser.getFile()); + if (file.exists()) { // load the jar in a separate thread new Thread(() -> { try { - gui.getController().openJar(new JarFile(gui.jarFileChooser.getSelectedFile())); + gui.getController().openJar(new JarFile(file)); } catch (IOException ex) { throw new Error(ex); } @@ -78,9 +81,11 @@ public class MenuBar extends JMenuBar { item = new JMenuItem("Tiny"); openMenu.add(item); item.addActionListener(event -> { - if (this.gui.tinyMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + this.gui.tinyMappingsFileChooser.setVisible(true); + File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); + if (file.exists()) { try { - this.gui.getController().openTinyMappings(this.gui.tinyMappingsFileChooser.getSelectedFile()); + this.gui.getController().openTinyMappings(file); } catch (IOException ex) { throw new Error(ex); } catch (MappingParseException ex) { @@ -199,8 +204,10 @@ public class MenuBar extends JMenuBar { 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.gui.tinyMappingsFileChooser.setVisible(true); + if (this.gui.tinyMappingsFileChooser.getFile() != null) { + File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); + this.gui.getController().exportJar(file); } }); this.exportJarMenu = item; -- cgit v1.2.3