1 16 package net.sf.jftp.gui.tasks; 17 18 import net.sf.jftp.*; 19 import net.sf.jftp.config.*; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.net.*; 22 import net.sf.jftp.system.logging.Log; 23 import net.sf.jftp.util.*; 24 25 import java.awt.*; 26 27 import java.io.*; 28 29 import java.util.*; 30 31 import javax.swing.*; 32 import javax.swing.event.*; 33 import javax.swing.text.html.*; 34 35 36 public class HttpBrowser extends JInternalFrame implements HyperlinkListener 37 { 38 public HttpBrowser(String url) 39 { 40 super("Http Browser", true, true, true, true); 41 42 try 43 { 44 setTitle(url); 45 46 JEditorPane pane = new JEditorPane(url); 47 pane.setEditable(false); 48 pane.addHyperlinkListener(this); 49 50 if(!pane.getEditorKit().getContentType().equals("text/html") && 51 !pane.getEditorKit().getContentType().equals("text/rtf")) 52 { 53 if(!pane.getEditorKit().getContentType().equals("text/plain")) 54 { 55 Log.debug("Could not display URL."); 56 57 return; 58 } 59 60 pane.setEditable(false); 61 pane.addHyperlinkListener(this); 62 } 63 64 JScrollPane jsp = new JScrollPane(pane); 65 66 getContentPane().setLayout(new BorderLayout()); 67 getContentPane().add("Center", jsp); 68 69 setLocation(50, 50); 70 setSize(600, 400); 71 show(); 72 requestFocus(); 73 } 74 catch(Exception ex) 75 { 76 Log.debug("Error fetching URL: " + ex); 77 ex.printStackTrace(); 78 } 79 } 80 81 public void hyperlinkUpdate(HyperlinkEvent e) 82 { 83 if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 84 { 85 JEditorPane pane = (JEditorPane) e.getSource(); 86 87 if(e instanceof HTMLFrameHyperlinkEvent) 88 { 89 HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e; 90 HTMLDocument doc = (HTMLDocument) pane.getDocument(); 91 doc.processHTMLFrameHyperlinkEvent(evt); 92 } 93 else 94 { 95 try 96 { 97 String url = e.getURL().toString(); 98 String tmp = url.substring(url.lastIndexOf("/")); 99 100 Vector listeners = new Vector(); 101 listeners.add(JFtp.localDir); 102 103 if(!url.endsWith(".htm") && !url.endsWith(".html") && 104 (tmp.indexOf(".") >= 0)) 105 { 106 JFtp.statusP.startTransfer(url, 107 JFtp.localDir.getPath(), 108 listeners, 109 JFtp.getConnectionHandler()); 110 } 111 else 112 { 113 pane.setPage(e.getURL()); 114 } 115 } 116 catch(Throwable t) 117 { 118 t.printStackTrace(); 119 } 120 } 121 } 122 } 123 } 124 | Popular Tags |