- Timestamp:
- 2023-02-15T16:39:22+01:00 (22 months ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r18389 r18663 20 20 import java.util.Map; 21 21 import java.util.Optional; 22 import java.util.ArrayList; 22 23 23 24 import javax.swing.BorderFactory; … … 32 33 import org.openstreetmap.josm.gui.widgets.JosmTextField; 33 34 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 35 import org.openstreetmap.josm.gui.widgets.EditableList; 34 36 import org.openstreetmap.josm.io.DefaultProxySelector; 35 37 import org.openstreetmap.josm.io.ProxyPolicy; … … 47 49 public class ProxyPreferencesPanel extends VerticallyScrollablePanel { 48 50 51 private static final long serialVersionUID = -2479852374189976764L; 52 49 53 static final class AutoSizePanel extends JPanel { 54 private static final long serialVersionUID = 7469560761925020366L; 55 50 56 AutoSizePanel() { 51 57 super(new GridBagLayout()); … … 65 71 private final JosmTextField tfProxyHttpUser = new JosmTextField(20); 66 72 private final JosmPasswordField tfProxyHttpPassword = new JosmPasswordField(20); 73 private final EditableList tfExceptionHosts = new EditableList(tr("No proxy for")); 74 private final EditableList tfIncludeHosts = new EditableList(tr("Proxy only for")); 67 75 68 76 private JPanel pnlHttpProxyConfigurationPanel; 69 77 private JPanel pnlSocksProxyConfigurationPanel; 78 private JPanel pnlIncludeOrExcludeHostsPanel; 70 79 71 80 /** … … 168 177 pnl.add(tfProxySocksPort, gc); 169 178 tfProxySocksPort.setMinimumSize(tfProxySocksPort.getPreferredSize()); 179 180 // add an extra spacer, otherwise the layout is broken 181 gc.gridy = 2; 182 gc.gridx = 0; 183 gc.gridwidth = 2; 184 gc.fill = GridBagConstraints.BOTH; 185 gc.weightx = 1.0; 186 gc.weighty = 1.0; 187 pnl.add(new JPanel(), gc); 188 return pnl; 189 } 190 191 protected final JPanel buildExceptionIncludesHostsProxyConfigurationPanel() { 192 JPanel pnl = new AutoSizePanel(); 193 GridBagConstraints gc = new GridBagConstraints(); 194 gc.anchor = GridBagConstraints.LINE_START; 195 gc.insets = new Insets(5, 5, 0, 0); 196 gc.weightx = 0.0; 197 pnl.add(new JLabel(tr("No proxy for (hosts):")), gc); 198 199 gc.gridx = 1; 200 gc.weightx = 0.0; 201 gc.fill = GridBagConstraints.NONE; 202 pnl.add(new JLabel(tr("Proxy only for (hosts):")), gc); 203 204 gc.gridy = 1; 205 gc.gridx = 0; 206 gc.weightx = 1.0; 207 gc.fill = HORIZONTAL; 208 tfExceptionHosts.setMinimumSize(tfExceptionHosts.getPreferredSize()); 209 pnl.add(tfExceptionHosts, gc); 210 211 gc.gridx = 1; 212 gc.weightx = 1.0; 213 gc.fill = HORIZONTAL; 214 tfIncludeHosts.setMinimumSize(tfIncludeHosts.getPreferredSize()); 215 pnl.add(tfIncludeHosts, gc); 170 216 171 217 // add an extra spacer, otherwise the layout is broken … … 215 261 pnlSocksProxyConfigurationPanel = buildSocksProxyConfigurationPanel(); 216 262 pnl.add(pnlSocksProxyConfigurationPanel, GBC.eop().fill(HORIZONTAL)); 263 264 pnl.add(Box.createVerticalGlue(), GBC.eol().fill()); 265 266 // the panel with the exception and includes hosts 267 pnlIncludeOrExcludeHostsPanel = buildExceptionIncludesHostsProxyConfigurationPanel(); 268 pnl.add(pnlIncludeOrExcludeHostsPanel, GBC.eop().fill(HORIZONTAL)); 217 269 218 270 pnl.add(Box.createVerticalGlue(), GBC.eol().fill()); … … 239 291 tfProxySocksHost.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_HOST, "")); 240 292 tfProxySocksPort.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_PORT, "")); 293 tfExceptionHosts.setItems(pref.getList(DefaultProxySelector.PROXY_EXCEPTIONS, new ArrayList<>())); 294 tfIncludeHosts.setItems(pref.getList(DefaultProxySelector.PROXY_INCLUDES, new ArrayList<>())); 241 295 242 296 if (pp == ProxyPolicy.USE_SYSTEM_SETTINGS && !DefaultProxySelector.willJvmRetrieveSystemProxies()) { … … 278 332 279 333 rbProxyPolicy.get(ProxyPolicy.USE_SYSTEM_SETTINGS).setEnabled(DefaultProxySelector.willJvmRetrieveSystemProxies()); 334 335 boolean proxyEnabled = !rbProxyPolicy.get(ProxyPolicy.NO_PROXY).isSelected(); 336 for (Component c : pnlIncludeOrExcludeHostsPanel.getComponents()) { 337 c.setEnabled(proxyEnabled); 338 } 280 339 } 281 340 … … 312 371 pref.put(DefaultProxySelector.PROXY_SOCKS_HOST, tfProxySocksHost.getText()); 313 372 pref.put(DefaultProxySelector.PROXY_SOCKS_PORT, tfProxySocksPort.getText()); 373 pref.putList(DefaultProxySelector.PROXY_EXCEPTIONS, tfExceptionHosts.getItems()); 374 pref.putList(DefaultProxySelector.PROXY_INCLUDES, tfIncludeHosts.getItems()); 375 314 376 315 377 // update the proxy selector -
trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java
r18211 r18663 44 44 /** Property key for proxy exceptions list */ 45 45 public static final String PROXY_EXCEPTIONS = "proxy.exceptions"; 46 /** 47 * Property key for hosts that should be proxied (if this is set, only specified hosts should be proxied) 48 * @since 18663 49 */ 50 public static final String PROXY_INCLUDES = "proxy.includes.hosts"; 46 51 47 52 private static final List<Proxy> NO_PROXY_LIST = Collections.singletonList(Proxy.NO_PROXY); … … 87 92 private final Set<String> errorMessages = new HashSet<>(); 88 93 private Set<String> proxyExceptions; 94 private Set<String> proxyIncludes; 89 95 90 96 /** … … 165 171 Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK)) 166 172 ); 173 proxyIncludes = new HashSet<>( 174 Config.getPref().getList(PROXY_INCLUDES, 175 Collections.emptyList()) 176 ); 167 177 } 168 178 … … 215 225 @Override 216 226 public List<Proxy> select(URI uri) { 217 if (uri != null && proxyExceptions.contains(uri.getHost())) { 227 // This is specified in ProxySelector#select, "@throws IllegalArgumentException if the argument is null" 228 if (uri == null) { 229 throw new IllegalArgumentException("URI cannot be null"); 230 } 231 if (proxyExceptions.contains(uri.getHost())) { 218 232 return NO_PROXY_LIST; 219 233 } 220 switch(proxyPolicy) { 234 if (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost())) { 235 return NO_PROXY_LIST; 236 } 237 switch (proxyPolicy) { 221 238 case USE_SYSTEM_SETTINGS: 222 239 if (!jvmWillUseSystemProxies) { 223 Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. " +240 Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. " + 224 241 "The property ''java.net.useSystemProxies'' was missing at startup time. Will not use a proxy.")); 225 242 return NO_PROXY_LIST; … … 239 256 } 240 257 // should not happen 241 return null;258 return Collections.emptyList(); 242 259 } 243 260 }
Note:
See TracChangeset
for help on using the changeset viewer.