[591] | 1 | package net.oni2.aeinstaller.gui.settings;
|
---|
| 2 |
|
---|
| 3 | import java.awt.event.ActionEvent;
|
---|
| 4 | import java.awt.event.KeyEvent;
|
---|
| 5 | import java.util.ResourceBundle;
|
---|
| 6 |
|
---|
| 7 | import javax.swing.AbstractAction;
|
---|
[608] | 8 | import javax.swing.JCheckBox;
|
---|
[591] | 9 | import javax.swing.JComboBox;
|
---|
| 10 | import javax.swing.JComponent;
|
---|
[593] | 11 | import javax.swing.JDialog;
|
---|
[591] | 12 | import javax.swing.JOptionPane;
|
---|
| 13 | import javax.swing.KeyStroke;
|
---|
| 14 | import javax.swing.UIManager;
|
---|
| 15 |
|
---|
[720] | 16 | import net.oni2.SettingsManager;
|
---|
[840] | 17 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
---|
[591] | 18 |
|
---|
| 19 | import org.javabuilders.BuildResult;
|
---|
| 20 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * @author Christian Illy
|
---|
| 24 | */
|
---|
[593] | 25 | public class SettingsDialog extends JDialog {
|
---|
[591] | 26 | private static final long serialVersionUID = -5719515325671846620L;
|
---|
| 27 |
|
---|
[840] | 28 | private ResourceBundle bundle = UTF8ResourceBundleLoader
|
---|
[629] | 29 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 30 | + getClass().getSimpleName());
|
---|
[591] | 31 | @SuppressWarnings("unused")
|
---|
| 32 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 33 |
|
---|
| 34 | private JComboBox cmbLaF;
|
---|
| 35 | private LaFComboModel laFModel;
|
---|
| 36 |
|
---|
[608] | 37 | private JCheckBox chkNotifyOnStart;
|
---|
[646] | 38 | private JCheckBox chkNotifyDepsAfterInstall;
|
---|
[625] | 39 | private JCheckBox chkCopyIntro;
|
---|
| 40 | private JCheckBox chkCopyOutro;
|
---|
[608] | 41 |
|
---|
[591] | 42 | /**
|
---|
[593] | 43 | * Open the settings
|
---|
[591] | 44 | */
|
---|
[593] | 45 | public SettingsDialog() {
|
---|
[609] | 46 | setResizable(false);
|
---|
[591] | 47 |
|
---|
| 48 | AbstractAction closeAction = new AbstractAction() {
|
---|
| 49 |
|
---|
| 50 | private static final long serialVersionUID = 1L;
|
---|
| 51 |
|
---|
| 52 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 53 | dispose();
|
---|
| 54 | }
|
---|
| 55 | };
|
---|
| 56 | KeyStroke ksCtrlW = KeyStroke
|
---|
| 57 | .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
|
---|
| 58 | getRootPane()
|
---|
| 59 | .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 60 | .put(ksCtrlW, "close");
|
---|
| 61 | getRootPane().getActionMap().put("close", closeAction);
|
---|
| 62 |
|
---|
| 63 | initValues();
|
---|
[641] | 64 |
|
---|
| 65 | setLocationRelativeTo(null);
|
---|
[591] | 66 | }
|
---|
| 67 |
|
---|
| 68 | private void initValues() {
|
---|
[720] | 69 | SettingsManager set = SettingsManager.getInstance();
|
---|
[591] | 70 |
|
---|
| 71 | laFModel = new LaFComboModel();
|
---|
| 72 | cmbLaF.setModel(laFModel);
|
---|
[608] | 73 |
|
---|
| 74 | chkNotifyOnStart.setSelected(set.get("notifyupdates", true));
|
---|
[840] | 75 | chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall",
|
---|
| 76 | false));
|
---|
[625] | 77 | chkCopyIntro.setSelected(set.get("copyintro", false));
|
---|
| 78 | chkCopyOutro.setSelected(set.get("copyoutro", true));
|
---|
[591] | 79 | }
|
---|
| 80 |
|
---|
| 81 | @SuppressWarnings("unused")
|
---|
| 82 | private boolean save() {
|
---|
[720] | 83 | SettingsManager set = SettingsManager.getInstance();
|
---|
[591] | 84 |
|
---|
[625] | 85 | set.put("notifyupdates", chkNotifyOnStart.isSelected());
|
---|
[840] | 86 | set.put("notifyDepsAfterInstall",
|
---|
| 87 | chkNotifyDepsAfterInstall.isSelected());
|
---|
[625] | 88 | set.put("copyintro", chkCopyIntro.isSelected());
|
---|
| 89 | set.put("copyoutro", chkCopyOutro.isSelected());
|
---|
[608] | 90 |
|
---|
| 91 | String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel()
|
---|
| 92 | .getClass().getName());
|
---|
[591] | 93 | String newLaf = laFModel.getSelectedClassName();
|
---|
| 94 |
|
---|
| 95 | if (!newLaf.equals(oldLaf)) {
|
---|
| 96 | set.put("lookandfeel", newLaf);
|
---|
| 97 | JOptionPane.showMessageDialog(this,
|
---|
| 98 | bundle.getString("newLaF.text"),
|
---|
| 99 | bundle.getString("newLaF.title"),
|
---|
| 100 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | return true;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | }
|
---|