@Override public void actionPerformed(ActionEvent e) { if (focusOwner == null) return; String action = e.getActionCommand(); Action a = focusOwner.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(focusOwner, ActionEvent.ACTION_PERFORMED, null)); } } }
Action action = null; do { action = action == null ? aMap.get(DefaultEditorKit.deletePrevCharAction) : null; aMap.remove(DefaultEditorKit.deletePrevCharAction); aMap = aMap.getParent();
public Action get(Object key) { Component c = component; for (;;) { if (c instanceof JComponent) { javax.swing.ActionMap m = ((JComponent) c).getActionMap(); if (m != null) { Action a = m.get(key); if (a != null) { return a; } } } if (c instanceof Lookup.Provider) { break; } c = c.getParent(); if (c == null) { break; } } return null; }
/*** 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; }
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; }
@Override public void actionPerformed(ActionEvent e) { ActionEvent copyEvent = new ActionEvent( JPopupMenuTable.this.table, ActionEvent.ACTION_PERFORMED, "copy" ); JPopupMenuTable.this.table.getActionMap().get(copyEvent.getActionCommand()).actionPerformed(copyEvent); } }
/** * Perform copy event on current table. */ public void copyTable() { ActionEvent nev = new ActionEvent(this.tableValues, ActionEvent.ACTION_PERFORMED, "copy"); this.tableValues.getActionMap().get(nev.getActionCommand()).actionPerformed(nev); }
public Action get(Object key) { Component c = component; for (;;) { if (c instanceof JComponent) { javax.swing.ActionMap m = ((JComponent) c).getActionMap(); if (m != null) { Action a = m.get(key); if (a != null) { return a; } } } if (c instanceof Lookup.Provider) { break; } c = c.getParent(); if (c == null) { break; } } return null; }
/*** 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; }
/** * Selects word based on a mouse event. */ private void selectWord(MouseEvent e) { if (selectedWordEvent != null && selectedWordEvent.getX() == e.getX() && selectedWordEvent.getY() == e.getY()) { // We've already the done selection for this. return; } Action a = null; RTextArea textArea = getTextArea(); ActionMap map = textArea.getActionMap(); if (map != null) { a = map.get(RTextAreaEditorKit.selectWordAction); } if (a == null) { if (selectWord == null) { selectWord = new RTextAreaEditorKit.SelectWordAction(); } a = selectWord; } a.actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers())); selectedWordEvent = e; }
/** * Returns the "dumb complete word action" to test associated with a text * area. * * @param textArea The text area. * @return The associated action. */ private static final DumbCompleteWordAction getDumbCompleteWordAction( RSyntaxTextArea textArea) { ActionMap am = textArea.getActionMap(); return (DumbCompleteWordAction)am.get( RTextAreaEditorKit.rtaDumbCompleteWordAction); }
void updateState(ActionMap prev, ActionMap now, boolean fire) { if (key == null) { return; } boolean prevEnabled = false; if (prev != null) { Action prevAction = prev.get(key); if (prevAction != null) { prevEnabled = fire && prevAction.isEnabled(); prevAction.removePropertyChangeListener(weakL); } } if (now != null) { Action nowAction = now.get(key); boolean nowEnabled; if (nowAction != null) { nowAction.addPropertyChangeListener(weakL); nowEnabled = nowAction.isEnabled(); } else { nowEnabled = fallback != null && fallback.isEnabled(); } PropertyChangeSupport sup = fire ? support : null; if (sup != null && nowEnabled != prevEnabled) { sup.firePropertyChange("enabled", prevEnabled, !prevEnabled); // NOI18N } } }
/** * Create popup menu for this component. * @param component The component receiving the menu */ public JPopupMenuText(JTextComponent component) { super(component); if (component.isEditable()) { JMenuItem cutItem = new JMenuItem(); cutItem.setIcon(HelperUi.ICON_EMPTY); cutItem.setAction(component.getActionMap().get(DefaultEditorKit.cutAction)); cutItem.setText("Cut"); cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); cutItem.setMnemonic('t'); JMenuItem pasteItem = new JMenuItem(); pasteItem.setIcon(HelperUi.ICON_EMPTY); pasteItem.setAction(component.getActionMap().get(DefaultEditorKit.pasteAction)); pasteItem.setText("Paste"); pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); pasteItem.setMnemonic('P'); // Before Copy menu this.add(cutItem, 0); // After Copy menu this.add(pasteItem, 2); } }
private JPopupMenu createPopupMenu() { JPopupMenu popup = new JPopupMenu(); popup.add(getActionMap().get(ZOOM_ACTUAL)); popup.add(getActionMap().get(ZOOM_IN)); popup.add(getActionMap().get(ZOOM_OUT)); popup.addSeparator(); ButtonGroup group = new ButtonGroup(); JMenu background = new JMenu("Background"); popup.add(background); ChangeBackgroundAction checkered = new ChangeBackgroundAction("Checkered", checkeredBG); checkered.putValue(Action.SELECTED_KEY, backgroundPaint == checkeredBG); addCheckBoxItem(checkered, background, group); background.addSeparator(); addCheckBoxItem(new ChangeBackgroundAction("White", Color.WHITE), background, group); addCheckBoxItem(new ChangeBackgroundAction("Light", Color.LIGHT_GRAY), background, group); addCheckBoxItem(new ChangeBackgroundAction("Gray", Color.GRAY), background, group); addCheckBoxItem(new ChangeBackgroundAction("Dark", Color.DARK_GRAY), background, group); addCheckBoxItem(new ChangeBackgroundAction("Black", Color.BLACK), background, group); background.addSeparator(); ChooseBackgroundAction chooseBackgroundAction = new ChooseBackgroundAction("Choose...", defaultBG != null ? defaultBG : Color.BLUE); chooseBackgroundAction.putValue(Action.SELECTED_KEY, backgroundPaint == defaultBG); addCheckBoxItem(chooseBackgroundAction, background, group); return popup; }
copyItem.setAction(component.getActionMap().get(DefaultEditorKit.copyAction)); copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); copyItem.setMnemonic('C'); selectAllItem.setAction(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAllItem.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL")); I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", selectAllItem);
ActionMap map = textArea.getActionMap(); if (map != null) { a = map.get(RTextAreaEditorKit.selectLineAction);