javax.swing

Class ActionMap

Implemented Interfaces:
Serializable
Known Direct Subclasses:
ActionMapUIResource

public class ActionMap
extends Object
implements Serializable

ActionMap provides mappings from Objects (called keys or Action names) to Actions. An ActionMap is usually used with an InputMap to locate a particular action when a key is pressed. As with InputMap, an ActionMap can have a parent that is searched for keys not defined in the ActionMap.

As with InputMap if you create a cycle, eg:

   ActionMap am = new ActionMap();
   ActionMap bm = new ActionMap():
   am.setParent(bm);
   bm.setParent(am);
 
some of the methods will cause a StackOverflowError to be thrown.
See Also:
InputMap, Serialized Form

Constructor Summary

ActionMap()
Creates an ActionMap with no parent and no mappings.

Method Summary

Object[]
allKeys()
Returns an array of the keys defined in this ActionMap and its parent.
void
clear()
Removes all the mappings from this ActionMap.
Action
get(Object key)
Returns the binding for key, messaging the parent ActionMap if the binding is not locally defined.
ActionMap
getParent()
Returns this ActionMap's parent.
Object[]
keys()
Returns the Action names that are bound in this ActionMap.
void
put(Object key, Action action)
Adds a binding for key to action.
void
remove(Object key)
Removes the binding for key from this ActionMap.
void
setParent(ActionMap map)
Sets this ActionMap's parent.
int
size()
Returns the number of KeyStroke bindings.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

ActionMap

public ActionMap()
Creates an ActionMap with no parent and no mappings.
Usages and Demos :

View More Examples of ActionMap()
   1:     public ActionMap createActionMap(JComponent component) {
   2:         ActionMap map = new ActionMap();
   3:         String[] keys = getKeys();
   4:         for (int i = 0; i < keys.length; i++) {
   5:             if (keys[i] != null) {

View Full Code Here
   1:     
   2:     ActionMap am = new ActionMap();
   3:     am.setParent(getActionMap());
   4:     am.put("Copy", TransferHandler.getCopyAction());
   5:     setActionMap(am);

View Full Code Here
   1: 
   2:     _actionMap = new ActionMap();
   3:     _model = new DefaultGraphModel();
   4:         ...
   5:   {
   6:     _actionMap = new ActionMap();
   7: 
   8:     _model = new DefaultGraphModel();
   9:     _graph = new FsaGraph(_model);

View Full Code Here
   1:     
   2:     private ActionMap   m_actionMap = new ActionMap();
   3: 
   4:     private JButton     m_savedDefaultButton;
   5:     

View Full Code Here
   1:     Action[] actions = textComponent.getActions();
   2:     ActionMap am = new ActionMap();
   3:     for (int i = 0; i < actions.length; ++i)
   4:       {
   5:         String name = (String) actions[i].getValue(Action.NAME);

View Full Code Here

Method Details

allKeys

public Object[] allKeys()
Returns an array of the keys defined in this ActionMap and its parent. This method differs from keys() in that this method includes the keys defined in the parent.
Usages and Demos :

View More Examples of allKeys()
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5: 
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7: 
   8:         ...
   9:         Object[] keys;
  10:         keys = defaultActionMap.allKeys();
  11:         for (int i = 0; i < keys.length; i++) {
  12:         ...
  13: 
  14:         keys = currentActionMap.allKeys();

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5:     
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7:     
   8:         ...
   9:         Object[] keys;
  10:         keys = defaultActionMap.allKeys();
  11:         for (int i = 0; i < keys.length; i++) {
  12:         ...
  13:         
  14:         keys = currentActionMap.allKeys();

View Full Code Here

clear

public void clear()
Removes all the mappings from this ActionMap.

get

public Action get(Object key)
Returns the binding for key, messaging the parent ActionMap if the binding is not locally defined.
Usages and Demos :

View More Examples of get(Object key)
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.JButton;
   4:         ...
   5:     
   6:     private ActionMap   m_actionMap = new ActionMap();
   7: 
   8:         ...
   9:         return new Action[] {
  10:             m_actionMap.get(IWizardPage.MOVE_NEXT_COMMAND),
  11:         ...
  12:             m_actionMap.get(IWizardPage.MOVE_PREVIOUS_COMMAND),

View Full Code Here
   1: import javax.swing.AbstractAction;
   2: import javax.swing.ActionMap;
   3: import javax.swing.InputMap;
   4:         ...
   5:     protected void installActions() {
   6:         ActionMap actionMap = getActionMap();
   7: 
   8:         ...
   9: 
  10:         actionMap.get(SCROLL_RIGHT_ACTION)     .setEnabled(!b);
  11:         ...
  12:         actionMap.get(SCROLL_LEFT_ACTION)      .setEnabled(!b);

View Full Code Here

getParent

public ActionMap getParent()
Returns this ActionMap's parent.
Returns:
the ActionMap that is the parent of this one, or null if this ActionMap has no parent

keys

public Object[] keys()
Returns the Action names that are bound in this ActionMap.
Usages and Demos :

View More Examples of keys()
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5: 
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7: 
   8:         ...
   9: 
  10:         Object[] keys = currentActionMap.keys();
  11:         for (int i = 0; i < keys.length; i++) {
  12:         ...
  13: 
  14:         keys = defaultActionMap.keys();

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5:     
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7:     
   8:         ...
   9:         
  10:         Object[] keys = currentActionMap.keys();
  11:         for (int i = 0; i < keys.length; i++) {
  12:         ...
  13:         
  14:         keys = defaultActionMap.keys();

View Full Code Here

put

public void put(Object key,
                Action action)
Adds a binding for key to action. If action is null, this removes the current binding for key.

In most instances, key will be action.getValue(NAME).

Usages and Demos :

View More Examples of put(Object key,Action action)
   1:     im.setParent(getInputMap(WHEN_FOCUSED));
   2:     im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK),
   3:            "Copy");
   4:         ...
   5:     
   6:     ActionMap am = new ActionMap();
   7:     am.setParent(getActionMap());
   8:         ...
   9:     am.put("Copy", TransferHandler.getCopyAction());
  10:     setActionMap(am);

View Full Code Here
   1:         InputMap inputMap = viewport.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
   2:         ActionMap actionMap = viewport.getActionMap();
   3: 
   4:         ...
   5:         KeyStroke upKey = KeyStroke.getKeyStroke("UP");
   6:         inputMap.put(upKey, "up");
   7:         ...
   8:         actionMap.put("up", upKeyAction);
   9: 
  10:         ...
  11:         KeyStroke downKey = KeyStroke.getKeyStroke("DOWN");
  12:         inputMap.put(downKey, "down");

View Full Code Here
   1:       (JComponent.WHEN_IN_FOCUSED_WINDOW);
   2:     ActionMap actionMap=cancelButton.getActionMap();
   3:         ...
   4:     if(inputMap!=null && actionMap!=null)
   5:     {
   6:         ...
   7:       inputMap.put(cancelKeyStroke,"cancel");
   8:         ...
   9:       actionMap.put("cancel",cancelKeyAction);

View Full Code Here
   1:     InputMap inmap = getInputMap(WHEN_IN_FOCUSED_WINDOW);
   2:     inmap.put(getKS(KeyEvent.VK_LEFT, true), "GBSelectLeft");
   3:         ...
   4:     inmap.put(getKS(KeyEvent.VK_RIGHT, true), "GBSelectRight");
   5:         ...
   6:     inmap.put(getKS(KeyEvent.VK_ESCAPE, false), "GBStop");
   7:         ...
   8:     ActionMap actmap = getActionMap();

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.DefaultCellEditor;
   4:         ...
   5:         InputMap inputMap = getInputMap();
   6:         ActionMap actionMap = getActionMap();
   7: 
   8:         ...
   9:         KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
  10:         inputMap.put(keyStroke, "DELETE_SELECTED_ROWS");
  11:         ...
  12:         actionMap.put("DELETE_SELECTED_ROWS", getDeleteAction());

View Full Code Here

remove

public void remove(Object key)
Removes the binding for key from this ActionMap.
Usages and Demos :

View More Examples of remove(Object key)
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.InputMap;
   4:         ...
   5:         InputMap im = component.getInputMap(m_condition);
   6:         ActionMap am = component.getActionMap();
   7:         for (Entry e : m_entries) {
   8:         ...
   9:         InputMap im = component.getInputMap(m_condition);
  10:         ActionMap am = component.getActionMap();
  11:         for (Entry e : m_entries) {
  12:         ...
  13:         public void remove(InputMap im, ActionMap am) {
  14:             im.remove(m_keyStroke);

View Full Code Here
   1: import java.beans.PropertyChangeListener;
   2: import javax.swing.ActionMap;
   3: import javax.swing.JComponent;
   4:         ...
   5:         super.installKeyboardActions();
   6:         ActionMap map = SwingUtilities.getUIActionMap(frame);
   7:         if (map != null)
   8:         ...
   9:         {
  10:             map.remove("showSystemMenu");
  11:         }

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.InputMap;
   4:         ...
   5:     private InputMap            m_inputMap;
   6:     private ActionMap           m_actionMap;
   7: 
   8:         ...
   9:          if (m_inputMap != null) {
  10:              m_inputMap.remove(KeyUtils.UNDO);
  11:         ...
  12:              m_inputMap.remove(KeyUtils.REDO);

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5:     
   6:     private void cleanupPaneActions(ActionMap map) {
   7:         if(map == null)
   8:         ...
   9:                name.equals("unitScrollRight")) {
  10:                 map.remove(keys[i]);
  11:                 if(map.get(keys[i]) != null)

View Full Code Here
   1: 
   2: import javax.swing.ActionMap;
   3: import javax.swing.DefaultComboBoxModel;
   4:         ...
   5:     protected void initActions() {
   6:         ActionMap map = getActionMap();
   7:         map.put(ACTION_FIND, new Actions(ACTION_FIND));
   8:         ...
   9:             } else if (ACTION_CUT.equals(name)) {
  10:                 ActionMap map = getActionMap();
  11:         ...
  12:                 map.remove(ACTION_CUT);

View Full Code Here

setParent

public void setParent(ActionMap map)
Sets this ActionMap's parent.
Parameters:
map - the ActionMap that is the parent of this one
Usages and Demos :

View More Examples of setParent(ActionMap map)
   1:     InputMap im = new InputMap();
   2:     im.setParent(getInputMap(WHEN_FOCUSED));
   3:     im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK),
   4:         ...
   5:     
   6:     ActionMap am = new ActionMap();
   7:         ...
   8:     am.setParent(getActionMap());
   9:     am.put("Copy", TransferHandler.getCopyAction());

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5: 
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7: 
   8:         ...
   9:             currentActionMap = config.getActionMap();
  10:             currentActionMap.setParent(defaultActionMap);
  11:         }
  12:         ...
  13:     public void setParentActionMap(ActionMap map) {
  14:         defaultActionMap.setParent(map);

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.BorderFactory;
   4:         ...
   5:     
   6:     protected ActionMap defaultActionMap = new ActionMap();
   7:     
   8:         ...
   9:             currentActionMap = config.getActionMap();
  10:             currentActionMap.setParent(defaultActionMap);
  11:         }
  12:         ...
  13:     public void setParentActionMap(ActionMap map) {
  14:         defaultActionMap.setParent(map);

View Full Code Here
   1: import javax.swing.Action;
   2: import javax.swing.ActionMap;
   3: import javax.swing.DefaultCellEditor;
   4:         ...
   5:             InputMap inputMap = getInputMap();
   6:             inputMap.setParent(getTreeTable().getInputMap(JComponent.WHEN_FOCUSED));
   7:             getTreeTable().setInputMap(JComponent.WHEN_FOCUSED, inputMap);
   8:         ...
   9:             ActionMap actionMap= getActionMap();
  10:         ...
  11:             actionMap.setParent(getTreeTable().getActionMap());

View Full Code Here

size

public int size()
Returns the number of KeyStroke bindings.