public abstract class Actions extends Object
Action
objects.
EXAMPLES:
Creation of a new action, with reference to a original key:
AbstractAction beginAction=new AbstractAction(DefaultEditorKit.beginAction){
public void actionPerformed(ActionEvent e){
// ...
}
};
Creation of a new action, with a new key:
AbstractAction prevTargetAction=new AbstractAction("prev-target"){
public void actionPerformed(ActionEvent e){
// ...
}
};
Action that references an existing one:
Action kitUpAction=null;
AbstractAction upAction=new AbstractAction(DefaultEditorKit.upAction){
public void actionPerformed(ActionEvent e){
if(kitUpAction!=null){
// .... pre-action
kitUpAction.actionPerformed(e);
// .... post-action
}
}
};
Actions mapping:
protected void setActions(){
// get existing actions:
kitUpAction=getActionMap().get(DefaultEditorKit.upAction);
// actionKeys init:
java.util.HashMap actionKeys=Actions.getActionKeys(this);
// build new ActionMap:
ActionMap am=new ActionMap();
am.setParent(getActionMap());
setActionMap(am);
//Actions derived to trace (only for debug purposes):
Actions.mapTraceAction(this, actionKeys, DefaultEditorKit.readOnlyAction);
Actions.mapTraceAction(this, actionKeys, DefaultEditorKit.writableAction);
Actions.mapTraceAction(this, actionKeys, "requestFocus");
Actions.mapTraceAction(this, actionKeys, "toggle-componentOrientation");
//Actions to disable:
Actions.mapNullAction(this, actionKeys, DefaultEditorKit.beepAction);
//New actions:
Actions.mapAction(this, actionKeys, beginAction);
Actions.mapAction(this, actionKeys, upAction);
//Original actions mapped to other methods:
Actions.mapAction(this, actionKeys, beginAction, DefaultEditorKit.previousWordAction);
Actions.mapAction(this, actionKeys, prevTargetAction, DefaultEditorKit.beginParagraphAction);
//Uncomment this line only if you want to hide all other actions:
//am.setParent(null);
//
// Assign keystrokes to a new action:
getInputMap().put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.Event.SHIFT_MASK), prevTargetAction.getValue(Action.NAME));
}
Modifier and Type | Class and Description |
---|---|
static class |
Actions.NullAction |
static class |
Actions.TraceAction |
Constructor and Description |
---|
Actions() |
Modifier and Type | Method and Description |
---|---|
static void |
dumpActionKeys(Map<String,Object[]> actionKeys,
ActionMap am)
This function is for debug purposes only.
|
static Map<String,Object[]> |
getActionKeys(JComponent jc)
Collects the keys of all the actions linked to a specific
JComponent and groups them in arrays by action names. |
static void |
mapAction(JComponent jc,
Map<String,Object[]> actionKeys,
Action act) |
static void |
mapAction(JComponent jc,
Map<String,Object[]> actionKeys,
Action act,
String key) |
static void |
mapNullAction(JComponent jc,
Map<String,Object[]> actionKeys,
String s) |
static void |
mapTraceAction(JComponent jc,
Map<String,Object[]> actionKeys,
String s) |
static void |
traceHierarchy(Component cmp,
int level) |
public static Map<String,Object[]> getActionKeys(JComponent jc)
JComponent
and groups them in arrays by action names.jc
- The JComponent with the actions linked to.public static void dumpActionKeys(Map<String,Object[]> actionKeys, ActionMap am)
actionKeys
- am
- public static void mapAction(JComponent jc, Map<String,Object[]> actionKeys, Action act)
public static void mapAction(JComponent jc, Map<String,Object[]> actionKeys, Action act, String key)
public static void mapNullAction(JComponent jc, Map<String,Object[]> actionKeys, String s)
public static void mapTraceAction(JComponent jc, Map<String,Object[]> actionKeys, String s)
public static void traceHierarchy(Component cmp, int level)
Copyright © 2004-15 Francesc Busquets (fbusquets@xtec.cat) & Departament d'Educació de la Generalitat de Catalunya (info@xtec.cat)
Licensed under the terms of the GNU General Public License.