summaryrefslogtreecommitdiff
path: root/enigma-swing/src/main/java/cuchaz
diff options
context:
space:
mode:
authorGravatar modmuss502021-06-19 11:59:54 +0100
committerGravatar GitHub2021-06-19 12:59:54 +0200
commit15581927506a251de278499f9220d1da2c3b7099 (patch)
tree3170387fd3fd62095e3198ff3226ed0e4cc56a31 /enigma-swing/src/main/java/cuchaz
parentStructure panel options (#400) (diff)
downloadenigma-15581927506a251de278499f9220d1da2c3b7099.tar.gz
enigma-15581927506a251de278499f9220d1da2c3b7099.tar.xz
enigma-15581927506a251de278499f9220d1da2c3b7099.zip
Use JFileChooser for all open/save opertations (#401)
Diffstat (limited to 'enigma-swing/src/main/java/cuchaz')
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java23
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java32
2 files changed, 35 insertions, 20 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
index 60c535f5..52bd93ee 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -13,7 +13,6 @@ package cuchaz.enigma.gui;
13 13
14import java.awt.BorderLayout; 14import java.awt.BorderLayout;
15import java.awt.Container; 15import java.awt.Container;
16import java.awt.FileDialog;
17import java.awt.Point; 16import java.awt.Point;
18import java.awt.event.*; 17import java.awt.event.*;
19import java.nio.file.Path; 18import java.nio.file.Path;
@@ -75,11 +74,11 @@ public class Gui implements LanguageChangeListener {
75 private ConnectionState connectionState; 74 private ConnectionState connectionState;
76 private boolean isJarOpen; 75 private boolean isJarOpen;
77 76
78 public FileDialog jarFileChooser; 77 public JFileChooser jarFileChooser;
79 public FileDialog tinyMappingsFileChooser; 78 public JFileChooser tinyMappingsFileChooser;
80 public JFileChooser enigmaMappingsFileChooser; 79 public JFileChooser enigmaMappingsFileChooser;
81 public JFileChooser exportSourceFileChooser; 80 public JFileChooser exportSourceFileChooser;
82 public FileDialog exportJarFileChooser; 81 public JFileChooser exportJarFileChooser;
83 public SearchDialog searchDialog; 82 public SearchDialog searchDialog;
84 private GuiController controller; 83 private GuiController controller;
85 private JFrame frame; 84 private JFrame frame;
@@ -135,9 +134,13 @@ public class Gui implements LanguageChangeListener {
135 this.controller = new GuiController(this, profile); 134 this.controller = new GuiController(this, profile);
136 135
137 // init file choosers 136 // init file choosers
138 this.jarFileChooser = new FileDialog(getFrame(), I18n.translate("menu.file.jar.open"), FileDialog.LOAD); 137 this.jarFileChooser = new JFileChooser();
138 this.jarFileChooser.setDialogTitle(I18n.translate("menu.file.jar.open"));
139 this.jarFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
139 140
140 this.tinyMappingsFileChooser = new FileDialog(getFrame(), "Open tiny Mappings", FileDialog.LOAD); 141 this.tinyMappingsFileChooser = new JFileChooser();
142 this.tinyMappingsFileChooser.setDialogTitle("Open tiny Mappings");
143 this.tinyMappingsFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
141 144
142 this.enigmaMappingsFileChooser = new JFileChooser(); 145 this.enigmaMappingsFileChooser = new JFileChooser();
143 this.enigmaMappingsFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 146 this.enigmaMappingsFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
@@ -147,7 +150,9 @@ public class Gui implements LanguageChangeListener {
147 this.exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 150 this.exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
148 this.exportSourceFileChooser.setAcceptAllFileFilterUsed(false); 151 this.exportSourceFileChooser.setAcceptAllFileFilterUsed(false);
149 152
150 this.exportJarFileChooser = new FileDialog(getFrame(), I18n.translate("menu.file.export.jar"), FileDialog.SAVE); 153 this.exportJarFileChooser = new JFileChooser();
154 this.exportJarFileChooser.setDialogTitle(I18n.translate("menu.file.export.jar"));
155 this.exportJarFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
151 156
152 this.obfPanel = new ObfPanel(this); 157 this.obfPanel = new ObfPanel(this);
153 this.deobfPanel = new DeobfPanel(this); 158 this.deobfPanel = new DeobfPanel(this);
@@ -931,8 +936,8 @@ public class Gui implements LanguageChangeListener {
931 936
932 @Override 937 @Override
933 public void retranslateUi() { 938 public void retranslateUi() {
934 this.jarFileChooser.setTitle(I18n.translate("menu.file.jar.open")); 939 this.jarFileChooser.setDialogTitle(I18n.translate("menu.file.jar.open"));
935 this.exportJarFileChooser.setTitle(I18n.translate("menu.file.export.jar")); 940 this.exportJarFileChooser.setDialogTitle(I18n.translate("menu.file.export.jar"));
936 this.tabs.setTitleAt(0, I18n.translate("info_panel.tree.structure")); 941 this.tabs.setTitleAt(0, I18n.translate("info_panel.tree.structure"));
937 this.tabs.setTitleAt(1, I18n.translate("info_panel.tree.inheritance")); 942 this.tabs.setTitleAt(1, I18n.translate("info_panel.tree.inheritance"));
938 this.tabs.setTitleAt(2, I18n.translate("info_panel.tree.implementations")); 943 this.tabs.setTitleAt(2, I18n.translate("info_panel.tree.implementations"));
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
index 39aaebb5..6603dd55 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
@@ -1,13 +1,11 @@
1package cuchaz.enigma.gui.elements; 1package cuchaz.enigma.gui.elements;
2 2
3import java.awt.FileDialog;
4import java.awt.event.InputEvent; 3import java.awt.event.InputEvent;
5import java.awt.event.KeyEvent; 4import java.awt.event.KeyEvent;
6import java.io.File; 5import java.io.File;
7import java.io.IOException; 6import java.io.IOException;
8import java.nio.file.Files; 7import java.nio.file.Files;
9import java.nio.file.Path; 8import java.nio.file.Path;
10import java.nio.file.Paths;
11import java.util.Arrays; 9import java.util.Arrays;
12import java.util.Locale; 10import java.util.Locale;
13import java.util.Map; 11import java.util.Map;
@@ -217,18 +215,24 @@ public class MenuBar {
217 } 215 }
218 216
219 private void onOpenJarClicked() { 217 private void onOpenJarClicked() {
220 FileDialog d = this.gui.jarFileChooser; 218 JFileChooser d = this.gui.jarFileChooser;
221 d.setDirectory(UiConfig.getLastSelectedDir()); 219 d.setCurrentDirectory(new File(UiConfig.getLastSelectedDir()));
222 d.setVisible(true); 220 d.setVisible(true);
223 String file = d.getFile(); 221 int result = d.showOpenDialog(gui.getFrame());
222
223 if (result != JFileChooser.APPROVE_OPTION) {
224 return;
225 }
226
227 File file = d.getSelectedFile();
224 // checks if the file name is not empty 228 // checks if the file name is not empty
225 if (file != null) { 229 if (file != null) {
226 Path path = Paths.get(d.getDirectory()).resolve(file); 230 Path path = file.toPath();
227 // checks if the file name corresponds to an existing file 231 // checks if the file name corresponds to an existing file
228 if (Files.exists(path)) { 232 if (Files.exists(path)) {
229 this.gui.getController().openJar(path); 233 this.gui.getController().openJar(path);
230 } 234 }
231 UiConfig.setLastSelectedDir(d.getDirectory()); 235 UiConfig.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath());
232 } 236 }
233 } 237 }
234 238
@@ -272,12 +276,18 @@ public class MenuBar {
272 } 276 }
273 277
274 private void onExportJarClicked() { 278 private void onExportJarClicked() {
275 this.gui.exportJarFileChooser.setDirectory(UiConfig.getLastSelectedDir()); 279 this.gui.exportJarFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir()));
276 this.gui.exportJarFileChooser.setVisible(true); 280 this.gui.exportJarFileChooser.setVisible(true);
277 if (this.gui.exportJarFileChooser.getFile() != null) { 281 int result = this.gui.exportJarFileChooser.showSaveDialog(gui.getFrame());
278 Path path = Paths.get(this.gui.exportJarFileChooser.getDirectory(), this.gui.exportJarFileChooser.getFile()); 282
283 if (result != JFileChooser.APPROVE_OPTION) {
284 return;
285 }
286
287 if (this.gui.exportJarFileChooser.getSelectedFile() != null) {
288 Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath();
279 this.gui.getController().exportJar(path); 289 this.gui.getController().exportJar(path);
280 UiConfig.setLastSelectedDir(this.gui.exportJarFileChooser.getDirectory()); 290 UiConfig.setLastSelectedDir(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath());
281 } 291 }
282 } 292 }
283 293