1 19 package org.myorg.feedreader; 20 21 import java.io.IOException ; 22 import java.net.URL ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import javax.swing.JEditorPane ; 26 import javax.swing.JScrollPane ; 27 import org.openide.ErrorManager; 28 import org.openide.util.NbBundle; 29 import org.openide.windows.TopComponent; 30 31 34 final class BrowserTopComponent extends TopComponent { 35 36 37 private static Map browserComponents = new HashMap (); 38 39 private final JScrollPane scrollPane; 40 private final JEditorPane editorPane; 41 42 private final String title; 43 private String url; 44 45 private BrowserTopComponent(String title) { 46 this.title = title; 47 setName(title); 48 setToolTipText(NbBundle.getMessage(BrowserTopComponent.class, "HINT_BrowserTopComponent")); 49 50 scrollPane = new javax.swing.JScrollPane (); 51 editorPane = new javax.swing.JEditorPane (); 52 53 editorPane.setContentType("text/html"); 54 editorPane.setEditable(false); 55 56 setLayout(new java.awt.BorderLayout ()); 57 scrollPane.setViewportView(editorPane); 58 add(scrollPane, java.awt.BorderLayout.CENTER); 59 } 60 61 62 public static synchronized BrowserTopComponent getBrowserComponent(String title) { 63 BrowserTopComponent win = (BrowserTopComponent) browserComponents.get(title); 64 if (win == null) { 65 win = new BrowserTopComponent(title); 66 browserComponents.put(title, win); 67 } 68 return (BrowserTopComponent) win; 69 } 70 71 public int getPersistenceType() { 72 return TopComponent.PERSISTENCE_NEVER; 73 } 74 75 public void componentOpened() { 76 } 78 79 public synchronized void componentClosed() { 80 browserComponents.remove(title); 81 } 82 83 public void setPage(String url) { 84 this.url = url; 85 try { 86 editorPane.setPage(new URL (this.url)); 87 } catch (IOException ioe) { 88 ErrorManager.getDefault().notify(ioe); 89 } 90 } 91 92 } 93 | Popular Tags |