KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > BluePrintsComponent


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.j2ee.blueprints;
21
22 import java.lang.ref.WeakReference JavaDoc;
23 import org.openide.util.NbBundle;
24 import org.openide.*;
25 import org.openide.windows.*;
26
27 import java.io.*;
28 import java.awt.*;
29 import java.lang.reflect.Method JavaDoc;
30 import javax.swing.*;
31 import javax.accessibility.*;
32 import org.openide.ErrorManager;
33
34 /**
35  * The BluePrints screen.
36  * @author Ludo
37  */

38 class BluePrintsComponent extends TopComponent{
39     static final long serialVersionUID=6021472310161712674L;
40
41     private static WeakReference JavaDoc/*<BluePrintsComponent>*/ component =
42             new WeakReference JavaDoc(null);
43         
44     private JComponent panel;
45
46     private boolean initialized = false;
47     
48     private BluePrintsComponent(){
49         setLayout(new BorderLayout());
50         setName(NbBundle.getMessage(BluePrintsComponent.class, "LBL_Tab_Title")); //NOI18N
51
panel = null;
52         initialized = false;
53     }
54     
55     protected String JavaDoc preferredID(){
56         return "BluePrints"; //NOI18N
57
}
58     
59     /**
60      * #38900 - lazy addition of GUI components
61      */

62     
63     private void doInitialize() {
64         initAccessibility();
65         
66         try{
67             ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
68             panel =(JComponent)Class.forName(NbBundle.getMessage(
69                   BluePrintsComponent.class,"CLASS_content_panel"), true, cl).newInstance();
70             //panel =(JComponent)Class.forName(NbBundle.getMessage(BluePrintsComponent.class,"CLASS_content_panel")).newInstance();
71
}catch(Exception JavaDoc e){
72             ErrorManager.getDefault().notify(e);
73         }
74         if(panel == null)
75             return;
76
77         // Removed code that added scrollbars - we do not want them here.
78
add(panel);
79         setFocusable(true);
80     }
81         
82     /* Singleton accessor. As BluePrintsComponent is persistent singleton this
83      * accessor makes sure that BluePrintsComponent is deserialized by window system.
84      * Uses known unique TopComponent ID "BluePrints" to get BluePrintsComponent instance
85      * from window system. "BluePrints" is name of settings file defined in module layer.
86      */

87     public static BluePrintsComponent findComp() {
88         BluePrintsComponent wc = (BluePrintsComponent)component.get();
89         if (wc == null) {
90             TopComponent tc = WindowManager.getDefault().findTopComponent("BluePrints"); // NOI18N
91
if (tc != null) {
92                 if (tc instanceof BluePrintsComponent) {
93                     wc = (BluePrintsComponent)tc;
94                     component = new WeakReference JavaDoc(wc);
95                 } else {
96                     //Incorrect settings file?
97
IllegalStateException JavaDoc exc = new IllegalStateException JavaDoc
98                     ("Incorrect settings file. Unexpected class returned." // NOI18N
99
+ " Expected:" + BluePrintsComponent.class.getName() // NOI18N
100
+ " Returned:" + tc.getClass().getName()); // NOI18N
101
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
102                     //Fallback to accessor reserved for window system.
103
wc = BluePrintsComponent.createComp();
104                 }
105             } else {
106                 //BluePrintsComponent cannot be deserialized
107
//Fallback to accessor reserved for window system.
108
wc = BluePrintsComponent.createComp();
109             }
110         }
111         return wc;
112     }
113     
114     /* Singleton accessor reserved for window system ONLY. Used by window system to create
115      * BluePrintsComponent instance from settings file when method is given. Use <code>findComp</code>
116      * to get correctly deserialized instance of BluePrintsComponent. */

117     public static BluePrintsComponent createComp() {
118         BluePrintsComponent wc = (BluePrintsComponent)component.get();
119         if(wc == null) {
120             wc = new BluePrintsComponent();
121             component = new WeakReference JavaDoc(wc);
122         }
123         return wc;
124     }
125     
126     /** Overriden to explicitely set persistence type of BluePrintsComponent
127      * to PERSISTENCE_ALWAYS */

128     public int getPersistenceType() {
129         return TopComponent.PERSISTENCE_ALWAYS;
130     }
131     
132     static void clearRef(){
133         component.clear();
134     }
135     
136     private void initAccessibility(){
137         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BluePrintsComponent.class, "ACS_BluePrints_DESC")); // NOI18N
138
}
139     
140     public void requestFocus(){
141         super.requestFocus();
142         panel.requestFocus();
143     }
144     
145     /**
146      * #38900 - lazy addition of GUI components
147      */

148     public void addNotify() {
149         if (!initialized) {
150             initialized = true;
151             doInitialize();
152         }
153         super.addNotify();
154     }
155     
156     /**
157      * Called when <code>TopComponent</code> is about to be shown.
158      * Shown here means the component is selected or resides in it own cell
159      * in container in its <code>Mode</code>. The container is visible and not minimized.
160      * <p><em>Note:</em> component
161      * is considered to be shown, even its container window
162      * is overlapped by another window.</p>
163      * @since 2.18
164      *
165      * #38900 - lazy addition of GUI components
166      *
167      */

168     protected void componentShowing() {
169         if (!initialized) {
170             initialized = true;
171             doInitialize();
172         }
173         super.componentShowing();
174     }
175     
176 }
177
178
Popular Tags