77import java .awt .Component ;
88import java .awt .GridBagConstraints ;
99import java .awt .GridBagLayout ;
10+ import java .awt .event .WindowAdapter ;
11+ import java .awt .event .WindowEvent ;
12+ import java .awt .event .WindowListener ;
1013import java .util .Locale ;
1114import javax .swing .JButton ;
1215import javax .swing .JCheckBox ;
@@ -38,6 +41,8 @@ public class PreferencesWindow {
3841 // Fields to reset
3942 private JCheckBox openDuplicateFiles ;
4043 private JTextField pathField ;
44+ private JLabel restartLabel ;
45+ private JComboBox <String > localeBox ;
4146
4247 public PreferencesWindow () {
4348 initializeJDialog ();
@@ -59,6 +64,13 @@ private void initializeJDialog() {
5964 this .jDialog .setDefaultCloseOperation (WindowConstants .DISPOSE_ON_CLOSE );
6065 this .jDialog .setModal (true );
6166 this .jDialog .setLayout (new BorderLayout ());
67+ this .jDialog .addWindowListener (new WindowAdapter () {
68+ @ Override
69+ public void windowClosing (WindowEvent e ) {
70+ RupsConfiguration .INSTANCE .cancelTemporaryChanges ();
71+ resetView ();
72+ }
73+ });
6274 }
6375
6476 private void initializeLayout () {
@@ -115,24 +127,29 @@ private void createGeneralSettingsTab() {
115127 }
116128
117129 private void createVisualSettingsTab () {
118- final JComboBox < String > localeBox = new JComboBox <>();
119- localeBox .addItem ("nl-NL" );
120- localeBox .addItem ("en-US" );
121- localeBox .setSelectedItem (RupsConfiguration .INSTANCE .getUserLocale ().toLanguageTag ());
122- final JLabel localeLabel = new JLabel ("Locale" );
130+ this . localeBox = new JComboBox <>();
131+ this . localeBox .addItem ("nl-NL" );
132+ this . localeBox .addItem ("en-US" );
133+ this . localeBox .setSelectedItem (RupsConfiguration .INSTANCE .getUserLocale ().toLanguageTag ());
134+ final JLabel localeLabel = new JLabel (Language . LOCALE . getString () );
123135 localeLabel .setLabelFor (localeBox );
124136
125- localeBox .addActionListener (e -> {
137+ this .restartLabel = new JLabel (Language .PREFERENCES_NEED_RESTART .getString ());
138+ this .restartLabel .setVisible (false );
139+
140+ this .localeBox .addActionListener (e -> {
126141 Object selectedItem = localeBox .getSelectedItem ();
127142 String selectedString = (String ) selectedItem ;
128143 RupsConfiguration .INSTANCE .setUserLocale (Locale .forLanguageTag (selectedString ));
144+ this .restartLabel .setVisible (true );
129145 });
130146
131147 this .visualPanel = new JPanel ();
132148 this .visualPanel .setLayout (this .gridBagLayout );
133149
134150 this .visualPanel .add (localeLabel , this .left );
135- this .visualPanel .add (localeBox , this .right );
151+ this .visualPanel .add (this .localeBox , this .right );
152+ this .visualPanel .add (this .restartLabel , this .right );
136153 }
137154
138155 private void createTabbedPane () {
@@ -150,6 +167,7 @@ private void createSaveCancelResetSection() {
150167 JButton save = new JButton (Language .SAVE .getString ());
151168 save .addActionListener (e -> {
152169 RupsConfiguration .INSTANCE .saveConfiguration ();
170+ resetView ();
153171 this .jDialog .dispose ();
154172 });
155173 buttons .add (save );
@@ -176,7 +194,6 @@ private void createSaveCancelResetSection() {
176194 Language .PREFERENCES_RESET_TO_DEFAULTS_CONFIRM .getString ());
177195 if (choice == JOptionPane .OK_OPTION ) {
178196 RupsConfiguration .INSTANCE .resetToDefaultProperties ();
179-
180197 resetView ();
181198 }
182199 });
@@ -193,6 +210,8 @@ private void completeJDialogCreation() {
193210 private void resetView () {
194211 this .pathField .setText (RupsConfiguration .INSTANCE .getHomeFolder ().getPath ());
195212 this .openDuplicateFiles .setSelected (RupsConfiguration .INSTANCE .canOpenDuplicateFiles ());
213+ this .localeBox .setSelectedItem (RupsConfiguration .INSTANCE .getUserLocale ().toLanguageTag ());
214+ this .restartLabel .setVisible (false );
196215 }
197216
198217 public void show (Component component ) {
0 commit comments