001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.hostchooser;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.*;
020: import net.sf.jftp.gui.framework.*;
021: import net.sf.jftp.gui.tasks.ExternalDisplayer;
022: import net.sf.jftp.net.*;
023: import net.sf.jftp.system.logging.Log;
024: import net.sf.jftp.util.*;
025:
026: import java.awt.*;
027: import java.awt.event.*;
028:
029: import java.io.*;
030:
031: import java.net.*;
032:
033: import javax.swing.*;
034:
035: public class NfsHostChooser extends HFrame implements ActionListener,
036: WindowListener {
037: public static HTextField host = new HTextField("URL:",
038: "nfs://localhost:v2m/tmp", 20);
039: public static HTextField user = new HTextField("Username:",
040: "<anonymous>", 15);
041:
042: //public static HTextField pass = new HTextField("Password:","none@nowhere.no");
043: public static HPasswordField pass = new HPasswordField("Password:",
044: "nopasswd");
045: public static HButton info = new HButton("Read me!");
046: private HPanel okP = new HPanel();
047: private HButton ok = new HButton("Connect");
048: private ComponentListener listener = null;
049: private boolean useLocal = false;
050:
051: public NfsHostChooser(ComponentListener l, boolean local) {
052: listener = l;
053: useLocal = local;
054: init();
055: }
056:
057: public NfsHostChooser(ComponentListener l) {
058: listener = l;
059: init();
060: }
061:
062: public NfsHostChooser() {
063: init();
064: }
065:
066: public void init() {
067: //setSize(600, 220);
068: setLocation(100, 150);
069: setTitle("NFS Connection...");
070: setBackground(okP.getBackground());
071: getContentPane().setLayout(new GridLayout(4, 2, 5, 3));
072:
073: JPanel p = new JPanel();
074: p.add(info);
075:
076: //*** MY ADDITIONS
077: try {
078: File f = new File(Settings.appHomeDir);
079: f.mkdir();
080:
081: File f1 = new File(Settings.login);
082: f1.createNewFile();
083:
084: File f2 = new File(Settings.login_def_nfs);
085: f2.createNewFile();
086: } catch (IOException ex) {
087: ex.printStackTrace();
088: }
089:
090: LoadSet l = new LoadSet();
091: String[] login = l.loadSet(Settings.login_def_nfs);
092:
093: if ((login[0] != null) && (login.length > 1)) {
094: host.setText(login[0]);
095: user.setText(login[1]);
096: }
097:
098: /*
099: else {
100: System.out.println("made it here");
101: host.setText("nfs://localhost:v2m/tmp");
102: user.setText("guest");
103:
104: }
105: */
106: if (Settings.getStorePasswords()) {
107: if ((login[0] != null) && (login.length > 2)
108: && (login[2] != null)) {
109: pass.setText(login[2]);
110: }
111: } else {
112: pass.setText("");
113: }
114:
115: //***end of my changes (for this section)
116: getContentPane().add(host);
117: getContentPane().add(p);
118: getContentPane().add(user);
119: getContentPane().add(pass);
120:
121: getContentPane().add(new JLabel(""));
122: getContentPane().add(okP);
123:
124: okP.add(ok);
125: ok.addActionListener(this );
126: info.addActionListener(this );
127:
128: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
129:
130: pass.text.addActionListener(this );
131:
132: pack();
133: setModal(false);
134: setVisible(false);
135: addWindowListener(this );
136: }
137:
138: public void update() {
139: fixLocation();
140: setVisible(true);
141: toFront();
142: host.requestFocus();
143: }
144:
145: public void actionPerformed(ActionEvent e) {
146: if (e.getSource() == info) {
147: java.net.URL url = ClassLoader
148: .getSystemResource(Settings.nfsinfo);
149:
150: if (url == null) {
151: url = HImage.class.getResource("/" + Settings.nfsinfo);
152: }
153:
154: ExternalDisplayer d = new ExternalDisplayer(url);
155: } else if ((e.getSource() == ok)
156: || (e.getSource() == pass.text)) {
157: // Switch windows
158: //this.setVisible(false);
159: setCursor(new Cursor(Cursor.WAIT_CURSOR));
160:
161: NfsConnection con = null;
162:
163: String htmp = host.getText().trim();
164: String utmp = user.getText().trim();
165: String ptmp = pass.getText();
166:
167: //*** MY ADDITIONS
168: int potmp = 0; //*** just filler for the port number
169:
170: String userName = user.text.getText();
171:
172: //***
173: try {
174: boolean status;
175: status = StartConnection.startCon("NFS", htmp,
176: userName, ptmp, potmp, "", useLocal);
177:
178: /*
179:
180: con = new NfsConnection(htmp);
181: //JFtp.remoteDir.setCon(con);
182: //con.addConnectionListener(((ConnectionListener)JFtp.remoteDir));
183:
184: //JFtp.statusP.jftp.addConnection(htmp, con);
185:
186: if(!userName.equals("<anonymous>")) ((NfsConnection)con).login(utmp,ptmp);
187:
188: if(useLocal)
189: {
190: con.setLocalPath("/");
191: JFtp.statusP.jftp.addLocalConnection(htmp, con);
192: }
193: else JFtp.statusP.jftp.addConnection(htmp, con);
194:
195: con.chdir(htmp);
196:
197: //con.setLocalPath(JFtp.localDir.getCon().getPWD());
198: //con.addConnectionListener((ConnectionListener) JFtp.localDir);
199:
200:
201:
202: */
203: } catch (Exception ex) {
204: Log.debug("Could not create NfsConnection!");
205: }
206:
207: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
208: this .dispose();
209: JFtp.mainFrame.setVisible(true);
210: JFtp.mainFrame.toFront();
211:
212: if (listener != null) {
213: listener.componentResized(new ComponentEvent(this , 0));
214: }
215: }
216: }
217:
218: public void windowClosing(WindowEvent e) {
219: //System.exit(0);
220: this .dispose();
221: }
222:
223: public void windowClosed(WindowEvent e) {
224: }
225:
226: public void windowActivated(WindowEvent e) {
227: }
228:
229: public void windowDeactivated(WindowEvent e) {
230: }
231:
232: public void windowIconified(WindowEvent e) {
233: }
234:
235: public void windowDeiconified(WindowEvent e) {
236: }
237:
238: public void windowOpened(WindowEvent e) {
239: }
240:
241: public Insets getInsets() {
242: Insets std = super .getInsets();
243:
244: return new Insets(std.top + 10, std.left + 10, std.bottom + 10,
245: std.right + 10);
246: }
247:
248: public void pause(int time) {
249: try {
250: Thread.sleep(time);
251: } catch (Exception ex) {
252: }
253: }
254: }
|