- Timestamp:
- 2020-11-15T18:35:28+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r17271 r17312 2 2 package org.openstreetmap.josm.gui.preferences.server; 3 3 4 import static java.awt.GridBagConstraints.HORIZONTAL; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trc; … … 21 22 22 23 import javax.swing.BorderFactory; 24 import javax.swing.Box; 23 25 import javax.swing.ButtonGroup; 24 26 import javax.swing.JLabel; … … 37 39 import org.openstreetmap.josm.io.auth.CredentialsManager; 38 40 import org.openstreetmap.josm.spi.preferences.Config; 41 import org.openstreetmap.josm.spi.preferences.IPreferences; 39 42 import org.openstreetmap.josm.tools.GBC; 40 43 import org.openstreetmap.josm.tools.Logging; … … 78 81 gc.anchor = GridBagConstraints.WEST; 79 82 gc.insets = new Insets(5, 5, 0, 0); 80 gc.fill = GridBagConstraints.HORIZONTAL;83 gc.fill = HORIZONTAL; 81 84 gc.weightx = 0.0; 82 85 pnl.add(new JLabel(tr("Host:")), gc); … … 100 103 gc.gridx = 0; 101 104 gc.gridwidth = 2; 102 gc.fill = GridBagConstraints.HORIZONTAL;105 gc.fill = HORIZONTAL; 103 106 gc.weightx = 1.0; 104 107 pnl.add(new JMultilineLabel(tr("Please enter a username and a password if your proxy requires authentication.")), gc); … … 148 151 gc.anchor = GridBagConstraints.WEST; 149 152 gc.insets = new Insets(5, 5, 0, 0); 150 gc.fill = GridBagConstraints.HORIZONTAL;153 gc.fill = HORIZONTAL; 151 154 gc.weightx = 0.0; 152 155 pnl.add(new JLabel(tr("Host:")), gc); … … 191 194 192 195 // radio button "No proxy" 193 rbProxyPolicy.get(ProxyPolicy.NO_PROXY).setText(tr("No proxy")); 194 pnl.add(rbProxyPolicy.get(ProxyPolicy.NO_PROXY), GBC.eop().anchor(GBC.NORTHWEST)); 196 pnl.add(newRadioButton(ProxyPolicy.NO_PROXY, tr("No proxy")), GBC.eop().anchor(GBC.NORTHWEST)); 195 197 196 198 // radio button "System settings" 197 pnl.add(rbProxyPolicy.get(ProxyPolicy.USE_SYSTEM_SETTINGS), GBC.eol()); 198 rbProxyPolicy.get(ProxyPolicy.USE_SYSTEM_SETTINGS).setText(tr("Use standard system settings")); 199 pnl.add(newRadioButton(ProxyPolicy.USE_SYSTEM_SETTINGS, tr("Use standard system settings")), GBC.eol()); 199 200 if (!DefaultProxySelector.willJvmRetrieveSystemProxies()) { 200 201 String msg = tr("Use standard system settings (disabled. Start JOSM with <tt>-Djava.net.useSystemProxies=true</tt> to enable)"); 201 pnl.add(new JMultilineLabel("<html>" + msg + "</html>"), GBC.eop() );202 pnl.add(new JMultilineLabel("<html>" + msg + "</html>"), GBC.eop().fill(HORIZONTAL)); 202 203 } 203 204 204 205 // radio button http proxy 205 rbProxyPolicy.get(ProxyPolicy.USE_HTTP_PROXY).setText(tr("Manually configure a HTTP proxy")); 206 pnl.add(rbProxyPolicy.get(ProxyPolicy.USE_HTTP_PROXY), GBC.eol()); 206 pnl.add(newRadioButton(ProxyPolicy.USE_HTTP_PROXY, tr("Manually configure a HTTP proxy")), GBC.eol()); 207 207 208 208 // the panel with the http proxy configuration parameters 209 209 pnlHttpProxyConfigurationPanel = buildHttpProxyConfigurationPanel(); 210 pnl.add(pnlHttpProxyConfigurationPanel, GBC.eop().fill( GBC.HORIZONTAL));210 pnl.add(pnlHttpProxyConfigurationPanel, GBC.eop().fill(HORIZONTAL)); 211 211 212 212 // radio button SOCKS proxy 213 pnl.add(rbProxyPolicy.get(ProxyPolicy.USE_SOCKS_PROXY), GBC.eol()); 214 rbProxyPolicy.get(ProxyPolicy.USE_SOCKS_PROXY).setText(tr("Use a SOCKS proxy")); 213 pnl.add(newRadioButton(ProxyPolicy.USE_SOCKS_PROXY, tr("Use a SOCKS proxy")), GBC.eol()); 215 214 216 215 // the panel with the SOCKS configuration parameters 217 216 pnlSocksProxyConfigurationPanel = buildSocksProxyConfigurationPanel(); 218 pnl.add(pnlSocksProxyConfigurationPanel, GBC.eop().fill(GBC.HORIZONTAL)); 217 pnl.add(pnlSocksProxyConfigurationPanel, GBC.eop().fill(HORIZONTAL)); 218 219 pnl.add(Box.createVerticalGlue(), GBC.eol().fill()); 219 220 220 221 return pnl; 221 222 } 222 223 224 private JRadioButton newRadioButton(ProxyPolicy policy, String text) { 225 JRadioButton radioButton = rbProxyPolicy.get(policy); 226 radioButton.setText(text); 227 return radioButton; 228 } 229 223 230 /** 224 231 * Initializes the panel with the values from the preferences 225 232 */ 226 233 public final void initFromPreferences() { 227 ProxyPolicy pp = Optional.ofNullable(ProxyPolicy.fromName(Config.getPref().get(DefaultProxySelector.PROXY_POLICY, null))) 234 IPreferences pref = Config.getPref(); 235 ProxyPolicy pp = Optional.ofNullable(ProxyPolicy.fromName(pref.get(DefaultProxySelector.PROXY_POLICY, null))) 228 236 .orElse(ProxyPolicy.NO_PROXY); 229 237 rbProxyPolicy.get(pp).setSelected(true); 230 tfProxyHttpHost.setText( Config.getPref().get(DefaultProxySelector.PROXY_HTTP_HOST, ""));231 tfProxyHttpPort.setText( Config.getPref().get(DefaultProxySelector.PROXY_HTTP_PORT, ""));232 tfProxySocksHost.setText( Config.getPref().get(DefaultProxySelector.PROXY_SOCKS_HOST, ""));233 tfProxySocksPort.setText( Config.getPref().get(DefaultProxySelector.PROXY_SOCKS_PORT, ""));238 tfProxyHttpHost.setText(pref.get(DefaultProxySelector.PROXY_HTTP_HOST, "")); 239 tfProxyHttpPort.setText(pref.get(DefaultProxySelector.PROXY_HTTP_PORT, "")); 240 tfProxySocksHost.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_HOST, "")); 241 tfProxySocksPort.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_PORT, "")); 234 242 235 243 if (pp == ProxyPolicy.USE_SYSTEM_SETTINGS && !DefaultProxySelector.willJvmRetrieveSystemProxies()) { … … 275 283 class ProxyPolicyChangeListener implements ItemListener { 276 284 @Override 277 public void itemStateChanged(ItemEvent arg0) {285 public void itemStateChanged(ItemEvent e) { 278 286 updateEnabledState(); 279 287 } … … 301 309 .filter(pp -> rbProxyPolicy.get(pp).isSelected()) 302 310 .findFirst().orElse(null); 303 Config.getPref().put(DefaultProxySelector.PROXY_POLICY, Optional.ofNullable(policy).orElse(ProxyPolicy.NO_PROXY).getName()); 304 Config.getPref().put(DefaultProxySelector.PROXY_HTTP_HOST, tfProxyHttpHost.getText()); 305 Config.getPref().put(DefaultProxySelector.PROXY_HTTP_PORT, tfProxyHttpPort.getText()); 306 Config.getPref().put(DefaultProxySelector.PROXY_SOCKS_HOST, tfProxySocksHost.getText()); 307 Config.getPref().put(DefaultProxySelector.PROXY_SOCKS_PORT, tfProxySocksPort.getText()); 311 IPreferences pref = Config.getPref(); 312 pref.put(DefaultProxySelector.PROXY_POLICY, Optional.ofNullable(policy).orElse(ProxyPolicy.NO_PROXY).getName()); 313 pref.put(DefaultProxySelector.PROXY_HTTP_HOST, tfProxyHttpHost.getText()); 314 pref.put(DefaultProxySelector.PROXY_HTTP_PORT, tfProxyHttpPort.getText()); 315 pref.put(DefaultProxySelector.PROXY_SOCKS_HOST, tfProxySocksHost.getText()); 316 pref.put(DefaultProxySelector.PROXY_SOCKS_PORT, tfProxySocksPort.getText()); 308 317 309 318 // update the proxy selector
Note:
See TracChangeset
for help on using the changeset viewer.