01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.gui.tasks;
17:
18: import java.awt.FlowLayout;
19: import java.awt.event.ActionEvent;
20: import java.awt.event.ActionListener;
21:
22: import javax.swing.JLabel;
23:
24: import net.sf.jftp.config.Settings;
25: import net.sf.jftp.gui.framework.HButton;
26: import net.sf.jftp.gui.framework.HPanel;
27: import net.sf.jftp.gui.framework.HTextField;
28: import net.sf.jftp.system.logging.Log;
29:
30: public class ProxyChooser extends HPanel implements ActionListener {
31: private HTextField proxy;
32: private HTextField port;
33: private HButton ok = new HButton("Ok");
34:
35: public ProxyChooser() {
36: //setSize(500,120);
37: //setTitle("Proxy settings...");
38: //setLocation(50,150);
39: //getContentPane().
40: setLayout(new FlowLayout(FlowLayout.LEFT));
41:
42: proxy = new HTextField("Socks proxy:", "");
43: port = new HTextField("Port:", "");
44:
45: proxy.setText(Settings.getSocksProxyHost());
46: port.setText(Settings.getSocksProxyPort());
47:
48: //getContentPane().
49: add(proxy);
50:
51: //getContentPane().
52: add(port);
53:
54: //getContentPane().
55: add(ok);
56:
57: //getContentPane().
58: add(new JLabel(
59: "Please note that you have to restart JFtp to apply the changes!"));
60: ok.addActionListener(this );
61:
62: //setVisible(true);
63: }
64:
65: public void actionPerformed(ActionEvent e) {
66: if (e.getSource() == ok) {
67: //setVisible(false);
68: String h = proxy.getText().trim();
69: String p = port.getText().trim();
70:
71: java.util.Properties sysprops = System.getProperties();
72:
73: // Remove previous values
74: sysprops.remove("socksProxyHost");
75: sysprops.remove("socksProxyPort");
76:
77: Settings.setProperty("jftp.socksProxyHost", h);
78: Settings.setProperty("jftp.socksProxyPort", p);
79: Settings.save();
80:
81: Log.out("proxy vars: " + h + ":" + p);
82:
83: if (h.equals("") || p.equals("")) {
84: return;
85: }
86:
87: // Set your values
88: sysprops.put("socksProxyHost", h);
89: sysprops.put("socksProxyPort", p);
90:
91: Log.out("new proxy vars set.");
92:
93: remove(3);
94: add(new JLabel("Options set. Please restart JFtp."));
95: validate();
96: setVisible(true);
97: }
98: }
99: }
|