1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sf.magicproject.ui.component;
23
24 import java.awt.BorderLayout;
25 import java.awt.Dimension;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JCheckBox;
32 import javax.swing.JDialog;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JPasswordField;
36 import javax.swing.JTextField;
37 import javax.swing.SwingConstants;
38 import javax.swing.WindowConstants;
39
40 import net.sf.magicproject.tools.Configuration;
41 import net.sf.magicproject.ui.ToolKit;
42 import net.sf.magicproject.ui.i18n.LanguageManager;
43
44 import org.mortbay.util.Password;
45
46 /***
47 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
48 */
49 public class ProxyConfiguration extends JDialog implements ActionListener {
50
51 /***
52 * Create a new instance of JPrompt
53 */
54 public ProxyConfiguration() {
55 setModal(true);
56 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
57 setTitle(LanguageManager.getString("wiz_proxy.title"));
58 getContentPane().add(new JPanel(), BorderLayout.NORTH);
59 getContentPane().add(new JPanel(), BorderLayout.EAST);
60 getContentPane().add(new JPanel(), BorderLayout.WEST);
61
62 JPanel contentPanel = new JPanel();
63 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
64
65
66 contentPanel.add(useProxy);
67
68
69 JPanel proxyAddressPanel = new JPanel();
70 proxyAddressPanel.setLayout(new BoxLayout(proxyAddressPanel,
71 BoxLayout.X_AXIS));
72 proxyAddressPanel.add(new JLabel(LanguageManager
73 .getString("wiz_proxy.address")
74 + " : ", SwingConstants.RIGHT));
75 proxyAddressTxt.setMaximumSize(new Dimension(2100, 20));
76 proxyAddressPanel.add(proxyAddressTxt);
77 contentPanel.add(proxyAddressPanel);
78
79
80 JPanel proxyPortPanel = new JPanel();
81 proxyPortPanel.setLayout(new BoxLayout(proxyPortPanel, BoxLayout.X_AXIS));
82 proxyPortPanel.add(new JLabel(LanguageManager.getString("wiz_proxy.port")
83 + " : ", SwingConstants.RIGHT));
84 proxyPortTxt.setMaximumSize(new Dimension(2100, 20));
85 proxyPortPanel.add(proxyPortTxt);
86 contentPanel.add(proxyPortPanel);
87
88
89 JPanel proxyLoginPanel = new JPanel();
90 proxyLoginPanel.setLayout(new BoxLayout(proxyLoginPanel, BoxLayout.X_AXIS));
91 proxyLoginPanel.add(new JLabel(LanguageManager
92 .getString("wiz_proxy.username")
93 + " : ", SwingConstants.RIGHT));
94 proxyLoginTxt.setMaximumSize(new Dimension(2100, 20));
95 proxyLoginPanel.add(proxyLoginTxt);
96 contentPanel.add(proxyLoginPanel);
97
98
99 JPanel proxyPasswordPanel = new JPanel();
100 proxyPasswordPanel.setLayout(new BoxLayout(proxyPasswordPanel,
101 BoxLayout.X_AXIS));
102 proxyPasswordPanel.add(new JLabel(LanguageManager
103 .getString("wiz_proxy.password")
104 + " : ", SwingConstants.RIGHT));
105 proxyPasswordTxt.setMaximumSize(new Dimension(2100, 20));
106 proxyPasswordPanel.add(proxyPasswordTxt);
107 contentPanel.add(proxyPasswordPanel);
108
109 getContentPane().add(contentPanel, BorderLayout.CENTER);
110
111
112 JPanel buttonPanel = new JPanel();
113 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
114 pressme.setMnemonic('o');
115 pressme.addActionListener(this);
116 pressme.setPreferredSize(new Dimension(50, 20));
117 buttonPanel.add(pressme);
118 cancel.setMnemonic('c');
119 cancel.addActionListener(this);
120 cancel.setPreferredSize(new Dimension(50, 20));
121 ToolKit.addCancelByEscapeKey(this, cancel);
122 buttonPanel.add(cancel);
123 setBounds(100, 100, 350, 200);
124 pressme.requestFocus();
125 getRootPane().setDefaultButton(pressme);
126 getContentPane().add(buttonPanel, BorderLayout.SOUTH);
127
128 }
129
130 public void actionPerformed(ActionEvent event) {
131 Object source = event.getSource();
132 if (source == pressme) {
133
134 Configuration.setProperty("proxyObfuscatedLoginPwd", Password
135 .obfuscate(proxyLoginTxt.getText() + ':'
136 + new String(proxyPasswordTxt.getPassword())));
137 Configuration.setProperty("proxyHost", proxyAddressTxt.getText());
138 Configuration.setProperty("proxyPort", proxyPortTxt.getText());
139 Configuration.setProperty("useProxy", this.useProxy.isSelected());
140 dispose();
141 } else if (source == cancel) {
142 dispose();
143 }
144 }
145
146 private JButton pressme = new JButton(LanguageManager.getString("ok"));
147
148 private JButton cancel = new JButton(LanguageManager.getString("cancel"));
149
150 private String clearLoginPwd = Password.deobfuscate(Configuration.getString(
151 "proxyObfuscatedLoginPwd", ""));
152
153 private JTextField proxyAddressTxt = new JTextField(Configuration.getString(
154 "proxyHost", "192.168.0.252"));
155
156 private JTextField proxyPortTxt = new JTextField(Configuration.getInt(
157 "proxyPort", 1299));
158
159 private JPasswordField proxyPasswordTxt = new JPasswordField(clearLoginPwd
160 .substring(clearLoginPwd.indexOf(':') + 1));
161
162 private JTextField proxyLoginTxt = new JTextField(clearLoginPwd.substring(0,
163 clearLoginPwd.indexOf(':')));
164
165 /***
166 * Proxy checkBox
167 */
168 private JCheckBox useProxy = new JCheckBox(LanguageManager
169 .getString("wiz_proxy.enable"), Configuration.getBoolean("useProxy",
170 false));
171
172 }