summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar modmuss502017-06-07 16:15:55 +0100
committerGravatar asie2018-11-28 09:54:04 +0100
commit493fc21c1cca6487be0d630adfe67ca95e6ae872 (patch)
treef1df8a4b59191e68d00429b0bba88c9f8001c89f /src
parentAdd dark LAF (diff)
downloadenigma-493fc21c1cca6487be0d630adfe67ca95e6ae872.tar.gz
enigma-493fc21c1cca6487be0d630adfe67ca95e6ae872.tar.xz
enigma-493fc21c1cca6487be0d630adfe67ca95e6ae872.zip
Move to awt FileDialog
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java13
-rw-r--r--src/main/java/cuchaz/enigma/gui/elements/MenuBar.java19
2 files changed, 19 insertions, 13 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index 71bf5dcc..cac6ca1c 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;
20import cuchaz.enigma.gui.elements.MenuBar; 20import cuchaz.enigma.gui.elements.MenuBar;
21import cuchaz.enigma.gui.elements.PopupMenuBar; 21import cuchaz.enigma.gui.elements.PopupMenuBar;
22import cuchaz.enigma.gui.filechooser.FileChooserAny; 22import cuchaz.enigma.gui.filechooser.FileChooserAny;
23import cuchaz.enigma.gui.filechooser.FileChooserFile;
24import cuchaz.enigma.gui.filechooser.FileChooserFolder; 23import cuchaz.enigma.gui.filechooser.FileChooserFolder;
25import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter; 24import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter;
26import cuchaz.enigma.gui.highlight.ObfuscatedHighlightPainter; 25import cuchaz.enigma.gui.highlight.ObfuscatedHighlightPainter;
@@ -63,11 +62,11 @@ public class Gui {
63 private final MenuBar menuBar; 62 private final MenuBar menuBar;
64 // state 63 // state
65 public EntryReference<Entry, Entry> reference; 64 public EntryReference<Entry, Entry> reference;
66 public JFileChooser jarFileChooser; 65 public FileDialog jarFileChooser;
67 public JFileChooser tinyMappingsFileChooser; 66 public FileDialog tinyMappingsFileChooser;
68 public JFileChooser enigmaMappingsFileChooser; 67 public JFileChooser enigmaMappingsFileChooser;
69 public JFileChooser exportSourceFileChooser; 68 public JFileChooser exportSourceFileChooser;
70 public JFileChooser exportJarFileChooser; 69 public FileDialog exportJarFileChooser;
71 private GuiController controller; 70 private GuiController controller;
72 private JFrame frame; 71 private JFrame frame;
73 public PanelEditor editor; 72 public PanelEditor editor;
@@ -105,12 +104,12 @@ public class Gui {
105 this.controller = new GuiController(this); 104 this.controller = new GuiController(this);
106 105
107 // init file choosers 106 // init file choosers
108 this.jarFileChooser = new FileChooserFile(); 107 this.jarFileChooser = new FileDialog(getFrame(), "Open Jar", FileDialog.LOAD);
109 108
110 this.tinyMappingsFileChooser = new FileChooserFile(); 109 this.tinyMappingsFileChooser = new FileDialog(getFrame(), "Open tiny Mappings", FileDialog.LOAD);
111 this.enigmaMappingsFileChooser = new FileChooserAny(); 110 this.enigmaMappingsFileChooser = new FileChooserAny();
112 this.exportSourceFileChooser = new FileChooserFolder(); 111 this.exportSourceFileChooser = new FileChooserFolder();
113 this.exportJarFileChooser = new FileChooserFile(); 112 this.exportJarFileChooser = new FileDialog(getFrame(), "Export jar", FileDialog.SAVE);
114 113
115 this.obfPanel = new PanelObf(this); 114 this.obfPanel = new PanelObf(this);
116 this.deobfPanel = new PanelDeobf(this); 115 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 c0568bfb..68742f42 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;
9import javax.swing.*; 9import javax.swing.*;
10import java.awt.event.InputEvent; 10import java.awt.event.InputEvent;
11import java.awt.event.KeyEvent; 11import java.awt.event.KeyEvent;
12import java.io.File;
12import java.io.IOException; 13import java.io.IOException;
13import java.util.jar.JarFile; 14import java.util.jar.JarFile;
14 15
@@ -37,12 +38,14 @@ public class MenuBar extends JMenuBar {
37 JMenuItem item = new JMenuItem("Open Jar..."); 38 JMenuItem item = new JMenuItem("Open Jar...");
38 menu.add(item); 39 menu.add(item);
39 item.addActionListener(event -> { 40 item.addActionListener(event -> {
40 if (this.gui.jarFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 41 this.gui.jarFileChooser.setVisible(true);
42 File file = new File(this.gui.jarFileChooser.getDirectory() + File.separator + this.gui.jarFileChooser.getFile());
43 if (file.exists()) {
41 // load the jar in a separate thread 44 // load the jar in a separate thread
42 new Thread(() -> 45 new Thread(() ->
43 { 46 {
44 try { 47 try {
45 gui.getController().openJar(new JarFile(gui.jarFileChooser.getSelectedFile())); 48 gui.getController().openJar(new JarFile(file));
46 } catch (IOException ex) { 49 } catch (IOException ex) {
47 throw new Error(ex); 50 throw new Error(ex);
48 } 51 }
@@ -78,9 +81,11 @@ public class MenuBar extends JMenuBar {
78 item = new JMenuItem("Tiny"); 81 item = new JMenuItem("Tiny");
79 openMenu.add(item); 82 openMenu.add(item);
80 item.addActionListener(event -> { 83 item.addActionListener(event -> {
81 if (this.gui.tinyMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 84 this.gui.tinyMappingsFileChooser.setVisible(true);
85 File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile());
86 if (file.exists()) {
82 try { 87 try {
83 this.gui.getController().openTinyMappings(this.gui.tinyMappingsFileChooser.getSelectedFile()); 88 this.gui.getController().openTinyMappings(file);
84 } catch (IOException ex) { 89 } catch (IOException ex) {
85 throw new Error(ex); 90 throw new Error(ex);
86 } catch (MappingParseException ex) { 91 } catch (MappingParseException ex) {
@@ -199,8 +204,10 @@ public class MenuBar extends JMenuBar {
199 JMenuItem item = new JMenuItem("Export Jar..."); 204 JMenuItem item = new JMenuItem("Export Jar...");
200 menu.add(item); 205 menu.add(item);
201 item.addActionListener(event -> { 206 item.addActionListener(event -> {
202 if (this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 207 this.gui.tinyMappingsFileChooser.setVisible(true);
203 this.gui.getController().exportJar(this.gui.exportJarFileChooser.getSelectedFile()); 208 if (this.gui.tinyMappingsFileChooser.getFile() != null) {
209 File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile());
210 this.gui.getController().exportJar(file);
204 } 211 }
205 }); 212 });
206 this.exportJarMenu = item; 213 this.exportJarMenu = item;