|
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.form.palette; import java.awt.BorderLayout; import java.awt.Dimension; import org.openide.ErrorManager; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.openide.awt.UndoRedo; import org.openide.util.Utilities; /** * Top component which displays component palette. * * @author Jan Rojcek */ public class PaletteTopComponent extends TopComponent { static final long serialVersionUID = 4248268998485315735L; private static PaletteTopComponent instance; /** Creates new PaletteTopComponent */ private PaletteTopComponent() { setName(CPManager.getBundle().getString("CTL_Component_palette")); // NOI18N setToolTipText(CPManager.getBundle().getString("HINT_PaletteComponent")); setIcon(Utilities.loadImage("org/netbeans/modules/form/resources/palette.png")); // NOI18N } public void addNotify() { // XXX(-ttran) this is optimization for startup performance of the IDE. // It would not be needed if there was not the performance bug // #18039 in the window system. Once that bug is fixed we can move this // piece of code back to the constructor where it should be setLayout(new BorderLayout()); setPreferredSize(new Dimension(505, 88)); add(CPManager.getDefault().getPalette()); super.addNotify(); } public boolean requestFocusInWindow() { super.requestFocusInWindow(); return CPManager.getDefault().getPalette().requestFocusInWindow(); } /** Gets default instance. Don't use directly, it reserved for '.settings' file only, * i.e. deserialization routines, otherwise you can get non-deserialized instance. */ public static synchronized PaletteTopComponent getDefault() { if(instance == null) { instance = new PaletteTopComponent(); } return instance; } /** Finds default instance. Use in client code instead of {@link #getDefault()}. */ public static synchronized PaletteTopComponent getInstance() { if(instance == null) { TopComponent tc = WindowManager.getDefault().findTopComponent("ComponentPalette"); // NOI18N if(instance == null) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new IllegalStateException( "Can not find ComponentPalette component for its ID. Returned " + tc)); // NOI18N instance = new PaletteTopComponent(); } } return instance; } /** Overriden to explicitely set persistence type of PaletteTopComponent * to PERSISTENCE_ALWAYS */ public int getPersistenceType() { return TopComponent.PERSISTENCE_ALWAYS; } protected void componentClose() { // palette is closed so set mode of designer to selection CPManager.getDefault().setSelectedItem(null); } public UndoRedo getUndoRedo() { return org.netbeans.modules.form.ComponentInspector.getInstance().getUndoRedo(); } // public void requestFocus() { // super.requestFocus(); // if (CPManager.getDefault().getComponent() != null) // CPManager.getDefault().getComponent().requestFocus(); // } /** replaces this in object stream */ public Object writeReplace() { return new ResolvableHelper(); } protected String preferredID() { return getClass().getName(); } final public static class ResolvableHelper implements java.io.Serializable { static final long serialVersionUID = 7424646018839457793L; public Object readResolve() { return PaletteTopComponent.getDefault(); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.