|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.examplemodule02;
import org.openide.ErrorManager;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import java.awt.BorderLayout;
import javax.swing.JButton;
/**
*
* @author Marek Slama
*/
class TestComponent00 extends TopComponent {
static final long serialVersionUID = 6021472310161712674L;
private static TestComponent00 component = null;
private JButton button;
private TestComponent00() {
setLayout(new BorderLayout());
setName(NbBundle.getMessage(TestComponent00.class, "LBL_Tab_Title00"));
button = new JButton(getName());
add(button);
}
/* Singleton accessor. As TestComponent00 is persistent singleton this
* accessor makes sure that TestComponent00 is deserialized by window system.
* Uses known unique TopComponent ID "test02tc00" to get TestComponent00 instance
* from window system. "test02tc00" is name of settings file defined in module layer.
* For example ShowTestAction00 uses this method to create instance if necessary.
*/
public static synchronized TestComponent00 findDefault() {
if (component == null) {
//If settings file is correctly defined call of WindowManager.findTopComponent() will
//call TestComponent00.getDefault() and it will set static field component.
TopComponent tc = WindowManager.getDefault().findTopComponent("test02tc00"); // NOI18N
if (tc != null) {
if (!(tc instanceof TestComponent00)) {
//This should not happen. Possible only if some other module
//defines different settings file with the same name but different class.
//Incorrect settings file?
IllegalStateException exc = new IllegalStateException
("Incorrect settings file. Unexpected class returned." // NOI18N
+ " Expected:" + TestComponent00.class.getName() // NOI18N
+ " Returned:" + tc.getClass().getName()); // NOI18N
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
//Fallback to accessor reserved for window system.
TestComponent00.getDefault();
}
} else {
//This should not happen when settings file is correctly defined in module layer.
//TestComponent00 cannot be deserialized
//Fallback to accessor reserved for window system.
TestComponent00.getDefault();
}
}
return component;
}
/* Singleton accessor reserved for window system ONLY. Used by window system to create
* TestComponent00 instance from settings file when method is given. Use
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.