KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.jftp.JFtp;
19 import net.sf.jftp.config.Settings;
20 import net.sf.jftp.gui.base.UIUtils;
21 import net.sf.jftp.gui.framework.*;
22 import net.sf.jftp.net.*;
23
24 import java.awt.*;
25 import java.awt.event.*;
26
27 import java.io.*;
28
29 import java.lang.Integer JavaDoc;
30
31 import java.util.*;
32
33 import javax.swing.*;
34
35
36 //***
37
public class BookmarkItem extends JMenuItem
38 {
39     private String JavaDoc host = "localhost";
40     private String JavaDoc user = "anonymous";
41     private String JavaDoc pass = "j-ftp@sourceforge.net";
42     private String JavaDoc protocol = "FTP";
43     private int port = 21;
44     private String JavaDoc dirOrDom = "/";
45     private boolean useLocal = false;
46
47     public BookmarkItem(String JavaDoc host)
48     {
49         super(host);
50         this.host = host;
51     }
52
53     public void setProtocol(String JavaDoc proto)
54     {
55         protocol = proto;
56         setLabel(proto + ": " + getLabel());
57     }
58
59     public void setDirectory(String JavaDoc dir)
60     {
61         dirOrDom = dir;
62     }
63
64     public void setPort(int p)
65     {
66         port = p;
67     }
68
69     public void setLocal(boolean local)
70     {
71         useLocal = local;
72     }
73
74     public void setUserdata(String JavaDoc u, String JavaDoc p)
75     {
76         user = u;
77         pass = p;
78     }
79
80     public void connect()
81     {
82         if(protocol.equals("FTP"))
83         {
84             if(pass.equals(Settings.hiddenPassword))
85             {
86                 pass = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
87             }
88
89             int i = StartConnection.startFtpCon(host, user, pass, port,
90                                                 dirOrDom, useLocal);
91
92             if(i < 0)
93             {
94                 pass = Settings.hiddenPassword;
95             }
96
97             /*
98             FtpConnection con = StartConnection.con;
99
100             if(con != null)
101             {
102                     con.chdir(dirOrDom);
103             }
104             */

105         }
106         else
107         {
108             if(pass.equals(Settings.hiddenPassword))
109             {
110                 pass = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
111             }
112
113             boolean ok = StartConnection.startCon(protocol, host, user, pass,
114                                                   port, dirOrDom, useLocal);
115
116             if(!ok)
117             {
118                 pass = Settings.hiddenPassword;
119             }
120         }
121     }
122 }
123
Popular Tags