1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.xmlhammer.gui.preferences;
24
25 import java.awt.event.ItemEvent;
26 import java.awt.event.ItemListener;
27
28 import javax.swing.Box;
29 import javax.swing.JCheckBox;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33
34 import org.bounce.FormLayout;
35 import org.xmlhammer.model.preferences.Proxy;
36
37 /***
38 * Put comment...
39 *
40 * @version $Revision$, $Date$
41 * @author Edwin Dankert <edankert@gmail.com>
42 */
43
44 public class ProxyPreferencesPanel extends PreferencesPanel {
45 private static final long serialVersionUID = -4140066420809363167L;
46
47 private JLabel proxyAddressLabel = null;
48 private JLabel proxyPortLabel = null;
49 private JTextField proxyAddressField = null;
50 private JTextField proxyPortField = null;
51 private JCheckBox proxyEnabled = null;
52
53 /***
54 * @param name
55 */
56 public ProxyPreferencesPanel() {
57 super("HTTP Proxy", "preferences.proxy");
58 JPanel preferences = new JPanel( new FormLayout( 5, 2));
59
60 proxyEnabled = new JCheckBox("Enable HTTP Proxy Settings");
61 proxyEnabled.addItemListener(new ItemListener() {
62 public void itemStateChanged(ItemEvent event) {
63 update();
64 }
65 });
66
67 preferences.add(proxyEnabled, FormLayout.FULL);
68
69 preferences.add(Box.createVerticalStrut(10), FormLayout.FULL);
70
71 proxyAddressField = new JTextField();
72
73 proxyAddressLabel = new JLabel("Proxy Address:");
74 preferences.add(proxyAddressLabel, FormLayout.LEFT);
75 preferences.add(proxyAddressField, FormLayout.RIGHT_FILL);
76
77 proxyPortField = new JTextField();
78
79 proxyPortLabel = new JLabel( "Proxy Port:");
80 preferences.add(proxyPortLabel, FormLayout.LEFT);
81 preferences.add(proxyPortField, FormLayout.RIGHT_FILL);
82
83 setCenterPane(preferences);
84 }
85
86 public void setProxy(Proxy proxy) {
87 proxyAddressField.setText(proxy.getAddress() == null ? "" : proxy.getAddress());
88 proxyPortField.setText(proxy.getPort() == null ? "" : proxy.getPort());
89 proxyEnabled.setSelected(proxy.isEnabled());
90 update();
91 }
92
93 public Proxy getProxy() {
94 Proxy proxy = new Proxy();
95 proxy.setAddress(proxyAddressField.getText());
96 proxy.setPort(proxyPortField.getText());
97 proxy.setEnabled(proxyEnabled.isSelected());
98
99 return proxy;
100 }
101
102 public void update() {
103 proxyPortLabel.setEnabled(proxyEnabled.isSelected());
104 proxyPortField.setEnabled(proxyEnabled.isSelected());
105 proxyAddressField.setEnabled(proxyEnabled.isSelected());
106 proxyAddressLabel.setEnabled(proxyEnabled.isSelected());
107 }
108 }