@@ -51,6 +51,7 @@ This file is part of the iText (R) project.
5151import java .awt .GridBagConstraints ;
5252import java .awt .GridBagLayout ;
5353import java .awt .Insets ;
54+ import java .awt .event .ActionEvent ;
5455import java .awt .event .ItemEvent ;
5556import java .awt .event .WindowAdapter ;
5657import java .awt .event .WindowEvent ;
@@ -247,18 +248,7 @@ private void createSaveCancelResetSection() {
247248 buttons .add (save );
248249
249250 JButton cancel = new JButton (Language .DIALOG_CANCEL .getString ());
250- cancel .addActionListener (e -> {
251- if (RupsConfiguration .INSTANCE .hasUnsavedChanges ()) {
252- int choice = JOptionPane .showConfirmDialog (jDialog ,
253- Language .SAVE_UNSAVED_CHANGES .getString ());
254- if (choice == JOptionPane .OK_OPTION ) {
255- RupsConfiguration .INSTANCE .cancelTemporaryChanges ();
256- this .jDialog .dispose ();
257- }
258- } else {
259- this .jDialog .dispose ();
260- }
261- });
251+ cancel .addActionListener (this ::handleCancel );
262252 buttons .add (cancel );
263253
264254 JButton reset = new JButton (Language .PREFERENCES_RESET_TO_DEFAULTS .getString ());
@@ -293,4 +283,19 @@ public void show(Component component) {
293283 jDialog .setLocationRelativeTo (component );
294284 jDialog .setVisible (true );
295285 }
286+
287+ private void handleCancel (ActionEvent e ) {
288+ // Warn user of unsaved changes via dialog
289+ if (RupsConfiguration .INSTANCE .hasUnsavedChanges ()) {
290+ final int choice = JOptionPane .showConfirmDialog (
291+ jDialog , Language .SAVE_UNSAVED_CHANGES .getString ()
292+ );
293+ if (choice != JOptionPane .OK_OPTION ) {
294+ return ;
295+ }
296+ }
297+ RupsConfiguration .INSTANCE .cancelTemporaryChanges ();
298+ resetView ();
299+ jDialog .dispose ();
300+ }
296301}
0 commit comments