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