2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.welcome;
44
import java.lang.ref.WeakReference;
45
import org.openide.util.NbBundle;
46
import org.openide.windows.*;
49
import org.netbeans.modules.welcome.ui.StartPageContent;
50
import org.openide.ErrorManager;
51
import org.openide.nodes.Node;
55
* @author Richard Gregor, S. Aubrecht
57
public class WelcomeComponent extends TopComponent {
58
static final long serialVersionUID=6021472310161712674L;
59
private static WeakReference<WelcomeComponent> component =
60
new WeakReference<WelcomeComponent>(null);
61
private JComponent content;
63
private boolean initialized = false;
65
private WelcomeComponent(){
66
setLayout(new BorderLayout());
67
setName(NbBundle.getMessage(WelcomeComponent.class, "LBL_Tab_Title")); //NOI18N
70
putClientProperty( "activateAtStartup", Boolean.TRUE ); //NOI18N
73
@Override protected String preferredID(){
74
return "WelcomeComponent"; //NOI18N
78
* #38900 - lazy addition of GUI components
81
private void doInitialize() {
84
if( null == content ) {
85
WelcomeOptions.getDefault().incrementStartCounter();
86
content = new StartPageContent();
88
add( content, BorderLayout.CENTER );
89
setFocusable( false );
93
/* Singleton accessor. As WelcomeComponent is persistent singleton this
94
* accessor makes sure that WelcomeComponent is deserialized by window system.
95
* Uses known unique TopComponent ID "Welcome" to get WelcomeComponent instance
96
* from window system. "Welcome" is name of settings file defined in module layer.
98
public static WelcomeComponent findComp() {
99
WelcomeComponent wc = component.get();
101
TopComponent tc = WindowManager.getDefault().findTopComponent("Welcome"); // NOI18N
103
if (tc instanceof WelcomeComponent) {
104
wc = (WelcomeComponent)tc;
105
component = new WeakReference<WelcomeComponent>(wc);
107
//Incorrect settings file?
108
IllegalStateException exc = new IllegalStateException
109
("Incorrect settings file. Unexpected class returned." // NOI18N
110
+ " Expected:" + WelcomeComponent.class.getName() // NOI18N
111
+ " Returned:" + tc.getClass().getName()); // NOI18N
112
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
113
//Fallback to accessor reserved for window system.
114
wc = WelcomeComponent.createComp();
117
//WelcomeComponent cannot be deserialized
118
//Fallback to accessor reserved for window system.
119
wc = WelcomeComponent.createComp();
125
/* Singleton accessor reserved for window system ONLY. Used by window system to create
126
* WelcomeComponent instance from settings file when method is given. Use <code>findComp</code>
127
* to get correctly deserialized instance of WelcomeComponent. */
128
public static WelcomeComponent createComp() {
129
WelcomeComponent wc = component.get();
131
wc = new WelcomeComponent();
132
component = new WeakReference<WelcomeComponent>(wc);
137
/** Overriden to explicitely set persistence type of WelcomeComponent
138
* to PERSISTENCE_ALWAYS */
139
@Override public int getPersistenceType() {
140
return TopComponent.PERSISTENCE_NEVER;
143
private void initAccessibility(){
144
getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WelcomeComponent.class, "ACS_Welcome_DESC")); // NOI18N
148
* Called when <code>TopComponent</code> is about to be shown.
149
* Shown here means the component is selected or resides in it own cell
150
* in container in its <code>Mode</code>. The container is visible and not minimized.
151
* <p><em>Note:</em> component
152
* is considered to be shown, even its container window
153
* is overlapped by another window.</p>
156
* #38900 - lazy addition of GUI components
159
@Override protected void componentShowing() {
164
if( null != content && getComponentCount() == 0 ) {
165
//notify components down the hierarchy tree that they should
166
//refresh their content (e.g. RSS feeds)
167
add( content, BorderLayout.CENTER );
169
super.componentShowing();
170
setActivatedNodes( new Node[] {} );
173
private static boolean firstTimeOpen = true;
175
protected void componentOpened() {
176
super.componentOpened();
177
if( firstTimeOpen ) {
178
firstTimeOpen = false;
179
if( !WelcomeOptions.getDefault().isShowOnStartup() ) {
185
@Override protected void componentHidden() {
186
super.componentHidden();
187
if( null != content ) {
188
//notify components down the hierarchy tree that they no long
189
//need to periodically refresh their content (e.g. RSS feeds)
195
public void requestFocus() {
196
if( null != content )
197
content.requestFocus();
201
public boolean requestFocusInWindow() {
202
if( null != content )
203
return content.requestFocusInWindow();
204
return super.requestFocusInWindow();