|
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.editor;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.JTextComponent;
import javax.swing.text.Keymap;
import org.netbeans.editor.BaseKit;
import org.netbeans.editor.Registry;
import org.netbeans.editor.Settings;
import org.netbeans.editor.SettingsNames;
import org.netbeans.editor.Utilities;
import org.netbeans.editor.ext.ExtKit;
import org.netbeans.modules.editor.java.JavaKit;
import org.netbeans.modules.editor.options.BaseOptions;
import org.openide.awt.Mnemonics;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.Presenter;
/**
* Main menu action, like Edit/Go to Source, Edit/Go to Line...,
* View/Show Editor Toolbar, View/Show Line Numbers
* This is the action implements Presenter.Menu and delegates on specific actions like
* ExtKit.toggleToolbarAction or JavaKit.gotoSuperImplementationAction
*
* @author Martin Roskanin
*/
public abstract class MainMenuAction extends GlobalContextAction implements Presenter.Menu, ChangeListener {
public static final Icon BLANK_ICON = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/editor/resources/empty.gif"));
/** Creates a new instance of ShowLineNumbersAction */
public MainMenuAction() {
// needs to listen on Registry - resultChanged event is fired before
// TopComponent is really focused - this causes problems in getComponent method
Registry.addChangeListener(this);
}
public void resultChanged(org.openide.util.LookupEvent ev){
setMenu();
}
public void stateChanged(ChangeEvent e) {
setMenu();
}
public org.openide.util.HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
public String getName() {
return "";
}
/** Returns focused editor component */
private static JTextComponent getComponent(){
return Utilities.getFocusedComponent();
}
/** Returns the action by given name */
private static Action getActionByName(String actionName){
BaseKit bKit = getKit();
if (bKit!=null){
Action action = bKit.getActionByName(actionName);
return action;
}
return null;
}
/** Adds accelerators to given JMenuItem taken from the action */
protected static void addAccelerators(Action a, JMenuItem item, JTextComponent target){
if (target == null || a==null || item==null) return;
// get accelerators from kitAction
Action kitAction = getActionByName((String)a.getValue(Action.NAME));
if (kitAction!=null) a = kitAction;
// Try to get the accelerator, TopComponent action could be obsoleted
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
item.setAccelerator(keys[0]);
}else{
item.setAccelerator(null);
}
}
}
/** Gets the editor kit */
private static BaseKit getKit(){
JTextComponent component = getComponent();
return (component == null) ? null : Utilities.getKit(component);
}
public boolean isEnabled() {
return false;
}
private static Object getSettingValue(BaseKit kit, String settingName) {
return Settings.getValue(kit.getClass(), settingName);
}
/** Get the value of the boolean setting from the
|
... 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.