summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/elements
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/elements')
-rw-r--r--src/main/java/cuchaz/enigma/gui/elements/MenuBar.java85
1 files changed, 51 insertions, 34 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
index e79476b..e988d74 100644
--- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
+++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
@@ -17,12 +17,13 @@ public class MenuBar extends JMenuBar {
17 17
18 public final JMenuItem closeJarMenu; 18 public final JMenuItem closeJarMenu;
19 19
20 public final JMenuItem openMappingsMenu; 20 public final JMenuItem openMappingsJsonMenu;
21 public final JMenuItem openOldMappingsMenu; 21 public final JMenuItem openEnigmaMappingsMenu;
22 22
23 public final JMenuItem saveMappingsMenu; 23 public final JMenuItem saveMappingsMenu;
24 public final JMenuItem saveMappingsAsMenu; 24 public final JMenuItem saveMappingsJsonMenu;
25 public final JMenuItem saveMappingsOldMenu; 25 public final JMenuItem saveMappingEnigmaFileMenu;
26 public final JMenuItem saveMappingEnigmaDirectoryMenu;
26 public final JMenuItem saveMappingsSrgMenu; 27 public final JMenuItem saveMappingsSrgMenu;
27 public final JMenuItem closeMappingsMenu; 28 public final JMenuItem closeMappingsMenu;
28 29
@@ -62,43 +63,44 @@ public class MenuBar extends JMenuBar {
62 this.closeJarMenu = item; 63 this.closeJarMenu = item;
63 } 64 }
64 menu.addSeparator(); 65 menu.addSeparator();
66 JMenu openMenu = new JMenu("Open Mappings...");
65 { 67 {
66 JMenuItem item = new JMenuItem("Open Mappings..."); 68 JMenuItem item = new JMenuItem("Enigma");
67 menu.add(item); 69 openMenu.add(item);
68 item.addActionListener(event -> { 70 item.addActionListener(event -> {
69 if (this.gui.mappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 71 if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
70 try { 72 try {
71 this.gui.getController().openMappings(this.gui.mappingsFileChooser.getSelectedFile()); 73 this.gui.getController().openEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile());
72 } catch (IOException ex) { 74 } catch (IOException ex) {
73 throw new Error(ex); 75 throw new Error(ex);
76 } catch (MappingParseException ex) {
77 JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
74 } 78 }
75 } 79 }
76 }); 80 });
77 this.openMappingsMenu = item; 81 this.openEnigmaMappingsMenu = item;
78 } 82 }
83 menu.add(openMenu);
79 { 84 {
80 JMenuItem item = new JMenuItem("Open Old Mappings..."); 85 JMenuItem item = new JMenuItem("JSON (directory)");
81 menu.add(item); 86 openMenu.add(item);
82 item.addActionListener(event -> { 87 item.addActionListener(event -> {
83 if (this.gui.oldMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 88 if (this.gui.jsonMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
84 try { 89 try {
85 this.gui.getController().openOldMappings(this.gui.oldMappingsFileChooser.getSelectedFile()); 90 this.gui.getController().openJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
86 } catch (IOException ex) { 91 } catch (IOException ex) {
87 throw new Error(ex); 92 throw new Error(ex);
88 } catch (MappingParseException ex) {
89 JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
90 } 93 }
91 } 94 }
92 }); 95 });
93 this.openOldMappingsMenu = item; 96 this.openMappingsJsonMenu = item;
94 } 97 }
95 menu.addSeparator();
96 { 98 {
97 JMenuItem item = new JMenuItem("Save Mappings"); 99 JMenuItem item = new JMenuItem("Save Mappings");
98 menu.add(item); 100 menu.add(item);
99 item.addActionListener(event -> { 101 item.addActionListener(event -> {
100 try { 102 try {
101 this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile()); 103 this.gui.getController().saveMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
102 } catch (IOException ex) { 104 } catch (IOException ex) {
103 throw new Error(ex); 105 throw new Error(ex);
104 } 106 }
@@ -106,29 +108,29 @@ public class MenuBar extends JMenuBar {
106 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); 108 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
107 this.saveMappingsMenu = item; 109 this.saveMappingsMenu = item;
108 } 110 }
111 JMenu saveMenu = new JMenu("Save Mappings As...");
109 { 112 {
110 JMenuItem item = new JMenuItem("Save Mappings As..."); 113 JMenuItem item = new JMenuItem("Enigma (single file)");
111 menu.add(item); 114 saveMenu.add(item);
112 item.addActionListener(event -> { 115 item.addActionListener(event -> {
113 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 116 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
114 try { 117 try {
115 this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile()); 118 this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), false);
116 this.saveMappingsMenu.setEnabled(true); 119 this.saveMappingsMenu.setEnabled(true);
117 } catch (IOException ex) { 120 } catch (IOException ex) {
118 throw new Error(ex); 121 throw new Error(ex);
119 } 122 }
120 } 123 }
121 }); 124 });
122 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 125 this.saveMappingEnigmaFileMenu = item;
123 this.saveMappingsAsMenu = item;
124 } 126 }
125 { 127 {
126 JMenuItem item = new JMenuItem("Save Mappings as Enigma"); 128 JMenuItem item = new JMenuItem("Enigma (directory)");
127 menu.add(item); 129 saveMenu.add(item);
128 item.addActionListener(event -> { 130 item.addActionListener(event -> {
129 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 131 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
130 try { 132 try {
131 this.gui.getController().saveOldMappings(this.gui.mappingsFileChooser.getSelectedFile()); 133 this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), true);
132 this.saveMappingsMenu.setEnabled(true); 134 this.saveMappingsMenu.setEnabled(true);
133 } catch (IOException ex) { 135 } catch (IOException ex) {
134 throw new Error(ex); 136 throw new Error(ex);
@@ -136,22 +138,37 @@ public class MenuBar extends JMenuBar {
136 } 138 }
137 }); 139 });
138 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 140 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
139 this.saveMappingsOldMenu = item; 141 this.saveMappingEnigmaDirectoryMenu = item;
140 } 142 }
143 menu.add(saveMenu);
141 { 144 {
142 JMenuItem item = new JMenuItem("Save Mappings as SRG"); 145 JMenuItem item = new JMenuItem("JSON (directory)");
143 menu.add(item); 146 saveMenu.add(item);
144 item.addActionListener(event -> { 147 item.addActionListener(event -> {
145 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 148 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
146 try { 149 try {
147 this.gui.getController().saveSRGMappings(this.gui.mappingsFileChooser.getSelectedFile()); 150 this.gui.getController().saveJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
151 this.saveMappingsMenu.setEnabled(true);
152 } catch (IOException ex) {
153 throw new Error(ex);
154 }
155 }
156 });
157 this.saveMappingsJsonMenu = item;
158 }
159 {
160 JMenuItem item = new JMenuItem("SRG");
161 saveMenu.add(item);
162 item.addActionListener(event -> {
163 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
164 try {
165 this.gui.getController().saveSRGMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
148 this.saveMappingsMenu.setEnabled(true); 166 this.saveMappingsMenu.setEnabled(true);
149 } catch (IOException ex) { 167 } catch (IOException ex) {
150 throw new Error(ex); 168 throw new Error(ex);
151 } 169 }
152 } 170 }
153 }); 171 });
154 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
155 this.saveMappingsSrgMenu = item; 172 this.saveMappingsSrgMenu = item;
156 } 173 }
157 { 174 {