diff options
| author | 2021-06-19 11:59:54 +0100 | |
|---|---|---|
| committer | 2021-06-19 12:59:54 +0200 | |
| commit | 15581927506a251de278499f9220d1da2c3b7099 (patch) | |
| tree | 3170387fd3fd62095e3198ff3226ed0e4cc56a31 | |
| parent | Structure panel options (#400) (diff) | |
| download | enigma-15581927506a251de278499f9220d1da2c3b7099.tar.gz enigma-15581927506a251de278499f9220d1da2c3b7099.tar.xz enigma-15581927506a251de278499f9220d1da2c3b7099.zip | |
Use JFileChooser for all open/save opertations (#401)
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | 23 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 32 |
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 | ||
| 14 | import java.awt.BorderLayout; | 14 | import java.awt.BorderLayout; |
| 15 | import java.awt.Container; | 15 | import java.awt.Container; |
| 16 | import java.awt.FileDialog; | ||
| 17 | import java.awt.Point; | 16 | import java.awt.Point; |
| 18 | import java.awt.event.*; | 17 | import java.awt.event.*; |
| 19 | import java.nio.file.Path; | 18 | import 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 @@ | |||
| 1 | package cuchaz.enigma.gui.elements; | 1 | package cuchaz.enigma.gui.elements; |
| 2 | 2 | ||
| 3 | import java.awt.FileDialog; | ||
| 4 | import java.awt.event.InputEvent; | 3 | import java.awt.event.InputEvent; |
| 5 | import java.awt.event.KeyEvent; | 4 | import java.awt.event.KeyEvent; |
| 6 | import java.io.File; | 5 | import java.io.File; |
| 7 | import java.io.IOException; | 6 | import java.io.IOException; |
| 8 | import java.nio.file.Files; | 7 | import java.nio.file.Files; |
| 9 | import java.nio.file.Path; | 8 | import java.nio.file.Path; |
| 10 | import java.nio.file.Paths; | ||
| 11 | import java.util.Arrays; | 9 | import java.util.Arrays; |
| 12 | import java.util.Locale; | 10 | import java.util.Locale; |
| 13 | import java.util.Map; | 11 | import 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 | ||