Java Code Examples for javax.swing.ActionMap#get()
The following examples show how to use
javax.swing.ActionMap#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Actions.java From jclic with GNU General Public License v2.0 | 6 votes |
/** * Collects the keys of all the actions linked to a specific * {@link javax.swing.JComponent} and groups them in arrays by action names. * * @param jc The JComponent with the actions linked to. * @return A HashMap formed by pairs of action names (key) and arrays of action * keys (value). Usually each action name has only one action key * associated to it, and the value of the pair is an object array with * only one string, but this is not an imperative: several actions can * be associated to a single name. */ public static Map<String, Object[]> getActionKeys(JComponent jc) { Map<String, Object[]> result = new HashMap<String, Object[]>(); ActionMap am = jc.getActionMap(); for (Object amk : am.allKeys()) { Action act = am.get(amk); Object o = act.getValue(Action.NAME); if (o == null) o = ""; String name = o.toString(); Object[] keys = result.get(name); if (keys == null) keys = new Object[] { amk }; else { Object[] k2 = new Object[keys.length + 1]; int j; for (j = 0; j < keys.length; j++) k2[j] = keys[j]; k2[j] = amk; keys = k2; } result.put(name, keys); } return result; }
Example 2
Source File: CallbackSystemAction.java From netbeans with Apache License 2.0 | 6 votes |
/*** Finds an action that we should delegate to * @return the action or null */ private Action findAction() { Collection<? extends ActionMap> c = result != null ? result.allInstances() : Collections.<ActionMap>emptySet(); if (!c.isEmpty()) { Object key = delegate.getActionMapKey(); for (ActionMap map : c) { Action action = map.get(key); if (action != null) { return action; } } } return null; }
Example 3
Source File: ActionManager.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * Retrieve an action knowing its methodName. * * @param instance the instance of the hosting class * @param methodName the method name * @return the action found, or null if none */ public ApplicationAction getActionInstance (Object instance, String methodName) { ActionMap actionMap = MainGui.getInstance().getContext().getActionMap( instance); return (ApplicationAction) actionMap.get(methodName); }
Example 4
Source File: BasicLookAndFeel.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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); } } } }
Example 5
Source File: BasicLookAndFeel.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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); } } } }
Example 6
Source File: InitializeInAWTTest.java From netbeans with Apache License 2.0 | 5 votes |
public void resultChanged(LookupEvent ev) { if (!res.allItems().isEmpty()) { ActionMap m = res.allInstances().iterator().next(); last = m.get("MyAction"); } else { last = null; } }
Example 7
Source File: EditorFrame.java From settlers-remake with MIT License | 5 votes |
/** * Create a single menu in the Menubar * * @param menuName * Name of the menu * @return JMenu */ private JMenu createMenu(String menuName) { ActionMap actionMap = ((JPanel) this.getContentPane()).getActionMap(); JMenu menu = new JMenu(EditorLabels.getLabel("menu." + menuName)); // because of the open gl context menu.getPopupMenu().setLightWeightPopupEnabled(false); for (String menuActionName : menuconfig.getProperty("menu." + menuName, "").split(",")) { menuActionName = menuActionName.trim(); if (menuActionName.isEmpty()) { continue; } if ("---".equals(menuActionName)) { menu.addSeparator(); } else { final Action action = actionMap.get(menuActionName); if (action == null) { System.err.println("Action \"" + menuActionName + "\" not found!"); continue; } createMenuItemForAction(action, menuActionName, menu); } } return menu; }
Example 8
Source File: BasicLookAndFeel.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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); } } } }
Example 9
Source File: GlobalManager.java From netbeans with Apache License 2.0 | 5 votes |
public Action findGlobalAction(Object key) { if (key == null) { return null; } ActionMap map = actionMap.get(); Action a = (map == null) ? null : map.get(key); if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Action for key: {0} is: {1}", new Object[]{key, a}); // NOI18N } return a; }
Example 10
Source File: MainFrameTree.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
ActionListener treeActionAdapter(ActionMap map, String actionName) { final Action selectPrevious = map.get(actionName); return e -> { e.setSource(tree); selectPrevious.actionPerformed(e); }; }
Example 11
Source File: BasicLookAndFeel.java From Java8CN with Apache License 2.0 | 5 votes |
/** * 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); } } } }
Example 12
Source File: BasicLookAndFeel.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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); } } } }
Example 13
Source File: AnimationAutoCompletion.java From 3Dscript with BSD 2-Clause "Simplified" License | 5 votes |
/** * Installs a "trigger key" action onto the current text component. * * @param ks The keystroke that should trigger the action. * @see #uninstallTriggerKey() */ private void installTriggerKey(KeyStroke ks) { InputMap im = textComponent.getInputMap(); oldTriggerKey = im.get(ks); im.put(ks, PARAM_TRIGGER_KEY); ActionMap am = textComponent.getActionMap(); oldTriggerAction = am.get(PARAM_TRIGGER_KEY); am.put(PARAM_TRIGGER_KEY, createAutoCompleteAction()); }
Example 14
Source File: ActionManager.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Retrieve an action knowing its methodName. * * @param instance the instance of the hosting class * @param methodName the method name * @return the action found, or null if none */ public ApplicationAction getActionInstance (Object instance, String methodName) { ActionMap actionMap = OmrGui.getApplication().getContext().getActionMap(instance); return (ApplicationAction) actionMap.get(methodName); }
Example 15
Source File: QComboBoxUI.java From pumpernickel with MIT License | 5 votes |
@Override protected void uninstallKeyboardActions() { super.uninstallKeyboardActions(); // purge all our actions ActionMap actionMap = comboBox.getActionMap(); for (Object key : actionMap.allKeys()) { if (actionMap.get(key) instanceof QComboBoxUIAction) { actionMap.put(key, null); } } }
Example 16
Source File: SheetTable.java From netbeans with Apache License 2.0 | 4 votes |
@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)); } }
Example 17
Source File: AnimationAutoCompletion.java From 3Dscript with BSD 2-Clause "Simplified" License | 4 votes |
/** * Installs this auto-completion on a text component. If this * {@link AnimationAutoCompletion} is already installed on another text component, * it is uninstalled first. * * @param c The text component. * @see #uninstall() */ @Override public void install(JTextComponent c) { if (textComponent != null) { uninstall(); } this.textComponent = c; installTriggerKey(getTriggerKey()); // Install the function completion key, if there is one. // NOTE: We cannot do this if the start char is ' ' (e.g. just a space // between the function name and parameters) because it overrides // RSTA's special space action. It seems KeyStorke.getKeyStroke(' ') // hoses ctrl+space, shift+space, etc., even though I think it // shouldn't... char start = provider.getParameterListStart(); if (start != 0 && start != ' ') { InputMap im = c.getInputMap(); ActionMap am = c.getActionMap(); KeyStroke ks = KeyStroke.getKeyStroke(start); oldParenKey = im.get(ks); im.put(ks, PARAM_COMPLETE_KEY); oldParenAction = am.get(PARAM_COMPLETE_KEY); am.put(PARAM_COMPLETE_KEY, new ParameterizedCompletionStartAction( start)); } textComponentListener.addTo(this.textComponent); // In case textComponent is already in a window... textComponentListener.hierarchyChanged(null); if (isAutoActivationEnabled()) { autoActivationListener.addTo(this.textComponent); } UIManager.addPropertyChangeListener(lafListener); updateUI(); // In case there have been changes since we uninstalled }
Example 18
Source File: BaseTable.java From netbeans with Apache License 2.0 | 4 votes |
private void trySendEscToDialog(JTable jt) { // System.err.println("SendEscToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } InputMap imp = jt.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = jt.getRootPane().getActionMap(); KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Object key = imp.get(escape); if (key != null) { Action a = am.get(key); if (a != null) { if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N System.err.println("Action bound to escape key is " + a); //NOI18N } //Actions registered with deprecated registerKeyboardAction will //need this lookup of the action command String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY); if (commandKey == null) { commandKey = "cancel"; //NOI18N } a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N } } } }
Example 19
Source File: NavigatorTCTest.java From netbeans with Apache License 2.0 | 4 votes |
/** */ @RandomlyFails // NB-Core-Build #9367: Still Unstable public void test_118082_ExplorerView () throws Exception { System.out.println("Testing #118082, Explorer view integration..."); InstanceContent ic = getInstanceContent(); TestLookupHint explorerHint = new TestLookupHint("explorerview/tester"); ic.add(explorerHint); NavigatorTC navTC = NavigatorTC.getInstance(); NavigatorTCHandle navTCH = new NavigatorTCHandle(navTC); try { navTCH.open(); waitForProviders(navTC); List<? extends NavigatorPanel> panels = navTC.getPanels(); assertNotNull("Selected panel should not be null", navTC.getSelectedPanel()); assertTrue("Expected 1 provider panel, but got " + panels.size(), panels != null && panels.size() == 1); assertTrue("Panel class not expected", panels.get(0) instanceof ListViewNavigatorPanel); ListViewNavigatorPanel provider = (ListViewNavigatorPanel)panels.get(0); // wait for selected node change to be applied, because changes are // reflected with little delay waitForChange(); Node[] selNodes = provider.getExplorerManager().getSelectedNodes(); Node[] actNodes = navTC.getActivatedNodes(); Action copyAction = provider.getCopyAction(); assertTrue("Copy action should be enabled", copyAction.isEnabled()); assertNotNull("Activated nodes musn't be null", actNodes); assertNotNull("Explorer view selected nodes musn't be null", selNodes); assertTrue("Expected 1 activated node, but got " + actNodes.length, actNodes.length == 1); assertTrue("Nodes from explorer view not propagated correctly, should be the same as activated nodes, but got: \n" + "activated nodes: " + Arrays.toString(actNodes) +"\n" + "explorer view selected nodes: " + Arrays.toString(selNodes), Arrays.equals(actNodes, selNodes)); // test if action map can be found in NavigatorTC lookup Collection<? extends ActionMap> result = navTC.getLookup().lookupResult(ActionMap.class).allInstances(); boolean found = false; for (Iterator<? extends ActionMap> it = result.iterator(); it.hasNext();) { ActionMap map = it.next(); Action a = map.get(DefaultEditorKit.copyAction); if (a != null) { found = true; assertSame("Different action instance the expected", a, copyAction); } } assertTrue("Action " + DefaultEditorKit.copyAction + " not found in action map", found); } finally { // cleanup navTCH.close(); ic.remove(explorerHint); } }
Example 20
Source File: EditorFrame.java From settlers-remake with MIT License | 4 votes |
/** * Create the toolbar from menu.properties */ private void createToolbar() { ActionMap actionMap = ((JPanel) this.getContentPane()).getActionMap(); JToolBar tb = new JToolBar(); tb.setFloatable(false); for (String toolName : menuconfig.getProperty("toolbar", "").split(",")) { toolName = toolName.trim(); if (toolName.isEmpty()) { continue; } if ("---".equals(toolName)) { tb.addSeparator(); } else if ("player-spinner".equals(toolName)) { tb.add(new JLabel(EditorLabels.getLabel("window.current-player"))); JComponent playerSpinner = createPlayerSelectSelection(); tb.add(playerSpinner); } else { final Action action = actionMap.get(toolName); if (action == null) { System.err.println("Action \"" + toolName + "\" not found!"); continue; } final JButton bt = tb.add(action); action.addPropertyChangeListener(evt -> { if (Action.NAME.equals(evt.getPropertyName())) { setButtonText(bt, action); } }); setButtonText(bt, action); bt.setVerticalTextPosition(SwingConstants.CENTER); bt.setHorizontalTextPosition(SwingConstants.RIGHT); } } add(tb, BorderLayout.NORTH); }