KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myorg > feedreader > BrowserTopComponent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.myorg.feedreader;
20
21 import java.io.IOException JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import javax.swing.JEditorPane JavaDoc;
26 import javax.swing.JScrollPane JavaDoc;
27 import org.openide.ErrorManager;
28 import org.openide.util.NbBundle;
29 import org.openide.windows.TopComponent;
30
31 /**
32  * A top component with an embedded JEditorPane based HTML browser.
33  */

34 final class BrowserTopComponent extends TopComponent {
35
36     /** The cache of opened browser components. */
37     private static Map JavaDoc browserComponents = new HashMap JavaDoc();
38
39     private final JScrollPane JavaDoc scrollPane;
40     private final JEditorPane JavaDoc editorPane;
41     
42     private final String JavaDoc title;
43     private String JavaDoc url;
44     
45     private BrowserTopComponent(String JavaDoc title) {
46         this.title = title;
47         setName(title);
48         setToolTipText(NbBundle.getMessage(BrowserTopComponent.class, "HINT_BrowserTopComponent"));
49         
50         scrollPane = new javax.swing.JScrollPane JavaDoc();
51         editorPane = new javax.swing.JEditorPane JavaDoc();
52         
53         editorPane.setContentType("text/html");
54         editorPane.setEditable(false);
55         
56         setLayout(new java.awt.BorderLayout JavaDoc());
57         scrollPane.setViewportView(editorPane);
58         add(scrollPane, java.awt.BorderLayout.CENTER);
59     }
60     
61     
62     public static synchronized BrowserTopComponent getBrowserComponent(String JavaDoc 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         // TODO add custom code on component opening
77
}
78     
79     public synchronized void componentClosed() {
80         browserComponents.remove(title);
81     }
82     
83     public void setPage(String JavaDoc url) {
84         this.url = url;
85         try {
86             editorPane.setPage(new URL JavaDoc(this.url));
87         } catch (IOException JavaDoc ioe) {
88             ErrorManager.getDefault().notify(ioe);
89         }
90     }
91     
92 }
93
Popular Tags