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

Last change on this file since 863 was 860, checked in by alloc, 12 years ago

AEI2.11:

File size: 4.8 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 chkCopyIntro;
44 private JCheckBox chkCopyOutro;
45
46 private JCheckBox chkUseProxy;
47 private JTextField txtProxyHost;
48 private JTextField txtProxyPort;
49
50 /**
51 * Open the settings
52 */
53 public SettingsDialog() {
54 setResizable(false);
55
56 AbstractAction closeAction = new AbstractAction() {
57
58 private static final long serialVersionUID = 1L;
59
60 public void actionPerformed(ActionEvent arg0) {
61 dispose();
62 }
63 };
64 KeyStroke ksCtrlW = KeyStroke
65 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
66 getRootPane()
67 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
68 .put(ksCtrlW, "close");
69 getRootPane().getActionMap().put("close", closeAction);
70
71 initValues();
72
73 setLocationRelativeTo(null);
74 }
75
76 private void initValues() {
77 SettingsManager set = SettingsManager.getInstance();
78 ProxySettings prox = ProxySettings.getInstance();
79
80 laFModel = new LaFComboModel();
81 cmbLaF.setModel(laFModel);
82
83 chkNotifyOnStart.setSelected(set.get("notifyupdates", true));
84 chkNotifyNewPackagesOnStart.setSelected(set.get("notifynewpackages",
85 true));
86 chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall",
87 false));
88 chkCopyIntro.setSelected(set.get("copyintro", false));
89 chkCopyOutro.setSelected(set.get("copyoutro", true));
90
91 chkUseProxy.setSelected(prox.isUseProxy());
92 txtProxyHost.setText(prox.getHostOrIp());
93 txtProxyPort.setText(String.valueOf(prox.getPort()));
94 }
95
96 @SuppressWarnings("unused")
97 private boolean save() {
98
99 boolean proxyUse = chkUseProxy.isSelected();
100 int proxyPort = -1;
101 try {
102 proxyPort = Integer.valueOf(txtProxyPort.getText());
103 } catch (NumberFormatException e) {
104 }
105 if ((proxyPort < 1) || (proxyPort > 65535)) {
106 JOptionPane.showMessageDialog(this,
107 bundle.getString("proxyIllegalPort.text"),
108 bundle.getString("proxyIllegalPort.title"),
109 JOptionPane.ERROR_MESSAGE);
110 return false;
111 }
112 String proxyHost = txtProxyHost.getText();
113
114 ProxySettings prox = ProxySettings.getInstance();
115 if (!prox.getHostOrIp().equalsIgnoreCase(proxyHost)
116 || (prox.getPort() != proxyPort)
117 || (prox.isUseProxy() != proxyUse)) {
118 boolean proxyOldUse = prox.isUseProxy();
119 int proxyOldPort = prox.getPort();
120 String proxyOldHost = prox.getHostOrIp();
121
122 prox.setUseProxy(proxyUse);
123 prox.setHostOrIp(proxyHost);
124 prox.setPort(proxyPort);
125 if (!prox.validate()) {
126 JOptionPane.showMessageDialog(this,
127 bundle.getString("proxyVerifyFailed.text"),
128 bundle.getString("proxyVerifyFailed.title"),
129 JOptionPane.ERROR_MESSAGE);
130 prox.setUseProxy(proxyOldUse);
131 prox.setHostOrIp(proxyOldHost);
132 prox.setPort(proxyOldPort);
133 return false;
134 }
135
136 prox.serializeToFile(Paths.getProxySettingsFilename());
137 }
138
139 SettingsManager set = SettingsManager.getInstance();
140
141 set.put("notifyupdates", chkNotifyOnStart.isSelected());
142 set.put("notifynewpackages", chkNotifyNewPackagesOnStart.isSelected());
143 set.put("notifyDepsAfterInstall",
144 chkNotifyDepsAfterInstall.isSelected());
145 set.put("copyintro", chkCopyIntro.isSelected());
146 set.put("copyoutro", chkCopyOutro.isSelected());
147
148 String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel()
149 .getClass().getName());
150 String newLaf = laFModel.getSelectedClassName();
151
152 if (!newLaf.equals(oldLaf)) {
153 set.put("lookandfeel", newLaf);
154 JOptionPane.showMessageDialog(this,
155 bundle.getString("newLaF.text"),
156 bundle.getString("newLaF.title"),
157 JOptionPane.INFORMATION_MESSAGE);
158 }
159
160 return true;
161 }
162}
Note: See TracBrowser for help on using the repository browser.