|
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-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.actions; import java.awt.*; import java.awt.event.*; import java.util.Locale; import javax.swing.*; import org.openide.TopManager; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.SystemAction; /** * Shows help for the currently focused component. * * @see HelpCtx#findHelp * @author Jesse Glick * @deprecated Should not be referred to directly. */ public class HelpAction extends SystemAction { private static final long serialVersionUID = 4658008202517094416L; // XXX(-ttran) we need to register AWTEventListener even before HelpAction // is called for the first time. Do it in a static block. Beware that it // wouldn't work if the class is not loaded eargerly static { WindowActivatedDetector.install(); } public String getName() { // Not actually used anymore, so no need for I18N... return "Help"; // NOI18N } public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } protected void initialize () { super.initialize (); // Cf. org.netbeans.core.windows.frames.NbFocusManager and // org.netbeans.core.windows.frames.ShortcutAndMenuKeyEventProcessor putProperty ("OpenIDE-Transmodal-Action", Boolean.TRUE); // NOI18N } private static class WindowActivatedDetector implements AWTEventListener { private static java.lang.ref.WeakReference currentWindowRef; private static boolean installed; static synchronized void install() { if (installed) return; installed = true; Toolkit.getDefaultToolkit ().addAWTEventListener( new WindowActivatedDetector(), AWTEvent.WINDOW_EVENT_MASK); } static synchronized Window getCurrentActivatedWindow() { if (currentWindowRef != null) { return (Window) currentWindowRef.get(); } else { return null; } } private static synchronized void setCurrentActivatedWindow(Window w) { currentWindowRef = new java.lang.ref.WeakReference(w); } public void eventDispatched (AWTEvent ev) { if (ev.getID() != WindowEvent.WINDOW_ACTIVATED) return; setCurrentActivatedWindow(((WindowEvent) ev).getWindow()); } } private static HelpCtx findHelpCtx() { Window w = WindowActivatedDetector.getCurrentActivatedWindow(); Component focused = (w != null) ? SwingUtilities.findFocusOwner(w) : null; HelpCtx help = (focused == null) ? HelpCtx.DEFAULT_HELP : HelpCtx.findHelp(focused); return help; } public void actionPerformed (ActionEvent ev) { HelpCtx help; final MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); if (path != null && path.length > 0 && !(path[0].getComponent() instanceof javax.swing.plaf.basic.ComboPopup) ) { help = HelpCtx.findHelp(path[path.length - 1].getComponent()); SwingUtilities.invokeLater(new Runnable() { public void run() { MenuElement[] newPath = MenuSelectionManager.defaultManager().getSelectedPath(); if (newPath.length != path.length) return; for (int i = 0; i < newPath.length; i++) { if (newPath[i] != path[i]) return; } MenuSelectionManager.defaultManager().clearSelectedPath(); } }); } else { help = findHelpCtx(); } TopManager.getDefault().setStatusText(NbBundle.getBundle("org.openide.deprecated.Bundle", Locale.getDefault(), StepOutAction.class.getClassLoader()).getString("CTL_OpeningHelp")); TopManager.getDefault().showHelp(help); TopManager.getDefault().setStatusText(""); // NOI18N } } |
... 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.