source: java/installer2/src/net/oni2/aeinstaller/gui/settings/SettingsDialog.java@ 1085

Last change on this file since 1085 was 873, checked in by alloc, 12 years ago

AEI2.14:

File size: 5.0 KB
Line 
1package net.oni2.aeinstaller.gui.settings;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.KeyEvent;
5import java.util.ResourceBundle;
6
7import javax.swing.AbstractAction;
8import javax.swing.JCheckBox;
9import javax.swing.JComboBox;
10import javax.swing.JComponent;
11import javax.swing.JDialog;
12import javax.swing.JOptionPane;
13import javax.swing.JTextField;
14import javax.swing.KeyStroke;
15import javax.swing.UIManager;
16
17import net.oni2.ProxySettings;
18import net.oni2.SettingsManager;
19import net.oni2.aeinstaller.backend.Paths;
20import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
21
22import org.javabuilders.BuildResult;
23import org.javabuilders.swing.SwingJavaBuilder;
24
25/**
26 * @author Christian Illy
27 */
28public class SettingsDialog extends JDialog {
29 private static final long serialVersionUID = -5719515325671846620L;
30
31 private ResourceBundle bundle = UTF8ResourceBundleLoader
32 .getBundle("net.oni2.aeinstaller.localization."
33 + getClass().getSimpleName());
34 @SuppressWarnings("unused")
35 private BuildResult result = SwingJavaBuilder.build(this, bundle);
36
37 private JComboBox cmbLaF;
38 private LaFComboModel laFModel;
39
40 private JCheckBox chkNotifyOnStart;
41 private JCheckBox chkNotifyNewPackagesOnStart;
42 private JCheckBox chkNotifyDepsAfterInstall;
43 private JCheckBox chkShowTipsAtStart;
44 private JCheckBox chkCopyIntro;
45 private JCheckBox chkCopyOutro;
46
47 private JCheckBox chkUseProxy;
48 private JTextField txtProxyHost;
49 private JTextField txtProxyPort;
50
51 /**
52 * Open the settings
53 */
54 public SettingsDialog() {
55 setResizable(false);
56
57 AbstractAction closeAction = new AbstractAction() {
58
59 private static final long serialVersionUID = 1L;
60
61 public void actionPerformed(ActionEvent arg0) {
62 dispose();
63 }
64 };
65 KeyStroke ksCtrlW = KeyStroke
66 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
67 getRootPane()
68 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
69 .put(ksCtrlW, "close");
70 getRootPane().getActionMap().put("close", closeAction);
71
72 initValues();
73
74 setLocationRelativeTo(null);
75 }
76
77 private void initValues() {
78 SettingsManager set = SettingsManager.getInstance();
79 ProxySettings prox = ProxySettings.getInstance();
80
81 laFModel = new LaFComboModel();
82 cmbLaF.setModel(laFModel);
83
84 chkNotifyOnStart.setSelected(set.get("notifyupdates", true));
85 chkNotifyNewPackagesOnStart.setSelected(set.get("notifynewpackages",
86 true));
87 chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall",
88 false));
89 chkShowTipsAtStart.setSelected(set.get("showTips", true));
90 chkCopyIntro.setSelected(set.get("copyintro", false));
91 chkCopyOutro.setSelected(set.get("copyoutro", true));
92
93 chkUseProxy.setSelected(prox.isUseProxy());
94 txtProxyHost.setText(prox.getHostOrIp());
95 txtProxyPort.setText(String.valueOf(prox.getPort()));
96 }
97
98 @SuppressWarnings("unused")
99 private boolean save() {
100 ProxySettings prox = ProxySettings.getInstance();
101
102 boolean proxyUse = chkUseProxy.isSelected();
103 int proxyPort = -1;
104 try {
105 proxyPort = Integer.valueOf(txtProxyPort.getText());
106 } catch (NumberFormatException e) {
107 }
108 if ((proxyPort < 1) || (proxyPort > 65535)) {
109 JOptionPane.showMessageDialog(this,
110 bundle.getString("proxyIllegalPort.text"),
111 bundle.getString("proxyIllegalPort.title"),
112 JOptionPane.ERROR_MESSAGE);
113 return false;
114 }
115 String proxyHost = txtProxyHost.getText();
116
117 if (!prox.getHostOrIp().equalsIgnoreCase(proxyHost)
118 || (prox.getPort() != proxyPort)
119 || (prox.isUseProxy() != proxyUse)) {
120 boolean proxyOldUse = prox.isUseProxy();
121 int proxyOldPort = prox.getPort();
122 String proxyOldHost = prox.getHostOrIp();
123
124 prox.setUseProxy(proxyUse);
125 prox.setHostOrIp(proxyHost);
126 prox.setPort(proxyPort);
127 if (proxyUse) {
128 if (!prox.validate()) {
129 JOptionPane.showMessageDialog(this,
130 bundle.getString("proxyVerifyFailed.text"),
131 bundle.getString("proxyVerifyFailed.title"),
132 JOptionPane.ERROR_MESSAGE);
133 prox.setUseProxy(proxyOldUse);
134 prox.setHostOrIp(proxyOldHost);
135 prox.setPort(proxyOldPort);
136 return false;
137 }
138 }
139
140 prox.serializeToFile(Paths.getProxySettingsFilename());
141 }
142
143 SettingsManager set = SettingsManager.getInstance();
144
145 set.put("notifyupdates", chkNotifyOnStart.isSelected());
146 set.put("notifynewpackages", chkNotifyNewPackagesOnStart.isSelected());
147 set.put("notifyDepsAfterInstall",
148 chkNotifyDepsAfterInstall.isSelected());
149 set.put("showTips", chkShowTipsAtStart.isSelected());
150 set.put("copyintro", chkCopyIntro.isSelected());
151 set.put("copyoutro", chkCopyOutro.isSelected());
152
153 String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel()
154 .getClass().getName());
155 String newLaf = laFModel.getSelectedClassName();
156
157 if (!newLaf.equals(oldLaf)) {
158 set.put("lookandfeel", newLaf);
159 JOptionPane.showMessageDialog(this,
160 bundle.getString("newLaF.text"),
161 bundle.getString("newLaF.title"),
162 JOptionPane.INFORMATION_MESSAGE);
163 }
164
165 return true;
166 }
167}
Note: See TracBrowser for help on using the repository browser.