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.tasks;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.*;
020: import net.sf.jftp.gui.framework.*;
021: import net.sf.jftp.net.*;
022: import net.sf.jftp.system.logging.Log;
023: import net.sf.jftp.util.*;
024:
025: import java.awt.*;
026:
027: import java.io.*;
028:
029: import java.util.*;
030:
031: import javax.swing.*;
032: import javax.swing.event.*;
033: import javax.swing.text.html.*;
034:
035: public class HttpBrowser extends JInternalFrame implements
036: HyperlinkListener {
037: public HttpBrowser(String url) {
038: super ("Http Browser", true, true, true, true);
039:
040: try {
041: setTitle(url);
042:
043: JEditorPane pane = new JEditorPane(url);
044: pane.setEditable(false);
045: pane.addHyperlinkListener(this );
046:
047: if (!pane.getEditorKit().getContentType().equals(
048: "text/html")
049: && !pane.getEditorKit().getContentType().equals(
050: "text/rtf")) {
051: if (!pane.getEditorKit().getContentType().equals(
052: "text/plain")) {
053: Log.debug("Could not display URL.");
054:
055: return;
056: }
057:
058: pane.setEditable(false);
059: pane.addHyperlinkListener(this );
060: }
061:
062: JScrollPane jsp = new JScrollPane(pane);
063:
064: getContentPane().setLayout(new BorderLayout());
065: getContentPane().add("Center", jsp);
066:
067: setLocation(50, 50);
068: setSize(600, 400);
069: show();
070: requestFocus();
071: } catch (Exception ex) {
072: Log.debug("Error fetching URL: " + ex);
073: ex.printStackTrace();
074: }
075: }
076:
077: public void hyperlinkUpdate(HyperlinkEvent e) {
078: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
079: JEditorPane pane = (JEditorPane) e.getSource();
080:
081: if (e instanceof HTMLFrameHyperlinkEvent) {
082: HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
083: HTMLDocument doc = (HTMLDocument) pane.getDocument();
084: doc.processHTMLFrameHyperlinkEvent(evt);
085: } else {
086: try {
087: String url = e.getURL().toString();
088: String tmp = url.substring(url.lastIndexOf("/"));
089:
090: Vector listeners = new Vector();
091: listeners.add(JFtp.localDir);
092:
093: if (!url.endsWith(".htm") && !url.endsWith(".html")
094: && (tmp.indexOf(".") >= 0)) {
095: JFtp.statusP.startTransfer(url, JFtp.localDir
096: .getPath(), listeners, JFtp
097: .getConnectionHandler());
098: } else {
099: pane.setPage(e.getURL());
100: }
101: } catch (Throwable t) {
102: t.printStackTrace();
103: }
104: }
105: }
106: }
107: }
|