KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.jftp.*;
19 import net.sf.jftp.config.*;
20 import net.sf.jftp.gui.framework.*;
21 import net.sf.jftp.gui.tasks.ExternalDisplayer;
22 import net.sf.jftp.net.*;
23 import net.sf.jftp.system.logging.Log;
24 import net.sf.jftp.util.*;
25
26 import java.awt.*;
27 import java.awt.event.*;
28
29 import java.io.*;
30
31 import java.net.*;
32
33 import javax.swing.*;
34
35
36 public class NfsHostChooser extends HFrame implements ActionListener,
37                                                       WindowListener
38 {
39     public static HTextField host = new HTextField("URL:",
40                                                    "nfs://localhost:v2m/tmp", 20);
41     public static HTextField user = new HTextField("Username:", "<anonymous>",
42                                                    15);
43
44     //public static HTextField pass = new HTextField("Password:","none@nowhere.no");
45
public static HPasswordField pass = new HPasswordField("Password:",
46                                                            "nopasswd");
47     public static HButton info = new HButton("Read me!");
48     private HPanel okP = new HPanel();
49     private HButton ok = new HButton("Connect");
50     private ComponentListener listener = null;
51     private boolean useLocal = false;
52
53     public NfsHostChooser(ComponentListener l, boolean local)
54     {
55         listener = l;
56         useLocal = local;
57         init();
58     }
59
60     public NfsHostChooser(ComponentListener l)
61     {
62         listener = l;
63         init();
64     }
65
66     public NfsHostChooser()
67     {
68         init();
69     }
70
71     public void init()
72     {
73         //setSize(600, 220);
74
setLocation(100, 150);
75         setTitle("NFS Connection...");
76         setBackground(okP.getBackground());
77         getContentPane().setLayout(new GridLayout(4, 2, 5, 3));
78
79         JPanel p = new JPanel();
80         p.add(info);
81
82         //*** MY ADDITIONS
83
try
84         {
85             File f = new File(Settings.appHomeDir);
86             f.mkdir();
87
88             File f1 = new File(Settings.login);
89             f1.createNewFile();
90
91             File f2 = new File(Settings.login_def_nfs);
92             f2.createNewFile();
93         }
94         catch(IOException ex)
95         {
96             ex.printStackTrace();
97         }
98
99         LoadSet l = new LoadSet();
100         String JavaDoc[] login = l.loadSet(Settings.login_def_nfs);
101
102         if((login[0] != null) && (login.length > 1))
103         {
104             host.setText(login[0]);
105             user.setText(login[1]);
106         }
107
108         /*
109         else {
110                 System.out.println("made it here");
111                 host.setText("nfs://localhost:v2m/tmp");
112                 user.setText("guest");
113
114         }
115         */

116         if(Settings.getStorePasswords())
117         {
118             if((login[0] != null) && (login.length > 2) && (login[2] != null))
119             {
120                 pass.setText(login[2]);
121             }
122         }
123         else
124         {
125             pass.setText("");
126         }
127
128         //***end of my changes (for this section)
129
getContentPane().add(host);
130         getContentPane().add(p);
131         getContentPane().add(user);
132         getContentPane().add(pass);
133
134         getContentPane().add(new JLabel(""));
135         getContentPane().add(okP);
136
137         okP.add(ok);
138         ok.addActionListener(this);
139         info.addActionListener(this);
140
141         setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
142
143         pass.text.addActionListener(this);
144
145         pack();
146         setModal(false);
147         setVisible(false);
148         addWindowListener(this);
149     }
150
151     public void update()
152     {
153     fixLocation();
154         setVisible(true);
155         toFront();
156         host.requestFocus();
157     }
158
159     public void actionPerformed(ActionEvent e)
160     {
161         if(e.getSource() == info)
162         {
163             java.net.URL JavaDoc url = ClassLoader.getSystemResource(Settings.nfsinfo);
164
165             if(url == null)
166             {
167                 url = HImage.class.getResource("/" + Settings.nfsinfo);
168             }
169
170             ExternalDisplayer d = new ExternalDisplayer(url);
171         }
172         else if((e.getSource() == ok) || (e.getSource() == pass.text))
173         {
174             // Switch windows
175
//this.setVisible(false);
176
setCursor(new Cursor(Cursor.WAIT_CURSOR));
177
178             NfsConnection con = null;
179
180             String JavaDoc htmp = host.getText().trim();
181             String JavaDoc utmp = user.getText().trim();
182             String JavaDoc ptmp = pass.getText();
183
184             //*** MY ADDITIONS
185
int potmp = 0; //*** just filler for the port number
186

187             String JavaDoc userName = user.text.getText();
188
189             //***
190
try
191             {
192                 boolean status;
193                 status = StartConnection.startCon("NFS", htmp, userName, ptmp,
194                                                   potmp, "", useLocal);
195
196                 /*
197
198                 con = new NfsConnection(htmp);
199                 //JFtp.remoteDir.setCon(con);
200                 //con.addConnectionListener(((ConnectionListener)JFtp.remoteDir));
201
202                 //JFtp.statusP.jftp.addConnection(htmp, con);
203
204                 if(!userName.equals("<anonymous>")) ((NfsConnection)con).login(utmp,ptmp);
205
206                 if(useLocal)
207                 {
208                  con.setLocalPath("/");
209                       JFtp.statusP.jftp.addLocalConnection(htmp, con);
210                 }
211                 else JFtp.statusP.jftp.addConnection(htmp, con);
212
213                 con.chdir(htmp);
214
215                 //con.setLocalPath(JFtp.localDir.getCon().getPWD());
216                 //con.addConnectionListener((ConnectionListener) JFtp.localDir);
217
218
219
220                 */

221             }
222             catch(Exception JavaDoc ex)
223             {
224                 Log.debug("Could not create NfsConnection!");
225             }
226
227             setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
228             this.dispose();
229             JFtp.mainFrame.setVisible(true);
230             JFtp.mainFrame.toFront();
231
232             if(listener != null)
233             {
234                 listener.componentResized(new ComponentEvent(this, 0));
235             }
236         }
237     }
238
239     public void windowClosing(WindowEvent e)
240     {
241         //System.exit(0);
242
this.dispose();
243     }
244
245     public void windowClosed(WindowEvent e)
246     {
247     }
248
249     public void windowActivated(WindowEvent e)
250     {
251     }
252
253     public void windowDeactivated(WindowEvent e)
254     {
255     }
256
257     public void windowIconified(WindowEvent e)
258     {
259     }
260
261     public void windowDeiconified(WindowEvent e)
262     {
263     }
264
265     public void windowOpened(WindowEvent e)
266     {
267     }
268
269     public Insets getInsets()
270     {
271         Insets std = super.getInsets();
272
273         return new Insets(std.top + 10, std.left + 10, std.bottom + 10,
274                           std.right + 10);
275     }
276
277     public void pause(int time)
278     {
279         try
280         {
281             Thread.sleep(time);
282         }
283         catch(Exception JavaDoc ex)
284         {
285         }
286     }
287 }
288
Popular Tags