@@ -28,7 +28,7 @@ public class MemEdit {
28
28
29
29
private NRAM nram = null ;
30
30
31
- public final JDialog frame = new JDialog (Main .ui .frame , "Memory Viewer" );
31
+ public final JDialog frame = new JDialog (Main .ui .frame , "Memory Viewer" , Dialog . ModalityType . MODELESS );
32
32
private final JMenuBar menu = new JMenuBar ();
33
33
private final FilenameFilter hexFilter = new FilenameFilter () {
34
34
@ Override
@@ -155,6 +155,42 @@ public void jumpTo(int adr) {
155
155
scroll .setValue (adr / memView .getCellsPerRow ());
156
156
}
157
157
158
+ /**
159
+ * Handles a save action to save the data
160
+ * @param e The event that triggered the action
161
+ * @param shouldClose Whether the window should close after a successful save
162
+ */
163
+ private void saveActionPerformed (ActionEvent e , boolean shouldClose ) {
164
+ Preferences prefs = Preferences .userNodeForPackage (MemEdit .class );
165
+ FileDialog fd = new FileDialog (frame , "Save Hex-encoded data" , FileDialog .SAVE );
166
+ fd .setFilenameFilter (hexFilter );
167
+ // can just append .hex if the user doesn't
168
+ if (Main .sim .filePath .isEmpty ()) {
169
+ fd .setFile ("*.hex" );
170
+ } else {
171
+ int ind = Main .sim .filePath .lastIndexOf ('/' );
172
+ fd .setFile (Main .sim .filePath .substring (ind + 1 ));
173
+ }
174
+
175
+ fd .setDirectory (prefs .get ("hex_fileDir" , "" ));
176
+ fd .setVisible (true );
177
+
178
+ if (fd .getFile () != null ) {
179
+ String path = fd .getDirectory () + fd .getFile ();
180
+
181
+ // Is the file being created with the correct extension?
182
+ if (!path .endsWith (".hex" )) {
183
+ path = path + ".hex" ;
184
+ }
185
+
186
+ HexWriter .writeFile (new File (path ), nram );
187
+
188
+ if (shouldClose ) {
189
+ close ();
190
+ }
191
+ }
192
+ }
193
+
158
194
/**
159
195
* Fills the file menu
160
196
*/
@@ -209,34 +245,31 @@ else if (res == JOptionPane.NO_OPTION) {
209
245
file .add (menuItem );
210
246
211
247
menuItem = new JMenuItem ("Save Data" );
212
- menuItem .setMnemonic (KeyEvent .VK_O );
248
+ menuItem .setMnemonic (KeyEvent .VK_S );
213
249
menuItem .setToolTipText ("Saves the current NRAM contents to a hex data file" );
214
250
menuItem .addActionListener (new ActionListener () {
215
251
public void actionPerformed (ActionEvent e ) {
216
- Preferences prefs = Preferences .userNodeForPackage (MemEdit .class );
217
- FileDialog fd = new FileDialog (frame , "Save Hex-encoded data" , FileDialog .SAVE );
218
- fd .setFilenameFilter (hexFilter );
219
- // can just append .hex if the user doesn't
220
- if (Main .sim .filePath .isEmpty ()) {
221
- fd .setFile ("*.hex" );
222
- } else {
223
- int ind = Main .sim .filePath .lastIndexOf ('/' );
224
- fd .setFile (Main .sim .filePath .substring (ind + 1 ));
225
- }
226
-
227
- fd .setDirectory (prefs .get ("hex_fileDir" , "" ));
228
- fd .setVisible (true );
229
-
230
- if (fd .getFile () != null ) {
231
- String path = fd .getDirectory () + fd .getFile ();
252
+ saveActionPerformed (e , false );
253
+ }
254
+ });
255
+ file .add (menuItem );
232
256
233
- // Is the file being created with the correct extension?
234
- if (!path .endsWith (".hex" )) {
235
- path = path + ".hex" ;
236
- }
257
+ menuItem = new JMenuItem ("Close without save" );
258
+ menuItem .setMnemonic (KeyEvent .VK_X );
259
+ menuItem .setToolTipText ("Closes the window without saving NRAM contents" );
260
+ menuItem .addActionListener (new ActionListener () {
261
+ public void actionPerformed (ActionEvent e ) {
262
+ close ();
263
+ }
264
+ });
265
+ file .add (menuItem );
237
266
238
- HexWriter .writeFile (new File (path ), nram );
239
- }
267
+ menuItem = new JMenuItem ("Close with save" );
268
+ menuItem .setMnemonic (KeyEvent .VK_D );
269
+ menuItem .setToolTipText ("Saves the current NRAM contents to a hex data file and closes the window" );
270
+ menuItem .addActionListener (new ActionListener () {
271
+ public void actionPerformed (ActionEvent e ) {
272
+ saveActionPerformed (e , true );
240
273
}
241
274
});
242
275
file .add (menuItem );
0 commit comments