Skip to content

Commit d1a28c3

Browse files
committed
Improve cancellation in Preferences
It should reset values in the fields, when changes are cancelled.
1 parent 39a9d20 commit d1a28c3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/main/java/com/itextpdf/rups/view/PreferencesWindow.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ This file is part of the iText (R) project.
5151
import java.awt.GridBagConstraints;
5252
import java.awt.GridBagLayout;
5353
import java.awt.Insets;
54+
import java.awt.event.ActionEvent;
5455
import java.awt.event.ItemEvent;
5556
import java.awt.event.WindowAdapter;
5657
import 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

Comments
 (0)