javax.swing.JComponent.getActionForKeyStroke()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中javax.swing.JComponent.getActionForKeyStroke()方法的一些代码示例,展示了JComponent.getActionForKeyStroke()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getActionForKeyStroke()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getActionForKeyStroke

JComponent.getActionForKeyStroke介绍

暂无

代码示例

代码示例来源:origin: com.jidesoft/jide-oss

/**
 * Registers all actions registered on the source component and registered them on the target component at the
 * specified condition.
 *
 * @param sourceComponent the source component.
 * @param targetComponent the target component.
 * @param keyStrokes      the keystrokes
 * @param condition       the condition which will be used in {@link javax.swing.JComponent#registerKeyboardAction(java.awt.event.ActionListener,
 *                        javax.swing.KeyStroke, int)} as the last parameter.
 */
public static void synchronizeKeyboardActions(JComponent sourceComponent, JComponent targetComponent, KeyStroke[] keyStrokes, int condition) {
  for (KeyStroke keyStroke : keyStrokes) {
    ActionListener actionListener = sourceComponent.getActionForKeyStroke(keyStroke);
    if (actionListener != null) {
      targetComponent.registerKeyboardAction(actionListener, keyStroke, condition);
    }
  }
}

代码示例来源:origin: net.java.dev.laf-widget/laf-widget

public void actionPerformed(ActionEvent e) {
    TabPagerManager te = TabPagerManager.getPager();
    if (te.isVisible()) {
      te.hide();
    } else {
      // fix for defect 233 on Substance - the key event
      // is not dispatched when tab pager is not showing.
      Component comp = jcomp.getParent();
      while (comp != null) {
        if (comp instanceof JComponent) {
          JComponent jc = (JComponent) comp;
          KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(
              KeyEvent.VK_ESCAPE, 0, false);
          ActionListener al = jc
              .getActionForKeyStroke(escapeKeyStroke);
          if (al != null) {
            al.actionPerformed(e);
            return;
          }
        }
        comp = comp.getParent();
      }
    }
  }
});

代码示例来源:origin: com.jidesoft/jide-oss

public static void restoreAction(JComponent component, int condition, KeyStroke keyStroke) {
  if (component == null) {
    return;
  }
  ActionListener action = component.getActionForKeyStroke(keyStroke);
  if (action instanceof DelegateAction) {
    Action actualAction = ((DelegateAction) action).getAction();
    if (actualAction != null) {
      component.registerKeyboardAction(actualAction, keyStroke, condition);
    }
    else {
      component.unregisterKeyboardAction(keyStroke);
    }
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib

private void performJavaDocAction(KeyStroke ks){
  ActionListener act = getJavaDocPane().getJavadocDisplayComponent().getActionForKeyStroke(ks);
  if (act!=null){
    act.actionPerformed(new ActionEvent(getJavaDocPane().getJavadocDisplayComponent(), ActionEvent.ACTION_PERFORMED, "")); //NOI18N
    getJavaDocPane().getJavadocDisplayComponent().repaint();
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-deprecated-pre61completion

private void performJavaDocAction(KeyStroke ks){
  ActionListener act = getJavaDocPane().getJavadocDisplayComponent().getActionForKeyStroke(ks);
  if (act!=null){
    act.actionPerformed(new ActionEvent(getJavaDocPane().getJavadocDisplayComponent(), ActionEvent.ACTION_PERFORMED, "")); //NOI18N
    getJavaDocPane().getJavadocDisplayComponent().repaint();
  }
}

代码示例来源:origin: stackoverflow.com

final ActionListener ctrlVAction = editorPane.getActionForKeyStroke(ctrlV);
editorPane.registerKeyboardAction(new CombinedAction(ctrlVAction, new ActionListener() {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf-navigation

private State handleKeyEvent (Widget widget, WidgetKeyEvent event, KeyStroke keyStroke) {
  ActionListener action;
  if (actionMap != null && inputMap != null) {
    Object o = inputMap.get (keyStroke);
    action = o != null ? actionMap.get (o) : null;
  } else {
    JComponent view = widget.getScene ().getView ();
    action = view != null ? view.getActionForKeyStroke (keyStroke) : null;
  }
  if (action != null) {
    action.actionPerformed (new ActionEvent (widget, (int) event.getEventID (), null, event.getWhen (), event.getModifiers ())); // TODO - action-event command
    return State.CONSUMED;
  }
  return State.REJECTED;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

private State handleKeyEvent (Widget widget, WidgetKeyEvent event, KeyStroke keyStroke) {
  if (keyStroke == null)
    return State.REJECTED;
  ActionListener action;
  if (actionMap != null && inputMap != null) {
    Object o = inputMap.get (keyStroke);
    action = o != null ? actionMap.get (o) : null;
  } else {
    JComponent view = widget.getScene ().getView ();
    action = view != null ? view.getActionForKeyStroke (keyStroke) : null;
  }
  if (action != null) {
    action.actionPerformed (new ActionEvent (widget, (int) event.getEventID (), null, event.getWhen (), event.getModifiers ())); // TODO - action-event command
    return State.CONSUMED;
  }
  return State.REJECTED;
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

private State handleKeyEvent (Widget widget, WidgetKeyEvent event, KeyStroke keyStroke) {
  if (keyStroke == null)
    return State.REJECTED;
  ActionListener action;
  if (actionMap != null && inputMap != null) {
    Object o = inputMap.get (keyStroke);
    action = o != null ? actionMap.get (o) : null;
  } else {
    JComponent view = widget.getScene ().getView ();
    action = view != null ? view.getActionForKeyStroke (keyStroke) : null;
  }
  if (action != null) {
    action.actionPerformed (new ActionEvent (widget, (int) event.getEventID (), null, event.getWhen (), event.getModifiers ())); // TODO - action-event command
    return State.CONSUMED;
  }
  return State.REJECTED;
}

代码示例来源:origin: com.jidesoft/jide-oss

public static void restoreAction(JComponent component, int condition, KeyStroke keyStroke, Class<?> actionClass) {
  ActionListener action = component.getActionForKeyStroke(keyStroke);
  ActionListener parent = action;
  ActionListener top = action;
  while (action instanceof DelegateAction) {
    if (actionClass.isAssignableFrom(action.getClass())) {
      if (top == action) {
        Action a = ((DelegateAction) action).getAction();
        if (a == null) {
          component.unregisterKeyboardAction(keyStroke);
        }
        else {
          component.registerKeyboardAction(a, keyStroke, condition);
        }
      }
      else {
        ((DelegateAction) parent).setAction(((DelegateAction) action).getAction());
      }
      break;
    }
    parent = action;
    action = ((DelegateAction) action).getAction();
  }
}

代码示例来源:origin: com.jidesoft/jide-oss

public static void restoreAction(JComponent component, int condition, KeyStroke keyStroke, Action actionToBeRemoved) {
    ActionListener action = component.getActionForKeyStroke(keyStroke);
    ActionListener parent = action;
    ActionListener top = action;
    while (action instanceof DelegateAction) {
      if (actionToBeRemoved == action) {
        if (top == action) {
          component.registerKeyboardAction(((DelegateAction) action).getAction(), keyStroke, condition);
        }
        else {
          ((DelegateAction) parent).setAction(((DelegateAction) action).getAction());
        }
        break;
      }
      parent = action;
      action = ((DelegateAction) action).getAction();
    }
  }
}

代码示例来源:origin: com.jidesoft/jide-oss

public static void replaceAction(JComponent component, int condition, JComponent target, int targetCondition, KeyStroke keyStroke, DelegateAction delegateAction, boolean first) {
  ActionListener action = component.getActionForKeyStroke(keyStroke);
  if (action != delegateAction && action instanceof Action) {
    if (!first && action instanceof DelegateAction) {

相关文章

JComponent类方法