下面列出了javax.swing.ActionMap#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void install() {
ActionMap map = table.getActionMap();
map.put("selectNextColumn", selectNextColumnAction()); // NOI18N
map.put("selectPreviousColumn", selectPreviousColumnAction()); // NOI18N
map.put("selectNextColumnCell", createNextCellAction()); // NOI18N
map.put("selectPreviousColumnCell", createPreviousCellAction()); // NOI18N
map.put("selectFirstColumn", selectFirstColumnAction()); // NOI18N
map.put("selectLastColumn", selectLastColumnAction()); // NOI18N
map.put("selectNextRowCell", selectNextRowAction()); // NOI18N
map.put("selectPreviousRowCell", selectPreviousRowAction()); // NOI18N
map.put("selectNextRowExtendSelection", map.get("selectNextRow")); // NOI18N
map.put("selectPreviousRowExtendSelection", map.get("selectPreviousRow")); // NOI18N
map.put("selectNextColumnExtendSelection", map.get("selectNextColumn")); // NOI18N
map.put("selectPreviousColumnExtendSelection", map.get("selectPreviousColumn")); // NOI18N
map.put("selectLastColumnExtendSelection", map.get("selectLastColumn")); // NOI18N
map.put("selectFirstColumnExtendSelection", map.get("selectFirstColumn")); // NOI18N
}
public void testCopyLikeProblem() throws Exception {
FileObject fo = folder.getFileObject("testCopyLike.instance");
Object obj = fo.getAttribute("instanceCreate");
if (!(obj instanceof Action)) {
fail("Shall create an action: " + obj);
}
InstanceContent ic = new InstanceContent();
AbstractLookup l = new AbstractLookup(ic);
ActionMap map = new ActionMap();
map.put("copy-to-clipboard", new MyAction());
ic.add(map);
CntListener list = new CntListener();
Action clone = ((ContextAwareAction)obj).createContextAwareInstance(l);
clone.addPropertyChangeListener(list);
assertTrue("Enabled", clone.isEnabled());
ic.remove(map);
assertFalse("Disabled", clone.isEnabled());
list.assertCnt("one change", 1);
}
public static ActionMap [] installOverrideActionMap(JTextComponent component) {
ActionMap origActionMap = component.getActionMap();
ActionMap actionMap = new ActionMap();
OverrideAction[] actions = new OverrideAction[]{
new OverrideAction(TAB),
new OverrideAction(SHIFT_TAB),
new OverrideAction(ENTER),
};
// Install the actions into new action map
for (OverrideAction action : actions) {
Object actionKey = (String) action.getValue(Action.NAME);
assert (actionKey != null);
// Translate to the real key in the action map
actionKey = action.findActionKey(component);
if (actionKey != null) { // == null may happen during unit tests
Action origAction = origActionMap.get(actionKey);
action.putValue(ORIGINAL_ACTION_PROPERTY, origAction);
actionMap.put(actionKey, action);
}
}
actionMap.setParent(origActionMap);
// Install the new action map and return the original action map
component.setActionMap(actionMap);
return new ActionMap [] { origActionMap, actionMap };
}
public static <NodeType extends ZyGraphNode<?>> void registerActions(
final AbstractZyGraph<NodeType, ?> graph) {
final ActionMap amap = graph.getView().getCanvasComponent().getActionMap();
amap.put("DOWN", new CActionHotKey<NodeType>("DOWN", graph));
amap.put("UP", new CActionHotKey<NodeType>("UP", graph));
amap.put("LEFT", new CActionHotKey<NodeType>("LEFT", graph));
amap.put("RIGHT", new CActionHotKey<NodeType>("RIGHT", graph));
amap.put("+", new CActionHotKey<NodeType>("+", graph));
amap.put("-", new CActionHotKey<NodeType>("-", graph));
amap.put("m", new CActionHotKey<NodeType>("m", graph));
amap.put("s", new CActionHotKey<NodeType>("s", graph));
amap.put("<", new CActionHotKey<NodeType>("<", graph));
amap.put("SELECT_VISIBLE_NODES", new CActionHotKey<NodeType>("SELECT_VISIBLE_NODES", graph));
amap.put("COPY_CONTENT_FROM_SELECTED_NODES", new CActionHotKey<NodeType>(
"COPY_CONTENT_FROM_SELECTED_NODES", graph));
graph.getView().setActionMap(amap);
graph.getView().getCanvasComponent().setActionMap(amap);
}
/**
* Creates new form J2DNiftyView
*/
public J2DNiftyView(int width , int height) {
initComponents();
//Init cut&paste
ActionMap map = this.getActionMap();
map.put(TransferHandler.getCopyAction().getValue(javax.swing.Action.NAME),
TransferHandler.getCopyAction());
map.put(TransferHandler.getPasteAction().getValue(javax.swing.Action.NAME),
TransferHandler.getPasteAction());
map.put(TransferHandler.getCutAction().getValue(javax.swing.Action.NAME),
TransferHandler.getCutAction());
this.setPreferredSize(new Dimension(width,height));
this.graphWrap = new GraphicsWrappImpl(width, height);
this.setOpaque(true);
previous=null;
selecting=false;
this.selected= new Rectangle();
this.clipView.setSize(width, height);
}
public ListViewNavigatorPanel () {
manager = new ExplorerManager();
ActionMap map = getActionMap();
copyAction = ExplorerUtils.actionCopy(manager);
map.put(DefaultEditorKit.copyAction, copyAction);
map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager));
map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager));
map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false
lookup = ExplorerUtils.createLookup(manager, map);
listView = new ListView();
fillListView(listView);
add(listView);
}
@RandomlyFails // NB-Core-Build #7816: expected:<0> but was:<1>
public void testPropertyChangeListenersDetachedAtFinalizeIssue58100() throws Exception {
class MyAction extends AbstractAction
implements ActionPerformer {
public void actionPerformed(ActionEvent ev) {
}
public void performAction(SystemAction a) {
}
}
MyAction action = new MyAction();
ActionMap map = new ActionMap();
CallbackSystemAction systemaction = (CallbackSystemAction)SystemAction.get(SimpleCallbackAction.class);
map.put(systemaction.getActionMapKey(), action);
Lookup context = Lookups.singleton(map);
Action delegateaction = systemaction.createContextAwareInstance(context);
assertTrue("Action is expected to have a PropertyChangeListener attached", action.getPropertyChangeListeners().length > 0);
Reference actionref = new WeakReference(systemaction);
systemaction = null;
delegateaction = null;
assertGC("CallbackSystemAction is supposed to be GCed", actionref);
assertEquals("Action is expected to have no PropertyChangeListener attached", 0, action.getPropertyChangeListeners().length);
}
private void installActions(ActionMap map, InputMap keys) {
/*
map.put(DefaultEditorKit.copyAction, copyActionPerformer);
map.put(DefaultEditorKit.cutAction, cutActionPerformer);
// Paste still done the old way...
//map.put(DefaultEditorKit.pasteAction, pasteActionPerformer);
*/
map.put("delete", deleteActionPerformer); // or false
map.put(DefaultEditorKit.copyAction, copyActionPerformer);
map.put(DefaultEditorKit.cutAction, cutActionPerformer);
/*
// Popup menu from the keyboard
map.put ("org.openide.actions.PopupAction",
new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
showKeyboardPopup();
}
});
}
});
keys.put(KeyStroke.getKeyStroke("control C"), DefaultEditorKit.copyAction);
keys.put(KeyStroke.getKeyStroke("control X"), DefaultEditorKit.cutAction);
keys.put(KeyStroke.getKeyStroke("control V"), DefaultEditorKit.pasteAction);
*/
keys.put(KeyStroke.getKeyStroke("DELETE"), "delete");
}
public EM() {
manager = new ExplorerManager();
ActionMap map = getActionMap();
map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager));
map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager));
map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager));
map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false
lookup = ExplorerUtils.createLookup(manager, map);
initComponent();
}
Caret(HexEditor hex) {
this.hex = hex;
this.listeners = new ArrayList<ChangeListener>();
this.cursor = -1;
Listener l = new Listener();
hex.addMouseListener(l);
hex.addMouseMotionListener(l);
hex.addKeyListener(l);
hex.addFocusListener(l);
InputMap imap = hex.getInputMap();
ActionMap amap = hex.getActionMap();
AbstractAction nullAction = new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 3859667024369145469L;
@Override
public void actionPerformed(ActionEvent e) {
}
};
String nullKey = "null";
amap.put(nullKey, nullAction);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), nullKey);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), nullKey);
}
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
if (!FILTER_ACTION_KEY.equals(actionKey)) return null;
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
actionMap.put(actionKey, action);
inputMap.put(ks, actionKey);
return ks;
}
/** Creates a modal dialog displaying this PreferencePanel. */
public JFrame createFrame(String name) {
JFrame f = new JFrame(name);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (isMac) {
f.getRootPane().putClientProperty("apple.awt.brushMetalLook",
Boolean.TRUE);
separator.setForeground(new Color(64, 64, 64));
}
f.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
f.getContentPane().add(this, c);
f.setResizable(false);
InputMap inputMap = f.getRootPane().getInputMap(
JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = f.getRootPane().getActionMap();
inputMap.put(escapeKey, escapeKey);
inputMap.put(commandPeriodKey, escapeKey);
actionMap.put(escapeKey, closeDialogAndDisposeAction);
return f;
}
public void testConcurrentModificationException () {
class MyAction extends AbstractAction {
public int cntEnabled;
public int cntPerformed;
@Override
public boolean isEnabled() {
cntEnabled++;
return true;
}
@Override
public void actionPerformed(ActionEvent ev) {
cntPerformed++;
}
}
MyAction myAction = new MyAction();
final ActionMap other = new ActionMap();
ActionMap tc = new ActionMap() {
@Override
public Action get(Object key) {
ActionsInfraHid.setActionMaps(other, new ActionMap ());
return super.get (key);
}
};
ActionsInfraHid.setActionMaps(other, new ActionMap ());
SurviveFocusChgCallbackAction a = SurviveFocusChgCallbackAction.get (SurviveFocusChgCallbackAction.class);
assertFalse("Disabled, as no a.getActionMapKey() in any map", a.isEnabled());
other.put(a.getActionMapKey(), myAction);
ActionsInfraHid.setActionMaps(tc, new ActionMap (), new ActionMap (), new ActionMap ());
assertTrue("Enabled now", a.isEnabled());
}
/**
* Initializes the keys that can be used by the user inside the component.
*/
private void initHotkeys() {
// Don't change focus on TAB
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<KeyStroke>());
final InputMap inputMap = this.getInputMap();
final ActionMap actionMap = getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LEFT");
actionMap.put("LEFT", m_leftAction);
inputMap
.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_DOWN_MASK), "shift LEFT");
actionMap.put("shift LEFT", m_leftAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RIGHT");
actionMap.put("RIGHT", m_rightAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_DOWN_MASK),
"shift RIGHT");
actionMap.put("shift RIGHT", m_rightAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "UP");
actionMap.put("UP", m_upAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_DOWN_MASK), "shift UP");
actionMap.put("shift UP", m_upAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "DOWN");
actionMap.put("DOWN", m_downAction);
inputMap
.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_DOWN_MASK), "shift DOWN");
actionMap.put("shift DOWN", m_downAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PAGE_DOWN");
actionMap.put("PAGE_DOWN", m_pageDownAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.SHIFT_DOWN_MASK),
"shift PAGE_DOWN");
actionMap.put("shift PAGE_DOWN", m_pageDownAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PAGE_UP");
actionMap.put("PAGE_UP", m_pageUpAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK),
"shift PAGE_UP");
actionMap.put("shift PAGE_UP", m_pageUpAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "TAB");
actionMap.put("TAB", m_tabAction);
}
public void testLookupOfStateInActionMap() throws Exception {
class MyAction extends AbstractAction
implements ActionPerformer {
int actionPerformed;
int performAction;
public void actionPerformed(ActionEvent ev) {
actionPerformed++;
}
public void performAction(SystemAction a) {
performAction++;
}
}
MyAction action = new MyAction();
ActionMap map = new ActionMap();
CallbackSystemAction system = (CallbackSystemAction)SystemAction.get(SurviveFocusChgCallbackAction.class);
system.setActionPerformer(null);
map.put(system.getActionMapKey(), action);
Action clone;
//
// Without action map
//
clone = system.createContextAwareInstance(Lookup.EMPTY);
assertTrue("Action should not be enabled if no callback provided", !clone.isEnabled());
system.setActionPerformer(action);
assertTrue("Is enabled, because it has a performer", clone.isEnabled());
system.setActionPerformer(null);
assertTrue("Is disabled, because the performer has been unregistered", !clone.isEnabled());
//
// test with actionmap
//
action.setEnabled(false);
Lookup context = Lookups.singleton(map);
clone = system.createContextAwareInstance(context);
MockPropertyChangeListener listener = new MockPropertyChangeListener();
clone.addPropertyChangeListener(listener);
assertTrue("Not enabled now", !clone.isEnabled());
action.setEnabled(true);
assertTrue("Clone is enabled because the action in ActionMap is", clone.isEnabled());
listener.assertEventCount(1);
system.setActionPerformer(action);
clone.actionPerformed(new ActionEvent(this, 0, ""));
assertEquals("MyAction.actionPerformed invoked", 1, action.actionPerformed);
assertEquals("MyAction.performAction is not invoked", 0, action.performAction);
action.setEnabled(false);
assertTrue("Clone is disabled because the action in ActionMap is", !clone.isEnabled());
listener.assertEventCount(1);
clone.actionPerformed(new ActionEvent(this, 0, ""));
assertEquals("MyAction.actionPerformed invoked again", 2, action.actionPerformed);
assertEquals("MyAction.performAction is not invoked, remains 0", 0, action.performAction);
}
/**
* Returns an <code>ActionMap</code> containing the audio actions
* for this look and feel.
* <P>
* The returned <code>ActionMap</code> contains <code>Actions</code> that
* embody the ability to render an auditory cue. These auditory
* cues map onto user and system activities that may be useful
* for an end user to know about (such as a dialog box appearing).
* <P>
* At the appropriate time,
* the {@code ComponentUI} is responsible for obtaining an
* <code>Action</code> out of the <code>ActionMap</code> and passing
* it to <code>playSound</code>.
* <P>
* This method first looks up the {@code ActionMap} from the
* defaults using the key {@code "AuditoryCues.actionMap"}.
* <p>
* If the value is {@code non-null}, it is returned. If the value
* of the default {@code "AuditoryCues.actionMap"} is {@code null}
* and the value of the default {@code "AuditoryCues.cueList"} is
* {@code non-null}, an {@code ActionMapUIResource} is created and
* populated. Population is done by iterating over each of the
* elements of the {@code "AuditoryCues.cueList"} array, and
* invoking {@code createAudioAction()} to create an {@code
* Action} for each element. The resulting {@code Action} is
* placed in the {@code ActionMapUIResource}, using the array
* element as the key. For example, if the {@code
* "AuditoryCues.cueList"} array contains a single-element, {@code
* "audioKey"}, the {@code ActionMapUIResource} is created, then
* populated by way of {@code actionMap.put(cueList[0],
* createAudioAction(cueList[0]))}.
* <p>
* If the value of the default {@code "AuditoryCues.actionMap"} is
* {@code null} and the value of the default
* {@code "AuditoryCues.cueList"} is {@code null}, an empty
* {@code ActionMapUIResource} is created.
*
*
* @return an ActionMap containing {@code Actions}
* responsible for playing auditory cues
* @throws ClassCastException if the value of the
* default {@code "AuditoryCues.actionMap"} is not an
* {@code ActionMap}, or the value of the default
* {@code "AuditoryCues.cueList"} is not an {@code Object[]}
* @see #createAudioAction
* @see #playSound(Action)
* @since 1.4
*/
protected ActionMap getAudioActionMap() {
ActionMap audioActionMap = (ActionMap)UIManager.get(
"AuditoryCues.actionMap");
if (audioActionMap == null) {
Object[] acList = (Object[])UIManager.get("AuditoryCues.cueList");
if (acList != null) {
audioActionMap = new ActionMapUIResource();
for(int counter = acList.length-1; counter >= 0; counter--) {
audioActionMap.put(acList[counter],
createAudioAction(acList[counter]));
}
}
UIManager.getLookAndFeelDefaults().put("AuditoryCues.actionMap",
audioActionMap);
}
return audioActionMap;
}
@Override
protected void initKeysAndActions() {
super.initKeysAndActions();
unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
expandAction = new ExpandAction();
collapseAction = new CollapseAction();
edClassAction = new EditorClassAction();
InputMap imp = getInputMap();
InputMap impAncestor = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = getActionMap();
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK);
imp.put(ks, null);
imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), ACTION_EXPAND);
imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), ACTION_COLLAPSE);
if (!GraphicsEnvironment.isHeadless()) {
imp.put(
KeyStroke.getKeyStroke(
KeyEvent.VK_HOME, KeyEvent.SHIFT_DOWN_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
), ACTION_EDCLASS
);
}
imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), ACTION_NEXT);
imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK), ACTION_PREV);
impAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK), ACTION_CUSTOM_EDITOR);
impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
am.put(ACTION_EXPAND, expandAction);
am.put(ACTION_COLLAPSE, collapseAction);
am.put(ACTION_CUSTOM_EDITOR, getCustomEditorAction());
am.put(ACTION_EDCLASS, edClassAction);
Action defaultAction = am.get( "selectNextRow" );
if( null != defaultAction ) {
am.put("selectNextRow", new IncrementAction(false, defaultAction));
}
defaultAction = am.get( "selectPreviousRow" );
if( null != defaultAction ) {
am.put("selectPreviousRow", new IncrementAction(true, defaultAction));
}
}
/**
* 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 inputMap add key event to this InputMap
* @param actionMap add action to this ActionMap
* @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
*/
public static void zoomMenuCommands(InputMap inputMap, ActionMap actionMap, Action zoomInAction, Action zoomOutAction) {
int menuKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
// add support for minus key
KeyStroke minusMenueKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_MINUS, menuKeyMask);
inputMap.put(minusMenueKeyStroke, "zoomOutWithMinusKey");
actionMap.put("zoomOutWithMinusKey", zoomOutAction);
// add support for plus key to zoom in. This only works if the keyboard
// layout allows access to the plus character without pressing the shift
// key, which is not the case for US and UK keyboards.
KeyStroke plusMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_PLUS, menuKeyMask);
inputMap.put(plusMenuKeyStroke, "zoomInWithPlusKey");
actionMap.put("zoomInWithPlusKey", zoomInAction);
// add support for cases where the plus character is the secondary
// character for the equal sign key. That is, plus is accessed by pressing
// the shift key and the equal key. This is the case for US and UK
// keyboard layouts, which are also used in Ireland, India, Australia, Canada,
// Hong Kong, New Zealand, South Africa, Malaysia, Singapore and Philippines.
// See https://stackoverflow.com/questions/15605109/java-keybinding-plus-key
// and https://en.wikipedia.org/wiki/QWERTY
// The French Canadian keyboard also has = and + on the same key.
Locale locale = InputContext.getInstance().getLocale();
String isoCountry = locale.getISO3Country();
// https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
if ("USA".equals(isoCountry)
|| "GBR".equals(isoCountry)
|| "IRL".equals(isoCountry)
|| "IND".equals(isoCountry)
|| "AUS".equals(isoCountry)
|| "CAN".equals(isoCountry)
|| "HKG".equals(isoCountry)
|| "NZL".equals(isoCountry)
|| "ZAF".equals(isoCountry)
|| "MYS".equals(isoCountry)
|| "SGP".equals(isoCountry)
|| "PHL".equals(isoCountry)) {
KeyStroke euqalsMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_EQUALS, menuKeyMask);
inputMap.put(euqalsMenuKeyStroke, "zoomInWithEqualsKey");
actionMap.put("zoomInWithEqualsKey", zoomInAction);
}
}
/**
* Returns an <code>ActionMap</code> containing the audio actions
* for this look and feel.
* <P>
* The returned <code>ActionMap</code> contains <code>Actions</code> that
* embody the ability to render an auditory cue. These auditory
* cues map onto user and system activities that may be useful
* for an end user to know about (such as a dialog box appearing).
* <P>
* At the appropriate time,
* the {@code ComponentUI} is responsible for obtaining an
* <code>Action</code> out of the <code>ActionMap</code> and passing
* it to <code>playSound</code>.
* <P>
* This method first looks up the {@code ActionMap} from the
* defaults using the key {@code "AuditoryCues.actionMap"}.
* <p>
* If the value is {@code non-null}, it is returned. If the value
* of the default {@code "AuditoryCues.actionMap"} is {@code null}
* and the value of the default {@code "AuditoryCues.cueList"} is
* {@code non-null}, an {@code ActionMapUIResource} is created and
* populated. Population is done by iterating over each of the
* elements of the {@code "AuditoryCues.cueList"} array, and
* invoking {@code createAudioAction()} to create an {@code
* Action} for each element. The resulting {@code Action} is
* placed in the {@code ActionMapUIResource}, using the array
* element as the key. For example, if the {@code
* "AuditoryCues.cueList"} array contains a single-element, {@code
* "audioKey"}, the {@code ActionMapUIResource} is created, then
* populated by way of {@code actionMap.put(cueList[0],
* createAudioAction(cueList[0]))}.
* <p>
* If the value of the default {@code "AuditoryCues.actionMap"} is
* {@code null} and the value of the default
* {@code "AuditoryCues.cueList"} is {@code null}, an empty
* {@code ActionMapUIResource} is created.
*
*
* @return an ActionMap containing {@code Actions}
* responsible for playing auditory cues
* @throws ClassCastException if the value of the
* default {@code "AuditoryCues.actionMap"} is not an
* {@code ActionMap}, or the value of the default
* {@code "AuditoryCues.cueList"} is not an {@code Object[]}
* @see #createAudioAction
* @see #playSound(Action)
* @since 1.4
*/
protected ActionMap getAudioActionMap() {
ActionMap audioActionMap = (ActionMap)UIManager.get(
"AuditoryCues.actionMap");
if (audioActionMap == null) {
Object[] acList = (Object[])UIManager.get("AuditoryCues.cueList");
if (acList != null) {
audioActionMap = new ActionMapUIResource();
for(int counter = acList.length-1; counter >= 0; counter--) {
audioActionMap.put(acList[counter],
createAudioAction(acList[counter]));
}
}
UIManager.getLookAndFeelDefaults().put("AuditoryCues.actionMap",
audioActionMap);
}
return audioActionMap;
}
public PopupHandler(LookTreeView view) {
this.view = view;
actionMap = new ActionMap();
actionMap.put("delete", new DeleteAction());
}