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

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

AEI2.14:

File size: 5.0 KB
RevLine 
[591]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;
[608]8import javax.swing.JCheckBox;
[591]9import javax.swing.JComboBox;
10import javax.swing.JComponent;
[593]11import javax.swing.JDialog;
[591]12import javax.swing.JOptionPane;
[856]13import javax.swing.JTextField;
[591]14import javax.swing.KeyStroke;
15import javax.swing.UIManager;
16
[852]17import net.oni2.ProxySettings;
[720]18import net.oni2.SettingsManager;
[852]19import net.oni2.aeinstaller.backend.Paths;
[840]20import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
[591]21
22import org.javabuilders.BuildResult;
23import org.javabuilders.swing.SwingJavaBuilder;
24
25/**
26 * @author Christian Illy
27 */
[593]28public class SettingsDialog extends JDialog {
[591]29 private static final long serialVersionUID = -5719515325671846620L;
30
[840]31 private ResourceBundle bundle = UTF8ResourceBundleLoader
[629]32 .getBundle("net.oni2.aeinstaller.localization."
33 + getClass().getSimpleName());
[591]34 @SuppressWarnings("unused")
35 private BuildResult result = SwingJavaBuilder.build(this, bundle);
36
37 private JComboBox cmbLaF;
38 private LaFComboModel laFModel;
39
[608]40 private JCheckBox chkNotifyOnStart;
[860]41 private JCheckBox chkNotifyNewPackagesOnStart;
[646]42 private JCheckBox chkNotifyDepsAfterInstall;
[873]43 private JCheckBox chkShowTipsAtStart;
[625]44 private JCheckBox chkCopyIntro;
45 private JCheckBox chkCopyOutro;
[608]46
[856]47 private JCheckBox chkUseProxy;
48 private JTextField txtProxyHost;
49 private JTextField txtProxyPort;
50
[591]51 /**
[593]52 * Open the settings
[591]53 */
[593]54 public SettingsDialog() {
[609]55 setResizable(false);
[591]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();
[641]73
74 setLocationRelativeTo(null);
[591]75 }
76
77 private void initValues() {
[720]78 SettingsManager set = SettingsManager.getInstance();
[856]79 ProxySettings prox = ProxySettings.getInstance();
[591]80
81 laFModel = new LaFComboModel();
82 cmbLaF.setModel(laFModel);
[608]83
84 chkNotifyOnStart.setSelected(set.get("notifyupdates", true));
[860]85 chkNotifyNewPackagesOnStart.setSelected(set.get("notifynewpackages",
86 true));
[840]87 chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall",
88 false));
[873]89 chkShowTipsAtStart.setSelected(set.get("showTips", true));
[625]90 chkCopyIntro.setSelected(set.get("copyintro", false));
91 chkCopyOutro.setSelected(set.get("copyoutro", true));
[856]92
93 chkUseProxy.setSelected(prox.isUseProxy());
94 txtProxyHost.setText(prox.getHostOrIp());
95 txtProxyPort.setText(String.valueOf(prox.getPort()));
[591]96 }
97
98 @SuppressWarnings("unused")
99 private boolean save() {
[872]100 ProxySettings prox = ProxySettings.getInstance();
[856]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);
[872]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 }
[856]138 }
139
140 prox.serializeToFile(Paths.getProxySettingsFilename());
141 }
142
[720]143 SettingsManager set = SettingsManager.getInstance();
[591]144
[625]145 set.put("notifyupdates", chkNotifyOnStart.isSelected());
[860]146 set.put("notifynewpackages", chkNotifyNewPackagesOnStart.isSelected());
[840]147 set.put("notifyDepsAfterInstall",
148 chkNotifyDepsAfterInstall.isSelected());
[873]149 set.put("showTips", chkShowTipsAtStart.isSelected());
[625]150 set.put("copyintro", chkCopyIntro.isSelected());
151 set.put("copyoutro", chkCopyOutro.isSelected());
[608]152
153 String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel()
154 .getClass().getName());
[591]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.