本文整理汇总了Java中javax.swing.JComponent.getActionMap方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.getActionMap方法的具体用法?Java JComponent.getActionMap怎么用?Java JComponent.getActionMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.getActionMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exchangeCommands
import javax.swing.JComponent; //导入方法依赖的package包/类
private static void exchangeCommands(String[][] commandsToExchange,
final JComponent target, final JComponent source) {
InputMap targetBindings = target.getInputMap();
KeyStroke[] targetBindingKeys = targetBindings.allKeys();
ActionMap targetActions = target.getActionMap();
InputMap sourceBindings = source.getInputMap();
ActionMap sourceActions = source.getActionMap();
for (int i = 0; i < commandsToExchange.length; i++) {
String commandFrom = commandsToExchange[i][0];
String commandTo = commandsToExchange[i][1];
final Action orig = targetActions.get(commandTo);
if (orig == null) {
continue;
}
sourceActions.put(commandTo, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
orig.actionPerformed(new ActionEvent(target, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
}
});
for (int j = 0; j < targetBindingKeys.length; j++) {
if (targetBindings.get(targetBindingKeys[j]).equals(commandFrom)) {
sourceBindings.put(targetBindingKeys[j], commandTo);
}
}
}
}
示例2: registerComponent
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Registers a component for tooltip management.
* <p>
* This will register key bindings to show and hide the tooltip text
* only if <code>component</code> has focus bindings. This is done
* so that components that are not normally focus traversable, such
* as <code>JLabel</code>, are not made focus traversable as a result
* of invoking this method.
*
* @param component a <code>JComponent</code> object to add
* @see JComponent#isFocusTraversable
*/
protected void registerComponent(JComponent component) {
component.removeMouseListener(this);
component.addMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);
if (shouldRegisterBindings(component)) {
// register our accessibility keybindings for this component
// this will apply globally across L&F
// Post Tip: Ctrl+F1
// Unpost Tip: Esc and Ctrl+F1
InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
ActionMap actionMap = component.getActionMap();
if (inputMap != null && actionMap != null) {
//XXX remove
}
}
}
示例3: registerAccelerators
import javax.swing.JComponent; //导入方法依赖的package包/类
private static void registerAccelerators(JComponent component, Action... actions) {
InputMap inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap actionMap = component.getActionMap();
for (Action action : actions) {
inputMap.put((KeyStroke)action.getValue(Action.ACCELERATOR_KEY), action);
actionMap.put(action, action);
}
}
示例4: unregisterComponent
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Removes a component from tooltip control.
*
* @param component a <code>JComponent</code> object to remove
*/
protected void unregisterComponent(JComponent component) {
component.removeMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);
if (shouldRegisterBindings(component)) {
InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
ActionMap actionMap = component.getActionMap();
if (inputMap != null && actionMap != null) {
//XXX remove
}
}
}
示例5: setupKeymap
import javax.swing.JComponent; //导入方法依赖的package包/类
private void setupKeymap(Set<Action> actions) {
JComponent comp = term.getScreen();
ActionMap actionMap = comp.getActionMap();
ActionMap newActionMap = new ActionMap();
newActionMap.setParent(actionMap);
printActionMap(actionMap);
InputMap inputMap = comp.getInputMap();
InputMap newInputMap = new InputMap();
newInputMap.setParent(inputMap);
Set<KeyStroke> passKeystrokes = new HashSet<KeyStroke>();
for (Action a : actions) {
String name = (String) a.getValue(Action.NAME);
KeyStroke accelerator = (KeyStroke) a.getValue(Action.ACCELERATOR_KEY);
System.out.printf("Registering %s for %s\n", accelerator, name);
if (accelerator == null)
continue;
newInputMap.put(accelerator, name);
newActionMap.put(name, a);
passKeystrokes.add(accelerator);
}
comp.setActionMap(newActionMap);
comp.setInputMap(JComponent.WHEN_FOCUSED, newInputMap);
term.setKeyStrokeSet((HashSet) passKeystrokes);
}
示例6: get
import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public Action get(Object key) {
ActionMap m;
if (delegate == null) {
JComponent comp = getComponent();
if (comp == null) {
m = null;
} else {
m = comp.getActionMap();
}
} else {
m = delegate;
}
if (m != null) {
Action a = m.get(key);
if (a != null) {
return a;
}
}
Component owner = GlobalActionContextImpl.findFocusOwner();
Action found = null;
while ((owner != null) && (owner != getComponent())) {
if ((found == null) && (owner instanceof JComponent)) {
m = ((JComponent) owner).getActionMap();
if (m != null) {
found = m.get(key);
}
}
owner = owner.getParent();
}
return (owner == getComponent()) ? found : null;
}
示例7: addToActionMap
import javax.swing.JComponent; //导入方法依赖的package包/类
public static void addToActionMap(JComponent component) {
ActionMap actionMap = component.getActionMap();
actionMap.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
actionMap.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
actionMap.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
actionMap.put(DeleteOperatorAction.getActionName(), new DeleteOperatorAction());
// only required if you have not set the menu accelerators
InputMap inputMap = component.getInputMap();
inputMap.put(KeyStroke.getKeyStroke("ctrl X"), TransferHandler.getCutAction().getValue(Action.NAME));
inputMap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME));
inputMap.put(KeyStroke.getKeyStroke("ctrl V"), TransferHandler.getPasteAction().getValue(Action.NAME));
inputMap.put(KeyStroke.getKeyStroke("del"), DeleteOperatorAction.getActionName());
}
示例8: addAccelerator
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Adds the accelerator key for a given action to the action and input maps
* of the simulator frame's content pane.
* @param action the action to be added
* @require <tt>frame.getContentPane()</tt> should be initialised
*/
public void addAccelerator(Action action) {
JComponent contentPane = (JComponent) getFrame().getContentPane();
ActionMap am = contentPane.getActionMap();
am.put(action.getValue(Action.NAME), action);
InputMap im = contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.NAME));
}
示例9: playSound
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Helper method to play a named sound.
*
* @param c JComponent to play the sound for.
* @param actionKey Key for the sound.
*/
static void playSound(JComponent c, Object actionKey) {
LookAndFeel laf = UIManager.getLookAndFeel();
if (laf instanceof BasicLookAndFeel) {
ActionMap map = c.getActionMap();
if (map != null) {
Action audioAction = map.get(actionKey);
if (audioAction != null) {
// pass off firing the Action to a utility method
((BasicLookAndFeel)laf).playSound(audioAction);
}
}
}
}
示例10: zoomMenuCommands
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Adds support for plus and minus menu commands, typically for zooming in
* and out. This is designed for menu items with key accelerators using
* KeyEvent.VK_ADD and KeyEvent.VK_SUBTRACT (which are typically on the
* numerical key pad). It adds support for KeyEvent.VK_MINUS and
* KeyEvent.VK_PLUS, and KeyEvent.VK_EQUALS for keyboard layouts with the
* plus sign as secondary key for the equals.
*
* @param zoomInAction action to call when the + key and the menu shortcut
* key are pressed
* @param zoomOutAction action to call when the - key and the menu shortcut
* key are pressed
* @param component component that will receive events and store actions
*/
public static void zoomMenuCommands(Action zoomInAction, Action zoomOutAction, JComponent component) {
InputMap inputMap = component.getInputMap();
ActionMap actionMap = component.getActionMap();
zoomMenuCommands(inputMap, actionMap, zoomInAction, zoomOutAction);
}