KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.BorderLayout JavaDoc;
22 import java.io.Serializable JavaDoc;
23 import javax.swing.ActionMap JavaDoc;
24 import org.openide.ErrorManager;
25 import org.openide.explorer.ExplorerManager;
26 import org.openide.explorer.ExplorerUtils;
27 import org.openide.explorer.view.BeanTreeView;
28 import org.openide.loaders.DataObjectNotFoundException;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
31 import org.openide.windows.TopComponent;
32
33 final class FeedTopComponent extends TopComponent implements ExplorerManager.Provider {
34
35     private static FeedTopComponent instance;
36     
37     private final ExplorerManager manager = new ExplorerManager();
38     private final BeanTreeView view = new BeanTreeView();
39     
40     private FeedTopComponent() {
41         setName(NbBundle.getMessage(FeedTopComponent.class, "CTL_FeedTopComponent"));
42         setToolTipText(NbBundle.getMessage(FeedTopComponent.class, "HINT_FeedTopComponent"));
43         setIcon(Utilities.loadImage("org/myorg/feedreader/rss16.gif", true));
44         setLayout(new BorderLayout JavaDoc());
45         add(view, BorderLayout.CENTER);
46         view.setRootVisible(true);
47         try {
48             manager.setRootContext(new RssNode.RootRssNode());
49         } catch (DataObjectNotFoundException ex) {
50             ErrorManager.getDefault().notify(ex);
51         }
52         ActionMap JavaDoc map = getActionMap();
53         map.put("delete", ExplorerUtils.actionDelete(manager, true));
54         associateLookup(ExplorerUtils.createLookup(manager, map));
55     }
56     
57     public static synchronized FeedTopComponent getDefault() {
58         if (instance == null) {
59             instance = new FeedTopComponent();
60         }
61         return instance;
62     }
63     
64     public int getPersistenceType() {
65         return TopComponent.PERSISTENCE_ALWAYS;
66     }
67     
68     protected String JavaDoc preferredID() {
69         return "FeedTopComponent";
70     }
71     
72     protected Object JavaDoc writeReplace() {
73         return new ResolvableHelper();
74     }
75     
76     private static final class ResolvableHelper implements Serializable JavaDoc {
77         
78         private static final long serialVersionUID = 1L;
79         
80         public Object JavaDoc readResolve() {
81             return FeedTopComponent.getDefault();
82         }
83         
84     }
85     
86     public ExplorerManager getExplorerManager() {
87         return manager;
88     }
89     
90 }
91
Popular Tags