diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/GuiController.java | 23 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 21 |
2 files changed, 19 insertions, 25 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 45c6131..15211e0 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -32,6 +32,7 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 32 | import cuchaz.enigma.utils.ReadableToken; | 32 | import cuchaz.enigma.utils.ReadableToken; |
| 33 | 33 | ||
| 34 | import javax.annotation.Nullable; | 34 | import javax.annotation.Nullable; |
| 35 | import javax.swing.*; | ||
| 35 | import java.awt.event.ItemEvent; | 36 | import java.awt.event.ItemEvent; |
| 36 | import java.io.File; | 37 | import java.io.File; |
| 37 | import java.io.IOException; | 38 | import java.io.IOException; |
| @@ -80,16 +81,22 @@ public class GuiController { | |||
| 80 | this.gui.onCloseJar(); | 81 | this.gui.onCloseJar(); |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | public void openMappings(MappingFormat format, Path path) throws IOException, MappingParseException { | 84 | public void openMappings(MappingFormat format, Path path) { |
| 84 | EntryTree<EntryMapping> mappings = format.read(path); | 85 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> { |
| 85 | deobfuscator.setMappings(mappings); | 86 | try { |
| 87 | EntryTree<EntryMapping> mappings = format.read(path, progress); | ||
| 88 | deobfuscator.setMappings(mappings, progress); | ||
| 86 | 89 | ||
| 87 | gui.setMappingsFile(path); | 90 | gui.setMappingsFile(path); |
| 88 | loadedMappingFormat = format; | 91 | loadedMappingFormat = format; |
| 89 | loadedMappingPath = path; | 92 | loadedMappingPath = path; |
| 90 | 93 | ||
| 91 | refreshClasses(); | 94 | refreshClasses(); |
| 92 | refreshCurrentClass(); | 95 | refreshCurrentClass(); |
| 96 | } catch (MappingParseException e) { | ||
| 97 | JOptionPane.showMessageDialog(this.gui.getFrame(), e.getMessage()); | ||
| 98 | } | ||
| 99 | }); | ||
| 93 | } | 100 | } |
| 94 | 101 | ||
| 95 | public void saveMappings(Path path) { | 102 | public void saveMappings(Path path) { |
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 14ad53d..d7be1a9 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -5,7 +5,6 @@ import cuchaz.enigma.config.Themes; | |||
| 5 | import cuchaz.enigma.gui.Gui; | 5 | import cuchaz.enigma.gui.Gui; |
| 6 | import cuchaz.enigma.gui.dialog.AboutDialog; | 6 | import cuchaz.enigma.gui.dialog.AboutDialog; |
| 7 | import cuchaz.enigma.gui.dialog.SearchDialog; | 7 | import cuchaz.enigma.gui.dialog.SearchDialog; |
| 8 | import cuchaz.enigma.throwables.MappingParseException; | ||
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 8 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 10 | 9 | ||
| 11 | import javax.swing.*; | 10 | import javax.swing.*; |
| @@ -68,15 +67,9 @@ public class MenuBar extends JMenuBar { | |||
| 68 | openMenu.add(item); | 67 | openMenu.add(item); |
| 69 | item.addActionListener(event -> { | 68 | item.addActionListener(event -> { |
| 70 | if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 69 | if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 71 | try { | 70 | File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); |
| 72 | File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); | 71 | MappingFormat format = selectedFile.isDirectory() ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_FILE; |
| 73 | MappingFormat format = selectedFile.isDirectory() ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_FILE; | 72 | this.gui.getController().openMappings(format, selectedFile.toPath()); |
| 74 | this.gui.getController().openMappings(format, selectedFile.toPath()); | ||
| 75 | } catch (IOException ex) { | ||
| 76 | throw new Error(ex); | ||
| 77 | } catch (MappingParseException ex) { | ||
| 78 | JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage()); | ||
| 79 | } | ||
| 80 | } | 73 | } |
| 81 | }); | 74 | }); |
| 82 | this.openEnigmaMappingsMenu = item; | 75 | this.openEnigmaMappingsMenu = item; |
| @@ -87,13 +80,7 @@ public class MenuBar extends JMenuBar { | |||
| 87 | this.gui.tinyMappingsFileChooser.setVisible(true); | 80 | this.gui.tinyMappingsFileChooser.setVisible(true); |
| 88 | File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); | 81 | File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); |
| 89 | if (file.exists()) { | 82 | if (file.exists()) { |
| 90 | try { | 83 | this.gui.getController().openMappings(MappingFormat.TINY_FILE, file.toPath()); |
| 91 | this.gui.getController().openMappings(MappingFormat.TINY_FILE, file.toPath()); | ||
| 92 | } catch (IOException ex) { | ||
| 93 | throw new Error(ex); | ||
| 94 | } catch (MappingParseException ex) { | ||
| 95 | JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage()); | ||
| 96 | } | ||
| 97 | } | 84 | } |
| 98 | }); | 85 | }); |
| 99 | this.openTinyMappingsMenu = item; | 86 | this.openTinyMappingsMenu = item; |