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