add a little bit better support for validating user entered settings
This commit is contained in:
parent
5242d629a5
commit
a477926c99
|
@ -8,10 +8,7 @@ import java.awt.event.WindowListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.*;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTabbedPane;
|
|
||||||
|
|
||||||
import org.fenix.llanfair.Language;
|
import org.fenix.llanfair.Language;
|
||||||
import org.fenix.llanfair.config.Settings;
|
import org.fenix.llanfair.config.Settings;
|
||||||
|
@ -53,6 +50,7 @@ public class EditSettings extends LlanfairDialog
|
||||||
settingsTabs.add(new TabHistory());
|
settingsTabs.add(new TabHistory());
|
||||||
settingsTabs.add(new TabComponents());
|
settingsTabs.add(new TabComponents());
|
||||||
|
|
||||||
|
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||||
createResources();
|
createResources();
|
||||||
placeComponents();
|
placeComponents();
|
||||||
setPersistentBehavior();
|
setPersistentBehavior();
|
||||||
|
@ -121,10 +119,16 @@ public class EditSettings extends LlanfairDialog
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Object source = e.getSource();
|
Object source = e.getSource();
|
||||||
if (source.equals(actionOK)) {
|
if (source.equals(actionOK)) {
|
||||||
for (SettingsTab tab : settingsTabs) {
|
try {
|
||||||
tab.doDelayedSettingChange();
|
for (SettingsTab tab : settingsTabs) {
|
||||||
|
tab.doDelayedSettingChange();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
} catch (InvalidSettingException ex) {
|
||||||
|
ex.tab.requestFocusInWindow();
|
||||||
|
ex.field.requestFocusInWindow();
|
||||||
|
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
dispose();
|
|
||||||
} else if (source.equals(reset)) {
|
} else if (source.equals(reset)) {
|
||||||
int option = JOptionPane.showConfirmDialog(this,
|
int option = JOptionPane.showConfirmDialog(this,
|
||||||
"" + Language.WARN_RESET_SETTINGS);
|
"" + Language.WARN_RESET_SETTINGS);
|
||||||
|
@ -144,10 +148,15 @@ public class EditSettings extends LlanfairDialog
|
||||||
@Override public void windowOpened(WindowEvent e) {}
|
@Override public void windowOpened(WindowEvent e) {}
|
||||||
|
|
||||||
@Override public void windowClosing(WindowEvent e) {
|
@Override public void windowClosing(WindowEvent e) {
|
||||||
for (SettingsTab tab : settingsTabs) {
|
try {
|
||||||
tab.doDelayedSettingChange();
|
for (SettingsTab tab : settingsTabs) {
|
||||||
|
tab.doDelayedSettingChange();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
} catch (InvalidSettingException ex) {
|
||||||
|
ex.tab.grabFocus();
|
||||||
|
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.fenix.llanfair.dialog;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class InvalidSettingException extends Exception {
|
||||||
|
public final SettingsTab tab;
|
||||||
|
public final Component field;
|
||||||
|
|
||||||
|
public InvalidSettingException(SettingsTab tab, Component field, String message) {
|
||||||
|
super(message);
|
||||||
|
this.tab = tab;
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidSettingException(SettingsTab tab, Component field, String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
this.tab = tab;
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ abstract class SettingsTab extends JPanel {
|
||||||
checkBoxes = new HashMap<String, SCheckBox>();
|
checkBoxes = new HashMap<String, SCheckBox>();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void doDelayedSettingChange();
|
abstract void doDelayedSettingChange() throws InvalidSettingException;
|
||||||
|
|
||||||
protected class SCheckBox extends LinkedCheckBox {
|
protected class SCheckBox extends LinkedCheckBox {
|
||||||
|
|
||||||
|
|
Reference in a new issue