KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > StatusPanel


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.base;
17
18 import net.sf.jftp.JFtp;
19 import net.sf.jftp.config.Settings;
20 import net.sf.jftp.gui.framework.*;
21 import net.sf.jftp.gui.hostchooser.HostChooser;
22 import net.sf.jftp.gui.hostchooser.NfsHostChooser;
23 import net.sf.jftp.gui.hostchooser.SftpHostChooser;
24 import net.sf.jftp.gui.hostchooser.SmbHostChooser;
25 import net.sf.jftp.gui.hostchooser.WebdavHostChooser;
26 import net.sf.jftp.gui.tasks.HttpBrowser;
27 import net.sf.jftp.net.*;
28 import net.sf.jftp.util.*;
29
30 import java.awt.*;
31 import java.awt.event.*;
32
33 import java.util.*;
34
35 import javax.swing.*;
36
37
38 public class StatusPanel extends HPanel implements ActionListener
39 {
40     public static StatusCanvas status = new StatusCanvas();
41     private HImageButton newcon = new HImageButton(Settings.hostImage,
42                                                    "newcon",
43                                                    "Add FTP Connection...", this);
44     private HImageButton smbcon = new HImageButton(Settings.openImage,
45                                                    "smbcon",
46                                                    "Add SMB Connection...", this);
47     private HImageButton sftpcon = new HImageButton(Settings.sftpImage,
48                                                     "sftpcon",
49                                                     "Add SFTP Connection...",
50                                                     this);
51     private HImageButton nfscon = new HImageButton(Settings.nfsImage, "nfscon",
52                                                    "Add NFS Connection...", this);
53     private HImageButton webdavcon = new HImageButton(Settings.webdavImage,
54                                                       "webdavcon",
55                                                       "Add WebDAV Connection...",
56                                                       this);
57     public HImageButton close = new HImageButton(Settings.closeImage, "close",
58                                                  "Close active tab...", this);
59     private HImageButton go = new HImageButton(Settings.refreshImage, "go",
60                                                "Download URL now...", this);
61     private JTextField address = new JTextField("http://", 30);
62     public JFtp jftp;
63
64     public StatusPanel(JFtp jftp)
65     {
66         this.jftp = jftp;
67         setLayout(new BorderLayout());
68
69         JToolBar bar = new JToolBar();
70
71         /*
72                 FlowLayout f = new FlowLayout(FlowLayout.LEFT);
73                 f.setHgap(1);
74                 f.setVgap(2);
75                 bar.setLayout(f);
76                 bar.setMargin(new Insets(0,0,0,0));
77         */

78         Insets in = bar.getMargin();
79         bar.setMargin(new Insets(in.top + 2, in.left + 4, in.bottom + 2,
80                                  in.right + 4));
81
82         bar.add(newcon);
83         newcon.setSize(24, 24);
84         newcon.setToolTipText("New FTP Connection...");
85         bar.add(new JLabel(" "));
86
87         bar.add(smbcon);
88         smbcon.setSize(24, 24);
89         smbcon.setToolTipText("New SMB Connection...");
90         bar.add(new JLabel(" "));
91
92         bar.add(sftpcon);
93         sftpcon.setSize(24, 24);
94         sftpcon.setToolTipText("New SFTP Connection...");
95         bar.add(new JLabel(" "));
96
97         bar.add(nfscon);
98         nfscon.setSize(24, 24);
99         nfscon.setToolTipText("New NFS Connection...");
100         bar.add(new JLabel(" "));
101
102         if(Settings.enableWebDav) bar.add(webdavcon);
103         webdavcon.setSize(24, 24);
104         webdavcon.setToolTipText("New WebDAV Connection...");
105         bar.add(new JLabel(" "));
106
107         bar.add(close);
108         close.setSize(24, 24);
109         close.setToolTipText("Close Active Remote tab...");
110         bar.add(new JLabel(" "));
111
112         address.addActionListener(this);
113         bar.add(new JLabel("URL: "));
114         bar.add(address);
115         bar.add(new JLabel(" "));
116         bar.add(go);
117
118         //***
119
go.setToolTipText("Download URL Now...");
120
121         //***
122
bar.add(new JLabel(" "));
123
124         //bar.add(status);
125
add("North", bar);
126
127         validate();
128         setFont(GUIDefaults.menuFont);
129         setVisible(true);
130     }
131
132     public void status(String JavaDoc msg)
133     {
134         status.setText(msg);
135     }
136
137     public String JavaDoc getHost()
138     {
139         return status.getHost();
140     }
141
142     public void setHost(String JavaDoc host)
143     {
144         status.setHost(host);
145     }
146
147     public void actionPerformed(ActionEvent e)
148     {
149         if(e.getActionCommand().equals("go") || (e.getSource() == address))
150         {
151             Vector listeners = new Vector();
152             listeners.add(JFtp.localDir);
153
154             String JavaDoc url = address.getText().trim();
155
156             startTransfer(url, JFtp.localDir.getPath(), listeners,
157                           JFtp.getConnectionHandler());
158         }
159         else if(e.getActionCommand().equals("smbcon"))
160         {
161             //jftp.safeDisconnect();
162
SmbHostChooser hc = new SmbHostChooser();
163             hc.toFront();
164
165             //hc.setModal(true);
166
hc.update();
167         }
168         else if(e.getActionCommand().equals("sftpcon"))
169         {
170             //jftp.safeDisconnect();
171
SftpHostChooser hc = new SftpHostChooser();
172             hc.toFront();
173
174             //hc.setModal(true);
175
hc.update();
176         }
177         else if(e.getActionCommand().equals("nfscon"))
178         {
179             //jftp.safeDisconnect();
180
NfsHostChooser hc = new NfsHostChooser();
181             hc.toFront();
182
183             //hc.setModal(true);
184
hc.update();
185         }
186         else if(e.getActionCommand().equals("webdavcon"))
187         {
188             //jftp.safeDisconnect();
189
WebdavHostChooser hc = new WebdavHostChooser();
190             hc.toFront();
191
192             //hc.setModal(true);
193
hc.update();
194         }
195         else if(e.getActionCommand().equals("close"))
196         {
197             jftp.closeCurrentTab();
198         }
199         else if(e.getActionCommand().equals("newcon") && (!jftp.uiBlocked))
200         {
201             // jftp.safeDisconnect();
202
// Switch windows
203
// jftp.mainFrame.setVisible(false);
204
HostChooser hc = new HostChooser();
205             hc.toFront();
206
207             //hc.setModal(true);
208
hc.update();
209         }
210     }
211
212     public void startTransfer(String JavaDoc url, String JavaDoc localPath, Vector listeners,
213                               ConnectionHandler handler)
214     {
215         if(url.startsWith("ftp://") &&
216                (url.endsWith("/") || (url.lastIndexOf("/") < 10)))
217         {
218             jftp.safeDisconnect();
219
220             HostChooser hc = new HostChooser();
221             hc.update(url);
222         }
223         else if(url.startsWith("http://") &&
224                     (url.endsWith("/") || (url.lastIndexOf("/") < 10)))
225         {
226             HttpBrowser h = new HttpBrowser(url);
227             JFtp.desktop.add(h, new Integer JavaDoc(Integer.MAX_VALUE));
228         }
229         else
230         {
231             HttpTransfer t = new HttpTransfer(url, localPath, listeners, handler);
232         }
233     }
234
235     public Insets getInsets()
236     {
237         Insets in = super.getInsets();
238
239         return new Insets(in.top, in.left, in.bottom, in.right);
240     }
241 }
242
Popular Tags