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