/Users/lyon/j4p/src/gui/browser/BrowserListener.java

1    package gui.browser; 
2     
3    import javax.swing.*; 
4    import javax.swing.event.HyperlinkEvent; 
5    import javax.swing.event.HyperlinkListener; 
6    import javax.swing.text.html.HTMLDocument; 
7    import javax.swing.text.html.HTMLFrameHyperlinkEvent; 
8     
9    public class BrowserListener 
10           implements HyperlinkListener { 
11    
12       BrowserLogic bl; 
13       JTextField tf; 
14    
15       public BrowserListener(BrowserLogic _bl, JTextField _tf) { 
16           bl = _bl; 
17           tf = _tf; 
18       } 
19    
20       public void hyperlinkUpdate(HyperlinkEvent e) { 
21           if (e.getEventType() == 
22                   HyperlinkEvent.EventType.ACTIVATED) { 
23               processActivated(e); 
24           } 
25       } 
26    
27       private void processActivated(HyperlinkEvent e) { 
28           JEditorPane jep = 
29                   (JEditorPane) e.getSource(); 
30           if (e instanceof HTMLFrameHyperlinkEvent) 
31               processHyperLinkEvent(e, jep); 
32           else { 
33               //     new ThreadedLoad(jep,e.getURL()); 
34               bl.hyperlinkPage(jep, e, tf); 
35           } 
36       } 
37    
38       private void setPage(JEditorPane jep, 
39                            HyperlinkEvent e) { 
40           new ThreadedLoad(jep, e.getURL()); 
41       } 
42    
43    
44       private void processHyperLinkEvent( 
45               HyperlinkEvent e, JEditorPane pane) { 
46           HTMLFrameHyperlinkEvent hle = (HTMLFrameHyperlinkEvent) e; 
47           HTMLDocument htmlDoc = (HTMLDocument) pane.getDocument(); 
48           htmlDoc.processHTMLFrameHyperlinkEvent(hle); 
49       } 
50   }