[591] | 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;
|
---|
[608] | 8 | import javax.swing.JCheckBox;
|
---|
[591] | 9 | import javax.swing.JComboBox;
|
---|
| 10 | import javax.swing.JComponent;
|
---|
[593] | 11 | import javax.swing.JDialog;
|
---|
[591] | 12 | import javax.swing.JOptionPane;
|
---|
[856] | 13 | import javax.swing.JTextField;
|
---|
[591] | 14 | import javax.swing.KeyStroke;
|
---|
| 15 | import javax.swing.UIManager;
|
---|
| 16 |
|
---|
[852] | 17 | import net.oni2.ProxySettings;
|
---|
[720] | 18 | import net.oni2.SettingsManager;
|
---|
[852] | 19 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[840] | 20 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
---|
[591] | 21 |
|
---|
| 22 | import org.javabuilders.BuildResult;
|
---|
| 23 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * @author Christian Illy
|
---|
| 27 | */
|
---|
[593] | 28 | public 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;
|
---|
[625] | 43 | private JCheckBox chkCopyIntro;
|
---|
| 44 | private JCheckBox chkCopyOutro;
|
---|
[608] | 45 |
|
---|
[856] | 46 | private JCheckBox chkUseProxy;
|
---|
| 47 | private JTextField txtProxyHost;
|
---|
| 48 | private JTextField txtProxyPort;
|
---|
| 49 |
|
---|
[591] | 50 | /**
|
---|
[593] | 51 | * Open the settings
|
---|
[591] | 52 | */
|
---|
[593] | 53 | public SettingsDialog() {
|
---|
[609] | 54 | setResizable(false);
|
---|
[591] | 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();
|
---|
[641] | 72 |
|
---|
| 73 | setLocationRelativeTo(null);
|
---|
[591] | 74 | }
|
---|
| 75 |
|
---|
| 76 | private void initValues() {
|
---|
[720] | 77 | SettingsManager set = SettingsManager.getInstance();
|
---|
[856] | 78 | ProxySettings prox = ProxySettings.getInstance();
|
---|
[591] | 79 |
|
---|
| 80 | laFModel = new LaFComboModel();
|
---|
| 81 | cmbLaF.setModel(laFModel);
|
---|
[608] | 82 |
|
---|
| 83 | chkNotifyOnStart.setSelected(set.get("notifyupdates", true));
|
---|
[860] | 84 | chkNotifyNewPackagesOnStart.setSelected(set.get("notifynewpackages",
|
---|
| 85 | true));
|
---|
[840] | 86 | chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall",
|
---|
| 87 | false));
|
---|
[625] | 88 | chkCopyIntro.setSelected(set.get("copyintro", false));
|
---|
| 89 | chkCopyOutro.setSelected(set.get("copyoutro", true));
|
---|
[856] | 90 |
|
---|
| 91 | chkUseProxy.setSelected(prox.isUseProxy());
|
---|
| 92 | txtProxyHost.setText(prox.getHostOrIp());
|
---|
| 93 | txtProxyPort.setText(String.valueOf(prox.getPort()));
|
---|
[591] | 94 | }
|
---|
| 95 |
|
---|
| 96 | @SuppressWarnings("unused")
|
---|
| 97 | private boolean save() {
|
---|
[856] | 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 |
|
---|
[720] | 139 | SettingsManager set = SettingsManager.getInstance();
|
---|
[591] | 140 |
|
---|
[625] | 141 | set.put("notifyupdates", chkNotifyOnStart.isSelected());
|
---|
[860] | 142 | set.put("notifynewpackages", chkNotifyNewPackagesOnStart.isSelected());
|
---|
[840] | 143 | set.put("notifyDepsAfterInstall",
|
---|
| 144 | chkNotifyDepsAfterInstall.isSelected());
|
---|
[625] | 145 | set.put("copyintro", chkCopyIntro.isSelected());
|
---|
| 146 | set.put("copyoutro", chkCopyOutro.isSelected());
|
---|
[608] | 147 |
|
---|
| 148 | String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel()
|
---|
| 149 | .getClass().getName());
|
---|
[591] | 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 | }
|
---|