source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/ProxyPreferences.java@ 1742

Last change on this file since 1742 was 1742, checked in by stoecker, 15 years ago

fixed #2849 - patch by jttt - fix memory leak

File size: 4.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8
9import javax.swing.Box;
10import javax.swing.JCheckBox;
11import javax.swing.JLabel;
12import javax.swing.JPasswordField;
13import javax.swing.JSeparator;
14import javax.swing.JTextField;
15import javax.swing.SwingConstants;
16
17import org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.tools.GBC;
19
20public class ProxyPreferences implements PreferenceSetting {
21
22 public static class Factory implements PreferenceSettingFactory {
23 public PreferenceSetting createPreferenceSetting() {
24 return new ProxyPreferences();
25 }
26 }
27
28 public static final String PROXY_ENABLE = "proxy.enable";
29 public static final String PROXY_HOST = "proxy.host";
30 public static final String PROXY_PORT = "proxy.port";
31 public static final String PROXY_ANONYMOUS = "proxy.anonymous";
32 public static final String PROXY_USER = "proxy.user";
33 public static final String PROXY_PASS = "proxy.pass";
34
35 private JCheckBox proxyEnable = new JCheckBox(tr("Enable proxy server"));
36 private JTextField proxyHost = new JTextField(20);
37 private JTextField proxyPort = new JTextField(5);
38 private JCheckBox proxyAnonymous = new JCheckBox(tr("Anonymous"));
39 private JTextField proxyUser = new JTextField(20);
40 private JPasswordField proxyPass = new JPasswordField(20);
41
42 public void addGui(PreferenceDialog gui) {
43 proxyEnable.setSelected(Main.pref.getBoolean(PROXY_ENABLE));
44 proxyEnable.addActionListener(new ActionListener(){
45 public void actionPerformed(ActionEvent e) {
46 proxyHost.setEnabled(proxyEnable.isSelected());
47 proxyPort.setEnabled(proxyEnable.isSelected());
48 proxyAnonymous.setEnabled(proxyEnable.isSelected());
49 proxyUser.setEnabled(proxyEnable.isSelected() && !proxyAnonymous.isSelected());
50 proxyPass.setEnabled(proxyEnable.isSelected() && !proxyAnonymous.isSelected());
51 }
52 });
53 proxyHost.setEnabled(Main.pref.getBoolean(PROXY_ENABLE));
54 proxyHost.setText(Main.pref.get(PROXY_HOST));
55 proxyPort.setEnabled(Main.pref.getBoolean(PROXY_ENABLE));
56 proxyPort.setText(Main.pref.get(PROXY_PORT));
57 proxyAnonymous.setEnabled(Main.pref.getBoolean(PROXY_ENABLE));
58 proxyAnonymous.setSelected(Main.pref.getBoolean(PROXY_ANONYMOUS));
59 proxyAnonymous.addActionListener(new ActionListener(){
60 public void actionPerformed(ActionEvent e) {
61 proxyUser.setEnabled(proxyEnable.isSelected() && !proxyAnonymous.isSelected());
62 proxyPass.setEnabled(proxyEnable.isSelected() && !proxyAnonymous.isSelected());
63 }
64 });
65 proxyUser.setEnabled(Main.pref.getBoolean(PROXY_ENABLE) && (Main.pref.getBoolean(PROXY_ANONYMOUS)));
66 proxyUser.setText(Main.pref.get(PROXY_USER));
67 proxyPass.setEnabled(Main.pref.getBoolean(PROXY_ENABLE) && (Main.pref.getBoolean(PROXY_ANONYMOUS)));
68 proxyPass.setText(Main.pref.get(PROXY_USER));
69
70 gui.connection.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
71 gui.connection.add(new JLabel(tr("Proxy Settings")), GBC.eol());
72 gui.connection.add(proxyEnable, GBC.eol().insets(20, 0, 0, 0));
73 gui.connection.add(new JLabel(tr("Proxy server host")), GBC.std());
74 gui.connection.add(proxyHost, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
75 gui.connection.add(new JLabel(tr("Proxy server port")), GBC.std());
76 gui.connection.add(proxyPort, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
77 gui.connection.add(proxyAnonymous, GBC.eop().insets(20, 0, 0, 0));
78 gui.connection.add(new JLabel(tr("Proxy server username")), GBC.std());
79 gui.connection.add(proxyUser, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
80 gui.connection.add(new JLabel(tr("Proxy server password")), GBC.std());
81 gui.connection.add(proxyPass, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
82
83 gui.connection.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
84 }
85
86 public boolean ok() {
87 Main.pref.put(PROXY_ENABLE, proxyEnable.isSelected());
88 Main.pref.put(PROXY_HOST, proxyHost.getText());
89 Main.pref.put(PROXY_PORT, proxyPort.getText());
90 Main.pref.put(PROXY_ANONYMOUS, proxyAnonymous.isSelected());
91 Main.pref.put(PROXY_USER, proxyUser.getText());
92 Main.pref.put(PROXY_PASS, new String(proxyPass.getPassword()));
93 return false;
94 }
95}
Note: See TracBrowser for help on using the repository browser.