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.base;
017:
018: import net.sf.jftp.JFtp;
019: import net.sf.jftp.config.Settings;
020: import net.sf.jftp.gui.framework.*;
021: import net.sf.jftp.gui.hostchooser.HostChooser;
022: import net.sf.jftp.gui.hostchooser.NfsHostChooser;
023: import net.sf.jftp.gui.hostchooser.SftpHostChooser;
024: import net.sf.jftp.gui.hostchooser.SmbHostChooser;
025: import net.sf.jftp.gui.hostchooser.WebdavHostChooser;
026: import net.sf.jftp.gui.tasks.HttpBrowser;
027: import net.sf.jftp.net.*;
028: import net.sf.jftp.util.*;
029:
030: import java.awt.*;
031: import java.awt.event.*;
032:
033: import java.util.*;
034:
035: import javax.swing.*;
036:
037: public class StatusPanel extends HPanel implements ActionListener {
038: public static StatusCanvas status = new StatusCanvas();
039: private HImageButton newcon = new HImageButton(Settings.hostImage,
040: "newcon", "Add FTP Connection...", this );
041: private HImageButton smbcon = new HImageButton(Settings.openImage,
042: "smbcon", "Add SMB Connection...", this );
043: private HImageButton sftpcon = new HImageButton(Settings.sftpImage,
044: "sftpcon", "Add SFTP Connection...", this );
045: private HImageButton nfscon = new HImageButton(Settings.nfsImage,
046: "nfscon", "Add NFS Connection...", this );
047: private HImageButton webdavcon = new HImageButton(
048: Settings.webdavImage, "webdavcon",
049: "Add WebDAV Connection...", this );
050: public HImageButton close = new HImageButton(Settings.closeImage,
051: "close", "Close active tab...", this );
052: private HImageButton go = new HImageButton(Settings.refreshImage,
053: "go", "Download URL now...", this );
054: private JTextField address = new JTextField("http://", 30);
055: public JFtp jftp;
056:
057: public StatusPanel(JFtp jftp) {
058: this .jftp = jftp;
059: setLayout(new BorderLayout());
060:
061: JToolBar bar = new JToolBar();
062:
063: /*
064: FlowLayout f = new FlowLayout(FlowLayout.LEFT);
065: f.setHgap(1);
066: f.setVgap(2);
067: bar.setLayout(f);
068: bar.setMargin(new Insets(0,0,0,0));
069: */
070: Insets in = bar.getMargin();
071: bar.setMargin(new Insets(in.top + 2, in.left + 4,
072: in.bottom + 2, in.right + 4));
073:
074: bar.add(newcon);
075: newcon.setSize(24, 24);
076: newcon.setToolTipText("New FTP Connection...");
077: bar.add(new JLabel(" "));
078:
079: bar.add(smbcon);
080: smbcon.setSize(24, 24);
081: smbcon.setToolTipText("New SMB Connection...");
082: bar.add(new JLabel(" "));
083:
084: bar.add(sftpcon);
085: sftpcon.setSize(24, 24);
086: sftpcon.setToolTipText("New SFTP Connection...");
087: bar.add(new JLabel(" "));
088:
089: bar.add(nfscon);
090: nfscon.setSize(24, 24);
091: nfscon.setToolTipText("New NFS Connection...");
092: bar.add(new JLabel(" "));
093:
094: if (Settings.enableWebDav)
095: bar.add(webdavcon);
096: webdavcon.setSize(24, 24);
097: webdavcon.setToolTipText("New WebDAV Connection...");
098: bar.add(new JLabel(" "));
099:
100: bar.add(close);
101: close.setSize(24, 24);
102: close.setToolTipText("Close Active Remote tab...");
103: bar.add(new JLabel(" "));
104:
105: address.addActionListener(this );
106: bar.add(new JLabel("URL: "));
107: bar.add(address);
108: bar.add(new JLabel(" "));
109: bar.add(go);
110:
111: //***
112: go.setToolTipText("Download URL Now...");
113:
114: //***
115: bar.add(new JLabel(" "));
116:
117: //bar.add(status);
118: add("North", bar);
119:
120: validate();
121: setFont(GUIDefaults.menuFont);
122: setVisible(true);
123: }
124:
125: public void status(String msg) {
126: status.setText(msg);
127: }
128:
129: public String getHost() {
130: return status.getHost();
131: }
132:
133: public void setHost(String host) {
134: status.setHost(host);
135: }
136:
137: public void actionPerformed(ActionEvent e) {
138: if (e.getActionCommand().equals("go")
139: || (e.getSource() == address)) {
140: Vector listeners = new Vector();
141: listeners.add(JFtp.localDir);
142:
143: String url = address.getText().trim();
144:
145: startTransfer(url, JFtp.localDir.getPath(), listeners, JFtp
146: .getConnectionHandler());
147: } else if (e.getActionCommand().equals("smbcon")) {
148: //jftp.safeDisconnect();
149: SmbHostChooser hc = new SmbHostChooser();
150: hc.toFront();
151:
152: //hc.setModal(true);
153: hc.update();
154: } else if (e.getActionCommand().equals("sftpcon")) {
155: //jftp.safeDisconnect();
156: SftpHostChooser hc = new SftpHostChooser();
157: hc.toFront();
158:
159: //hc.setModal(true);
160: hc.update();
161: } else if (e.getActionCommand().equals("nfscon")) {
162: //jftp.safeDisconnect();
163: NfsHostChooser hc = new NfsHostChooser();
164: hc.toFront();
165:
166: //hc.setModal(true);
167: hc.update();
168: } else if (e.getActionCommand().equals("webdavcon")) {
169: //jftp.safeDisconnect();
170: WebdavHostChooser hc = new WebdavHostChooser();
171: hc.toFront();
172:
173: //hc.setModal(true);
174: hc.update();
175: } else if (e.getActionCommand().equals("close")) {
176: jftp.closeCurrentTab();
177: } else if (e.getActionCommand().equals("newcon")
178: && (!jftp.uiBlocked)) {
179: // jftp.safeDisconnect();
180: // Switch windows
181: // jftp.mainFrame.setVisible(false);
182: HostChooser hc = new HostChooser();
183: hc.toFront();
184:
185: //hc.setModal(true);
186: hc.update();
187: }
188: }
189:
190: public void startTransfer(String url, String localPath,
191: Vector listeners, ConnectionHandler handler) {
192: if (url.startsWith("ftp://")
193: && (url.endsWith("/") || (url.lastIndexOf("/") < 10))) {
194: jftp.safeDisconnect();
195:
196: HostChooser hc = new HostChooser();
197: hc.update(url);
198: } else if (url.startsWith("http://")
199: && (url.endsWith("/") || (url.lastIndexOf("/") < 10))) {
200: HttpBrowser h = new HttpBrowser(url);
201: JFtp.desktop.add(h, new Integer(Integer.MAX_VALUE));
202: } else {
203: HttpTransfer t = new HttpTransfer(url, localPath,
204: listeners, handler);
205: }
206: }
207:
208: public Insets getInsets() {
209: Insets in = super .getInsets();
210:
211: return new Insets(in.top, in.left, in.bottom, in.right);
212: }
213: }
|