diff options
| author | 2019-09-08 13:43:13 +0100 | |
|---|---|---|
| committer | 2019-09-08 13:43:13 +0100 | |
| commit | 62b3d007a21f1ca737ca925b133fb1d3cdbff08e (patch) | |
| tree | 9bb884ab96a4bbf57877c15fc221f7f7ff13cf12 /src/main | |
| parent | Use name proposal service when exporting deobfuscated jar or decompiled sourc... (diff) | |
| download | enigma-62b3d007a21f1ca737ca925b133fb1d3cdbff08e.tar.gz enigma-62b3d007a21f1ca737ca925b133fb1d3cdbff08e.tar.xz enigma-62b3d007a21f1ca737ca925b133fb1d3cdbff08e.zip | |
Cleanup the mappings menu items to use the mappings format enum, will be useful for when adding more formats
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/Gui.java | 15 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 91 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/utils/Utils.java | 10 |
3 files changed, 47 insertions, 69 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 5b9a3315..52a97bbe 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -46,6 +46,7 @@ import java.awt.event.*; | |||
| 46 | import java.nio.file.Path; | 46 | import java.nio.file.Path; |
| 47 | import java.util.List; | 47 | import java.util.List; |
| 48 | import java.util.*; | 48 | import java.util.*; |
| 49 | import java.util.function.Consumer; | ||
| 49 | import java.util.function.Function; | 50 | import java.util.function.Function; |
| 50 | 51 | ||
| 51 | public class Gui { | 52 | public class Gui { |
| @@ -325,12 +326,9 @@ public class Gui { | |||
| 325 | 326 | ||
| 326 | // update menu | 327 | // update menu |
| 327 | this.menuBar.closeJarMenu.setEnabled(true); | 328 | this.menuBar.closeJarMenu.setEnabled(true); |
| 328 | this.menuBar.openTinyMappingsMenu.setEnabled(true); | 329 | this.menuBar.openMappingsMenus.forEach(item -> item.setEnabled(true)); |
| 329 | this.menuBar.openEnigmaMappingsMenu.setEnabled(true); | ||
| 330 | this.menuBar.saveMappingsMenu.setEnabled(false); | 330 | this.menuBar.saveMappingsMenu.setEnabled(false); |
| 331 | this.menuBar.saveMappingEnigmaFileMenu.setEnabled(true); | 331 | this.menuBar.saveMappingsMenus.forEach(item -> item.setEnabled(true)); |
| 332 | this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(true); | ||
| 333 | this.menuBar.saveMappingsSrgMenu.setEnabled(true); | ||
| 334 | this.menuBar.closeMappingsMenu.setEnabled(true); | 332 | this.menuBar.closeMappingsMenu.setEnabled(true); |
| 335 | this.menuBar.exportSourceMenu.setEnabled(true); | 333 | this.menuBar.exportSourceMenu.setEnabled(true); |
| 336 | this.menuBar.exportJarMenu.setEnabled(true); | 334 | this.menuBar.exportJarMenu.setEnabled(true); |
| @@ -348,12 +346,9 @@ public class Gui { | |||
| 348 | 346 | ||
| 349 | // update menu | 347 | // update menu |
| 350 | this.menuBar.closeJarMenu.setEnabled(false); | 348 | this.menuBar.closeJarMenu.setEnabled(false); |
| 351 | this.menuBar.openTinyMappingsMenu.setEnabled(false); | 349 | this.menuBar.openMappingsMenus.forEach(item -> item.setEnabled(false)); |
| 352 | this.menuBar.openEnigmaMappingsMenu.setEnabled(false); | ||
| 353 | this.menuBar.saveMappingsMenu.setEnabled(false); | 350 | this.menuBar.saveMappingsMenu.setEnabled(false); |
| 354 | this.menuBar.saveMappingEnigmaFileMenu.setEnabled(false); | 351 | this.menuBar.saveMappingsMenus.forEach(item -> item.setEnabled(false)); |
| 355 | this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(false); | ||
| 356 | this.menuBar.saveMappingsSrgMenu.setEnabled(false); | ||
| 357 | this.menuBar.closeMappingsMenu.setEnabled(false); | 352 | this.menuBar.closeMappingsMenu.setEnabled(false); |
| 358 | this.menuBar.exportSourceMenu.setEnabled(false); | 353 | this.menuBar.exportSourceMenu.setEnabled(false); |
| 359 | this.menuBar.exportJarMenu.setEnabled(false); | 354 | this.menuBar.exportJarMenu.setEnabled(false); |
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index a3bd2fe5..45daaca6 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -6,6 +6,7 @@ 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.translation.mapping.serde.MappingFormat; | 8 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 9 | import cuchaz.enigma.utils.Utils; | ||
| 9 | 10 | ||
| 10 | import javax.swing.*; | 11 | import javax.swing.*; |
| 11 | import java.awt.*; | 12 | import java.awt.*; |
| @@ -18,16 +19,15 @@ import java.net.URL; | |||
| 18 | import java.nio.file.Files; | 19 | import java.nio.file.Files; |
| 19 | import java.nio.file.Path; | 20 | import java.nio.file.Path; |
| 20 | import java.nio.file.Paths; | 21 | import java.nio.file.Paths; |
| 22 | import java.util.ArrayList; | ||
| 23 | import java.util.List; | ||
| 21 | 24 | ||
| 22 | public class MenuBar extends JMenuBar { | 25 | public class MenuBar extends JMenuBar { |
| 23 | 26 | ||
| 24 | public final JMenuItem closeJarMenu; | 27 | public final JMenuItem closeJarMenu; |
| 25 | public final JMenuItem openEnigmaMappingsMenu; | 28 | public final List<JMenuItem> openMappingsMenus; |
| 26 | public final JMenuItem openTinyMappingsMenu; | ||
| 27 | public final JMenuItem saveMappingsMenu; | 29 | public final JMenuItem saveMappingsMenu; |
| 28 | public final JMenuItem saveMappingEnigmaFileMenu; | 30 | public final List<JMenuItem> saveMappingsMenus; |
| 29 | public final JMenuItem saveMappingEnigmaDirectoryMenu; | ||
| 30 | public final JMenuItem saveMappingsSrgMenu; | ||
| 31 | public final JMenuItem closeMappingsMenu; | 31 | public final JMenuItem closeMappingsMenu; |
| 32 | public final JMenuItem dropMappingsMenu; | 32 | public final JMenuItem dropMappingsMenu; |
| 33 | public final JMenuItem exportSourceMenu; | 33 | public final JMenuItem exportSourceMenu; |
| @@ -61,27 +61,20 @@ public class MenuBar extends JMenuBar { | |||
| 61 | JMenu openMenu = new JMenu("Open Mappings..."); | 61 | JMenu openMenu = new JMenu("Open Mappings..."); |
| 62 | menu.add(openMenu); | 62 | menu.add(openMenu); |
| 63 | { | 63 | { |
| 64 | JMenuItem item = new JMenuItem("Enigma"); | 64 | openMappingsMenus = new ArrayList<>(); |
| 65 | openMenu.add(item); | 65 | for(MappingFormat format : MappingFormat.values()){ |
| 66 | item.addActionListener(event -> { | 66 | if(format.getReader() != null){ |
| 67 | if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 67 | JMenuItem item = new JMenuItem(Utils.caplisiseCamelCase(format.name())); |
| 68 | File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); | 68 | openMenu.add(item); |
| 69 | MappingFormat format = selectedFile.isDirectory() ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_FILE; | 69 | item.addActionListener(event -> { |
| 70 | this.gui.getController().openMappings(format, selectedFile.toPath()); | 70 | if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 71 | } | 71 | File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); |
| 72 | }); | 72 | this.gui.getController().openMappings(format, selectedFile.toPath()); |
| 73 | this.openEnigmaMappingsMenu = item; | 73 | } |
| 74 | 74 | }); | |
| 75 | item = new JMenuItem("Tiny"); | 75 | openMappingsMenus.add(item); |
| 76 | openMenu.add(item); | ||
| 77 | item.addActionListener(event -> { | ||
| 78 | this.gui.tinyMappingsFileChooser.setVisible(true); | ||
| 79 | File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); | ||
| 80 | if (file.exists()) { | ||
| 81 | this.gui.getController().openMappings(MappingFormat.TINY_FILE, file.toPath()); | ||
| 82 | } | 76 | } |
| 83 | }); | 77 | } |
| 84 | this.openTinyMappingsMenu = item; | ||
| 85 | } | 78 | } |
| 86 | { | 79 | { |
| 87 | JMenuItem item = new JMenuItem("Save Mappings"); | 80 | JMenuItem item = new JMenuItem("Save Mappings"); |
| @@ -95,41 +88,21 @@ public class MenuBar extends JMenuBar { | |||
| 95 | JMenu saveMenu = new JMenu("Save Mappings As..."); | 88 | JMenu saveMenu = new JMenu("Save Mappings As..."); |
| 96 | menu.add(saveMenu); | 89 | menu.add(saveMenu); |
| 97 | { | 90 | { |
| 98 | JMenuItem item = new JMenuItem("Enigma (single file)"); | 91 | saveMappingsMenus = new ArrayList<>(); |
| 99 | saveMenu.add(item); | 92 | for(MappingFormat format : MappingFormat.values()){ |
| 100 | item.addActionListener(event -> { | 93 | if(format.getWriter() != null){ |
| 101 | // TODO: Use a specific file chooser for it | 94 | JMenuItem item = new JMenuItem(Utils.caplisiseCamelCase(format.name())); |
| 102 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 95 | saveMenu.add(item); |
| 103 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_FILE); | 96 | item.addActionListener(event -> { |
| 104 | this.saveMappingsMenu.setEnabled(true); | 97 | // TODO: Use a specific file chooser for it |
| 105 | } | 98 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 106 | }); | 99 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); |
| 107 | this.saveMappingEnigmaFileMenu = item; | 100 | this.saveMappingsMenu.setEnabled(true); |
| 108 | } | 101 | } |
| 109 | { | 102 | }); |
| 110 | JMenuItem item = new JMenuItem("Enigma (directory)"); | 103 | saveMappingsMenus.add(item); |
| 111 | saveMenu.add(item); | ||
| 112 | item.addActionListener(event -> { | ||
| 113 | // TODO: Use a specific file chooser for it | ||
| 114 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 115 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_DIRECTORY); | ||
| 116 | this.saveMappingsMenu.setEnabled(true); | ||
| 117 | } | ||
| 118 | }); | ||
| 119 | item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); | ||
| 120 | this.saveMappingEnigmaDirectoryMenu = item; | ||
| 121 | } | ||
| 122 | { | ||
| 123 | JMenuItem item = new JMenuItem("SRG (single file)"); | ||
| 124 | saveMenu.add(item); | ||
| 125 | item.addActionListener(event -> { | ||
| 126 | // TODO: Use a specific file chooser for it | ||
| 127 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 128 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.SRG_FILE); | ||
| 129 | this.saveMappingsMenu.setEnabled(true); | ||
| 130 | } | 104 | } |
| 131 | }); | 105 | } |
| 132 | this.saveMappingsSrgMenu = item; | ||
| 133 | } | 106 | } |
| 134 | { | 107 | { |
| 135 | JMenuItem item = new JMenuItem("Close Mappings"); | 108 | JMenuItem item = new JMenuItem("Close Mappings"); |
diff --git a/src/main/java/cuchaz/enigma/utils/Utils.java b/src/main/java/cuchaz/enigma/utils/Utils.java index 67880428..1134c2a8 100644 --- a/src/main/java/cuchaz/enigma/utils/Utils.java +++ b/src/main/java/cuchaz/enigma/utils/Utils.java | |||
| @@ -25,6 +25,8 @@ import java.nio.file.Files; | |||
| 25 | import java.nio.file.Path; | 25 | import java.nio.file.Path; |
| 26 | import java.util.Comparator; | 26 | import java.util.Comparator; |
| 27 | import java.util.List; | 27 | import java.util.List; |
| 28 | import java.util.Locale; | ||
| 29 | import java.util.StringJoiner; | ||
| 28 | import java.util.stream.Collectors; | 30 | import java.util.stream.Collectors; |
| 29 | 31 | ||
| 30 | public class Utils { | 32 | public class Utils { |
| @@ -105,4 +107,12 @@ public class Utils { | |||
| 105 | } | 107 | } |
| 106 | } | 108 | } |
| 107 | } | 109 | } |
| 110 | |||
| 111 | public static String caplisiseCamelCase(String input){ | ||
| 112 | StringJoiner stringJoiner = new StringJoiner(" "); | ||
| 113 | for(String word : input.toLowerCase(Locale.ROOT).split("_")){ | ||
| 114 | stringJoiner.add(word.substring(0, 1).toUpperCase() + word.substring(1)); | ||
| 115 | } | ||
| 116 | return stringJoiner.toString(); | ||
| 117 | } | ||
| 108 | } | 118 | } |