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;
|
---|
8 | import javax.swing.JCheckBox;
|
---|
9 | import javax.swing.JComboBox;
|
---|
10 | import javax.swing.JComponent;
|
---|
11 | import javax.swing.JDialog;
|
---|
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 | */
|
---|
24 | public class SettingsDialog extends JDialog {
|
---|
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 |
|
---|
35 | private JCheckBox chkNotifyOnStart;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Open the settings
|
---|
39 | */
|
---|
40 | public SettingsDialog() {
|
---|
41 | setResizable(false);
|
---|
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 | }
|
---|