summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/elements
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/main/java/cuchaz/enigma/gui/elements
parentAdd dark LAF (diff)
downloadenigma-fork-493fc21c1cca6487be0d630adfe67ca95e6ae872.tar.gz
enigma-fork-493fc21c1cca6487be0d630adfe67ca95e6ae872.tar.xz
enigma-fork-493fc21c1cca6487be0d630adfe67ca95e6ae872.zip
Move to awt FileDialog
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/elements')
-rw-r--r--src/main/java/cuchaz/enigma/gui/elements/MenuBar.java19
1 files changed, 13 insertions, 6 deletions
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;
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;