KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > tasks > ProxyChooser


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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 JavaDoc;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.ActionListener JavaDoc;
21
22 import javax.swing.JLabel JavaDoc;
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
31 public class ProxyChooser extends HPanel implements ActionListener JavaDoc
32 {
33     private HTextField proxy;
34     private HTextField port;
35     private HButton ok = new HButton("Ok");
36
37     public ProxyChooser()
38     {
39         //setSize(500,120);
40
//setTitle("Proxy settings...");
41
//setLocation(50,150);
42
//getContentPane().
43
setLayout(new FlowLayout JavaDoc(FlowLayout.LEFT));
44
45         proxy = new HTextField("Socks proxy:", "");
46         port = new HTextField("Port:", "");
47
48         proxy.setText(Settings.getSocksProxyHost());
49         port.setText(Settings.getSocksProxyPort());
50
51         //getContentPane().
52
add(proxy);
53
54         //getContentPane().
55
add(port);
56
57         //getContentPane().
58
add(ok);
59
60         //getContentPane().
61
add(new JLabel JavaDoc("Please note that you have to restart JFtp to apply the changes!"));
62         ok.addActionListener(this);
63
64         //setVisible(true);
65
}
66
67     public void actionPerformed(ActionEvent JavaDoc e)
68     {
69         if(e.getSource() == ok)
70         {
71             //setVisible(false);
72
String JavaDoc h = proxy.getText().trim();
73             String JavaDoc p = port.getText().trim();
74
75             java.util.Properties JavaDoc sysprops = System.getProperties();
76
77             // Remove previous values
78
sysprops.remove("socksProxyHost");
79             sysprops.remove("socksProxyPort");
80
81             Settings.setProperty("jftp.socksProxyHost", h);
82             Settings.setProperty("jftp.socksProxyPort", p);
83             Settings.save();
84
85             Log.out("proxy vars: " + h + ":" + p);
86
87             if(h.equals("") || p.equals(""))
88             {
89                 return;
90             }
91
92             // Set your values
93
sysprops.put("socksProxyHost", h);
94             sysprops.put("socksProxyPort", p);
95
96             Log.out("new proxy vars set.");
97
98             remove(3);
99             add(new JLabel JavaDoc("Options set. Please restart JFtp."));
100             validate();
101             setVisible(true);
102         }
103     }
104 }
105
Popular Tags