KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > hostchooser > WebdavHostChooser


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.hostchooser;
17
18 import java.awt.BorderLayout JavaDoc;
19 import java.awt.Cursor JavaDoc;
20 import java.awt.Dimension JavaDoc;
21 import java.awt.GridLayout JavaDoc;
22 import java.awt.Insets JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.ComponentEvent JavaDoc;
26 import java.awt.event.ComponentListener JavaDoc;
27 import java.awt.event.WindowEvent JavaDoc;
28 import java.awt.event.WindowListener JavaDoc;
29
30 import javax.swing.JDialog JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32
33 import net.sf.jftp.JFtp;
34 import net.sf.jftp.gui.framework.HButton;
35 import net.sf.jftp.gui.framework.HFrame;
36 import net.sf.jftp.gui.framework.HPanel;
37 import net.sf.jftp.gui.framework.HPasswordField;
38 import net.sf.jftp.gui.framework.HTextField;
39 import net.sf.jftp.net.ConnectionListener;
40 import net.sf.jftp.net.WebdavConnection;
41
42
43 public class WebdavHostChooser extends HFrame implements ActionListener JavaDoc,
44                                                          WindowListener JavaDoc
45 {
46     public static HTextField host = new HTextField("URL:", "http://localhost",
47                                                    35);
48     public static HTextField user = new HTextField("Username:", "guest");
49
50     //public static HTextField port = new HTextField("Port:","22");
51
public static HPasswordField pass = new HPasswordField("Password:",
52                                                            "nopasswd");
53     private HPanel okP = new HPanel();
54     private HButton ok = new HButton("Connect");
55     private ComponentListener JavaDoc listener = null;
56     private boolean useLocal = false;
57
58     public WebdavHostChooser(ComponentListener JavaDoc l, boolean local)
59     {
60         listener = l;
61         useLocal = local;
62         init();
63     }
64
65     public WebdavHostChooser(ComponentListener JavaDoc l)
66     {
67         listener = l;
68         init();
69     }
70
71     public WebdavHostChooser()
72     {
73         init();
74     }
75
76     public void init()
77     {
78         //setSize(500, 200);
79
setLocation(100, 150);
80         setTitle("WebDAV Connection... (ALPHA STATE)");
81         setBackground(okP.getBackground());
82
83         host.setMinimumSize(new Dimension JavaDoc(500, 50));
84         getContentPane().setLayout(new BorderLayout JavaDoc(5, 5));
85         getContentPane().add("North", host);
86
87         HPanel p = new HPanel();
88         p.setLayout(new GridLayout JavaDoc(2, 2, 5, 3));
89
90         //***MY CHANGES
91
/*
92         try {
93                 File f = new File(Settings.appHomeDir);
94                 f.mkdir();
95                 File f1 = new File(Settings.login);
96                 f1.createNewFile();
97                 File f2 = new File(Settings.login_def_sftp);
98                 f2.createNewFile();
99                 File f3 = new File(Settings.ls_out);
100                 f3.createNewFile();
101                 File f4 = new File(Settings.sortls_out);
102                 f4.createNewFile();
103                 File f5 = new File(Settings.sortsize_out);
104                 f5.createNewFile();
105                 File f6 = new File(Settings.permissions_out);
106                 f6.createNewFile();
107         } catch (IOException ex) {
108                 ex.printStackTrace();
109         }
110
111         LoadSet l = new LoadSet();
112         String login[] = l.loadSet(Settings.login_def_sftp);
113
114
115         if (login[0] != null) {
116                 host.setText(login[0]);
117                 user.setText(login[1]);
118
119         }
120         */

121         /*
122         else {
123                 host.setText("localhost");
124                 user.setText("guest");
125
126         }
127         */

128         /*
129         if (Settings.getStorePasswords()) {
130                 if (login != null) {
131                         pass.setText(login[2]);
132                 }
133
134         } else
135                 pass.setText("");
136
137         */

138         //***end of my changes (for this section)
139
//getContentPane().add(host);
140
//getContentPane().add(new JLabel(" "));//port);
141
//getContentPane()
142
p.add(user);
143
144         //getContentPane()
145
p.add(pass);
146
147         //getContentPane()
148
p.add(new JLabel JavaDoc(""));
149
150         //getContentPane()
151
p.add(okP);
152
153         okP.add(ok);
154
155         getContentPane().add("South", p);
156
157         ok.addActionListener(this);
158
159         setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
160
161         pass.text.addActionListener(this);
162
163         setModal(false);
164         setVisible(false);
165         addWindowListener(this);
166
167         //novell webdav test site
168
host.setText("http://www.planetpdf.com/planetpdf/webdavdemo/");
169         user.setText("guest");
170         pass.setText("guest");
171
172         pack();
173     }
174
175     public void update()
176     {
177         setVisible(true);
178         toFront();
179         host.requestFocus();
180     }
181
182     public void actionPerformed(ActionEvent JavaDoc e)
183     {
184         if((e.getSource() == ok) || (e.getSource() == pass.text))
185         {
186             setCursor(new Cursor JavaDoc(Cursor.WAIT_CURSOR));
187
188             String JavaDoc htmp = host.getText().trim();
189             String JavaDoc utmp = user.getText().trim();
190             String JavaDoc ptmp = pass.getText();
191
192             WebdavConnection con;
193
194             if(useLocal)
195             {
196                 con = new WebdavConnection(htmp, utmp, ptmp,
197                                            (ConnectionListener) JFtp.localDir);
198                 JFtp.statusP.jftp.addLocalConnection("Webdav", con);
199                 con.chdir(htmp);
200             }
201             else
202             {
203                 con = new WebdavConnection(htmp, utmp, ptmp,
204                                            (ConnectionListener) JFtp.remoteDir);
205                 JFtp.statusP.jftp.addConnection("Webdav", con);
206                 con.chdir(htmp);
207             }
208
209             setCursor(new Cursor JavaDoc(Cursor.DEFAULT_CURSOR));
210             this.dispose();
211             JFtp.mainFrame.setVisible(true);
212             JFtp.mainFrame.toFront();
213
214             if(listener != null)
215             {
216                 listener.componentResized(new ComponentEvent JavaDoc(this, 0));
217             }
218         }
219     }
220
221     public void windowClosing(WindowEvent JavaDoc e)
222     {
223         //System.exit(0);
224
this.dispose();
225     }
226
227     public void windowClosed(WindowEvent JavaDoc e)
228     {
229     }
230
231     public void windowActivated(WindowEvent JavaDoc e)
232     {
233     }
234
235     public void windowDeactivated(WindowEvent JavaDoc e)
236     {
237     }
238
239     public void windowIconified(WindowEvent JavaDoc e)
240     {
241     }
242
243     public void windowDeiconified(WindowEvent JavaDoc e)
244     {
245     }
246
247     public void windowOpened(WindowEvent JavaDoc e)
248     {
249     }
250
251     public Insets JavaDoc getInsets()
252     {
253         Insets JavaDoc std = super.getInsets();
254
255         return new Insets JavaDoc(std.top + 10, std.left + 10, std.bottom + 10,
256                           std.right + 10);
257     }
258
259     public void pause(int time)
260     {
261         try
262         {
263             Thread.sleep(time);
264         }
265         catch(Exception JavaDoc ex)
266         {
267         }
268     }
269 }
270
Popular Tags