KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > comments > AutoCommentTopComponent


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
20 package org.netbeans.modules.javadoc.comments;
21
22 import java.io.*;
23 import java.awt.BorderLayout JavaDoc;
24 import java.lang.ref.Reference JavaDoc;
25 import java.lang.ref.SoftReference JavaDoc;
26
27 import org.openide.windows.TopComponent;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30 import org.openide.nodes.Node;
31 import org.openide.loaders.DataObject;
32
33 /** Just a top component which contains AutoCommentPanel
34  * @author phrebejk
35  * @version
36  */

37 public final class AutoCommentTopComponent
38             extends TopComponent
39             implements Externalizable
40 {
41     
42     static final String JavaDoc AUTO_COMMENT_HELP_CTX_KEY = "javadoc.auto.comment"; //NOI18N
43

44     /** The only AutoCommentTopComponent allowed in the system */
45     private static Reference JavaDoc acTopComponent;
46
47     /** The panel contained by acTopComponent */
48     private transient AutoCommentPanel acPanel;
49     
50     static final long serialVersionUID =3696398508351593122L;
51     
52     /** Creates new AutoCommentTopComponent */
53     private AutoCommentTopComponent() {
54         // Force winsys to not show tab when this comp is alone
55
putClientProperty("TabPolicy", "HideWhenAlone"); // NOI18N
56
setLayout( new BorderLayout JavaDoc() );
57         add( acPanel = new AutoCommentPanel(), BorderLayout.CENTER );
58     }
59
60     void setAutoCommenter( AutoCommenter aCommenter ) {
61         acPanel.setAutoCommenter( aCommenter );
62         // Nodes[] nodes = aCommenter.getNodes();
63
Node[] nodes = aCommenter.nodes;
64         String JavaDoc className = null;
65         if (nodes.length > 1 ) {
66             className = NbBundle.getMessage(AutoCommentTopComponent.class, "CTL_AUTOCOMMENT_MultipleSources"); //NOI18N
67
} else if (nodes.length == 1) {
68             DataObject dobj = (DataObject) nodes[0].getLookup().lookup(DataObject.class);
69             if (dobj != null) {
70                 className = dobj.getNodeDelegate().getDisplayName();
71             } else {
72                 className = nodes[0].getDisplayName();
73             }
74         } else {
75             className = ""; //NOI18N
76
}
77         setName(NbBundle.getMessage(AutoCommentTopComponent.class, "CTL_AUTOCOMMENT_WindowTitle") + " - " + className); //NOI18N
78
}
79
80     protected void componentActivated() {
81         super.componentActivated();
82         acPanel.activate();
83     }
84
85     protected void componentDeactivated() {
86         super.componentDeactivated();
87         if (this.isOpened()) {
88             acPanel.deactivate();
89         }
90     }
91
92     protected void componentClosed() {
93         acPanel.deactivate();
94         acPanel.setAutoCommenter(null);
95         super.componentClosed();
96     }
97
98     public int getPersistenceType() {
99         return TopComponent.PERSISTENCE_NEVER;
100     }
101     
102     protected String JavaDoc preferredID() {
103         return "AutoCommentTopComponent"; // NOI18N
104
}
105
106     public static AutoCommentTopComponent getDefault() {
107         AutoCommentTopComponent actp;
108         if (acTopComponent == null || (actp = (AutoCommentTopComponent) acTopComponent.get()) == null) {
109
110             actp = new AutoCommentTopComponent();
111             actp.getAccessibleContext().setAccessibleName(ResourceUtils.getBundledString("ACS_AutoCommentPanelA11yName")); // NOI18N
112
actp.getAccessibleContext().setAccessibleDescription(ResourceUtils.getBundledString("ACS_AutoCommentPanelA11yDesc")); // NOI18N
113
actp.setName(ResourceUtils.getBundledString ("CTL_AUTOCOMMENT_WindowTitle") ); //NOI18N
114
acTopComponent = new SoftReference JavaDoc(actp);
115         } else {
116             actp = (AutoCommentTopComponent) acTopComponent.get();
117         }
118
119         return actp;
120     }
121
122     public HelpCtx getHelpCtx () {
123         return new HelpCtx (AUTO_COMMENT_HELP_CTX_KEY);
124     }
125
126     // Implementation of Externalizable -----------------------------------------
127

128     /** Writes a resolvable */
129     protected Object JavaDoc writeReplace() {
130         return new Resolvable();
131     }
132
133     static class Resolvable implements java.io.Serializable JavaDoc {
134
135         static final long serialVersionUID =8143238035030034549L;
136         private Object JavaDoc readResolve() {
137             AutoCommentTopComponent actp = getDefault();
138             actp.setAutoCommenter( new AutoCommenter());
139             return actp;
140         }
141     }
142 }
143
Popular Tags