|
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.core.deprecated; import java.beans.*; import java.beans.beancontext.*; import java.util.*; import org.openide.*; import org.openide.loaders.*; import org.openide.options.*; import org.openide.actions.*; import org.openide.util.HelpCtx; import org.openide.util.actions.*; import org.openide.nodes.*; import org.openide.util.Lookup; import org.openide.util.NbBundle; /** This object represents all system options stored in ControlPanel. * * @author Petr Hamernik, Jaroslav Tulach, Dafe Simonek */ public class ControlPanelNode extends AbstractNode { /** generated Serialized Version UID */ static final long serialVersionUID = 472235064406221888L; /** default instance */ private static Node controlPanel; /** default project setggins */ private static Node projectSettings; /** used during deserialization */ // private transient Node[] ret; private boolean asProjectSettings; /** Default no-arg constructor */ public ControlPanelNode () { this (true); } private ControlPanelNode (boolean asProjectSettings) { super (new ControlPanelChildren ( (ControlPanel)Lookup.getDefault ().lookup (ControlPanel.class), asProjectSettings )); this.asProjectSettings = asProjectSettings; getCookieSet ().add (new InstanceSupport.Instance (Lookup.getDefault().lookup(ControlPanel.class))); if (asProjectSettings) { setName (NbBundle.getMessage(ControlPanelNode.class, "CTL_Project_Settings")); setShortDescription (NbBundle.getMessage(ControlPanelNode.class, "CTL_Project_Settings_Hint")); } else { setName (NbBundle.getMessage (ControlPanelNode.class, "CTL_ControlPanel")); } } /** Default instance of the node. * @return the node */ public static synchronized Node getDefault () { if (controlPanel == null) { controlPanel = new ControlPanelNode (false); } return controlPanel; } /** Getter for project settings. */ public static synchronized Node getProjectSettings () { if (projectSettings == null) { projectSettings = new ControlPanelNode (true); } return projectSettings; } public HelpCtx getHelpCtx () { return new HelpCtx (ControlPanelNode.class); } /** Getter for set of actions that should be present in the * popup menu of this node. This set is used in construction of * menu returned from getContextMenu and specially when a menu for * more nodes is constructed. * * @return array of system actions that should be in popup menu */ public SystemAction[] createActions () { return new SystemAction[] { SystemAction.get(ToolsAction.class), SystemAction.get(PropertiesAction.class), }; } /** @return a Node.Handle */ public Node.Handle getHandle() { return new Han (! asProjectSettings); } /***** Inner classes **************/ private static final class Han implements Node.Handle { private boolean def; static final long serialVersionUID =-2211277830988549398L; /** Constructor. */ public Han (boolean def) { this.def = def; } public Node getNode () { return def ? getDefault () : getProjectSettings (); } } /** Node representing one option in Control Panel*/ private static class ControlPanelItemNode extends BeanNode { /** * Constructs BeanNode for the bean. * * @param option system option for which we can construct BeanNode * (might not in fact be of type SystemOption... cf. CORBA module) */ public ControlPanelItemNode(Object option) throws IntrospectionException { super(option, getChildren (option)); } // Make sure to use ControlPanelItemNode recursively so as to disable deletion etc.: private static BeanChildren.Factory factory = null; private static synchronized BeanChildren.Factory getFactory () { if (factory == null) { factory = new BeanChildren.Factory () { public Node createNode (Object bean) throws IntrospectionException { return new ControlPanelItemNode (bean); } }; } return factory; } // Copied with modifications from BeanNode: private static Children getChildren (Object option) { if (option instanceof BeanContext) return new BeanChildren ((BeanContext) option, getFactory ()); if (option instanceof BeanContextProxy) { BeanContextChild bch = ((BeanContextProxy) option).getBeanContextProxy (); if (bch instanceof BeanContext) return new BeanChildren ((BeanContext) bch, getFactory ()); } return Children.LEAF; } /** Cannot be removed */ public boolean canDestroy () { return false; } /** Cannot be cut */ public boolean canCut () { return false; } public Node cloneNode () { try { return new ControlPanelItemNode (getBean ()); } catch (IntrospectionException e) { return super.cloneNode (); } } } // end of ControlPanelItemNode /** Implementation of children for ControlPanel node in explorer. * Extends Children.Map implementation to easily achieve nodes to options mapping. * This class listens on changes of underlying options and add or * remove nodes if appropriate. * * @author Dafe Simonek * @version 1.00, Oct 26, 1998 */ private static final class ControlPanelChildren extends Children.Keys implements java.util.Comparator { /** Reference to system option pool */ private ControlPanel options; private boolean asProjectSettings; private boolean isFirstCall = true; /** The only constructor. Non-public, called from ControlPanelNode. * Allows for different data representation through Map param. */ ControlPanelChildren (final ControlPanel options, boolean asProjectSettings) { this.options = options; this.asProjectSettings = asProjectSettings; setBefore (true); } private void initProjectSettings() { isFirstCall = false; Places places = (Places)Lookup.getDefault ().lookup (Places.class); Places.Nodes ns = places.nodes (); add (new Node[] { }); } /** Added into list */ protected void addNotify () { if (isFirstCall && asProjectSettings) initProjectSettings(); } /** Create default node array for options taken from NbControlPanel * Overrides abstract initMap from Children.Map class. */ protected Node[] createNodes (Object key) { return new Node[] { }; } /** Comparator of objects */ public int compare(Object oi, Object oj) { if (oi == oj) return 0; if (oi instanceof Node) return -1; if (oj instanceof Node) return 1; String namei = ((SystemOption) oi).displayName(); String namej = ((SystemOption) oj).displayName(); return namei.compareTo(namej); } } // end of ControlPanelChildren } |
... 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.