Java 类com.intellij.openapi.actionSystem.impl.ActionMenuItem 实例源码

项目:IntelliJ-Key-Promoter-X    文件:KeyPromoterAction.java   
/**
 * Information extraction for entries in the menu
 *
 * @param source source of the action
 */
private void analyzeActionMenuItem(ActionMenuItem source) {
    mySource = ActionSource.MENU_ENTRY;
    myDescription = source.getText();
    myMnemonic = source.getMnemonic();
    final Field actionField = findActionField(source, ActionRef.class);
    if (actionField != null) {
        try {
            final ActionRef o = (ActionRef) actionField.get(source);
            final AnAction action = o.getAction();
            if (action != null) {
                fixValuesFromAction(action);
            }
        } catch (Exception e) {
            // happens..
        }
    }
}
项目:IntelliJ-Key-Promoter-X    文件:KeyPromoterAction.java   
/**
 * Constructor used when have to fall back to inspect an AWT event instead of actions that are directly provided
 * by IDEA. Tool-window stripe buttons are such a case where I'm not notified by IDEA if one is pressed
 *
 * @param event mouse event that happened
 */
KeyPromoterAction(AWTEvent event) {
    final Object source = event.getSource();
    if (source instanceof ActionButton) {
        analyzeActionButton((ActionButton) source);
    } else if (source instanceof StripeButton) {
        analyzeStripeButton((StripeButton) source);
    } else if (source instanceof ActionMenuItem) {
        analyzeActionMenuItem((ActionMenuItem) source);
    } else if (source instanceof JButton) {
        analyzeJButton((JButton) source);
    }

}
项目:force-shortcuts-intellij-plugin    文件:ShortcutActionFactory.java   
public static Optional<ShortcutAction> buildShortcutIfAvailable(Component eventSource) {
    ShortcutAction shortcut = null;

    if (isActionButton(eventSource)) {
        shortcut = buildShortcut((ActionButton) eventSource);
    } else if (isActionMenuItem(eventSource)) {
        shortcut = buildShortcut((ActionMenuItem) eventSource);
    }

    if (shortcut != null && StringUtil.isEmptyOrSpaces(shortcut.getShortcutText())) {
        return Optional.empty();
    }

    return Optional.ofNullable(shortcut);
}
项目:intellij-ce-playground    文件:ProjectWindowAction.java   
@Override
public void setSelected(@Nullable AnActionEvent e, boolean selected) {

  if (e == null) return;
  boolean macMainMenu = SystemInfo.isMac && ActionPlaces.isMainMenuOrActionSearch(e.getPlace());

  if (!selected && !macMainMenu) {
    return;
  }

  final Project project = findProject();
  if (project == null) {
    return;
  }
  final JFrame projectFrame = WindowManager.getInstance().getFrame(project);
  final int frameState = projectFrame.getExtendedState();

  if (macMainMenu && !(e.getInputEvent().getSource() instanceof ActionMenuItem) && (projectFrame.getExtendedState() & Frame.ICONIFIED) != 0) {
    // On Mac minimized window should not be restored this way
    return;
  }

  if (BitUtil.isSet(frameState, Frame.ICONIFIED)) {
    // restore the frame if it is minimized
    projectFrame.setExtendedState(frameState ^ Frame.ICONIFIED);
  }
  projectFrame.toFront();
  projectFrame.requestFocus();
  //ProjectUtil.focusProjectWindow(project, true);
}
项目:intellij-ce-playground    文件:BegMenuItemUI.java   
/** Copied from BasicMenuItemUI */
private void doClick(MenuSelectionManager msm,MouseEvent e) {
  // Auditory cue
  if(!isInternalFrameSystemMenu()){
    @NonNls ActionMap map=menuItem.getActionMap();
    if(map!=null){
      Action audioAction=map.get(getPropertyPrefix()+".commandSound");
      if(audioAction!=null){
        // pass off firing the Action to a utility method
        BasicLookAndFeel lf=(BasicLookAndFeel)UIManager.getLookAndFeel();
        // It's a hack. The method BasicLookAndFeel.playSound has protected access, so
        // it's imposible to mormally invoke it.
        try {
          Method playSoundMethod=BasicLookAndFeel.class.getDeclaredMethod(PLAY_SOUND_METHOD,new Class[]{Action.class});
          playSoundMethod.setAccessible(true);
          playSoundMethod.invoke(lf,new Object[]{audioAction});
        } catch(Exception ignored) {}
      }
    }
  }
  // Visual feedback
  if(msm==null){
    msm=MenuSelectionManager.defaultManager();
  }
  msm.clearSelectedPath();
  ((ActionMenuItem)menuItem).fireActionPerformed(
    new ActionEvent(
      menuItem,
      ActionEvent.ACTION_PERFORMED,
      null,
      e.getWhen(),
      e.getModifiers()
    )
  );
}
项目:tools-idea    文件:BegMenuItemUI.java   
/** Copied from BasicMenuItemUI */
private void doClick(MenuSelectionManager msm,MouseEvent e) {
  // Auditory cue
  if(!isInternalFrameSystemMenu()){
    @NonNls ActionMap map=menuItem.getActionMap();
    if(map!=null){
      Action audioAction=map.get(getPropertyPrefix()+".commandSound");
      if(audioAction!=null){
        // pass off firing the Action to a utility method
        BasicLookAndFeel lf=(BasicLookAndFeel)UIManager.getLookAndFeel();
        // It's a hack. The method BasicLookAndFeel.playSound has protected access, so
        // it's imposible to mormally invoke it.
        try {
          Method playSoundMethod=BasicLookAndFeel.class.getDeclaredMethod(PLAY_SOUND_METHOD,new Class[]{Action.class});
          playSoundMethod.setAccessible(true);
          playSoundMethod.invoke(lf,new Object[]{audioAction});
        } catch(Exception ignored) {}
      }
    }
  }
  // Visual feedback
  if(msm==null){
    msm=MenuSelectionManager.defaultManager();
  }
  msm.clearSelectedPath();
  ((ActionMenuItem)menuItem).fireActionPerformed(
    new ActionEvent(
      menuItem,
      ActionEvent.ACTION_PERFORMED,
      null,
      e.getWhen(),
      e.getModifiers()
    )
  );
}
项目:force-shortcuts-intellij-plugin    文件:ShortcutActionFactory.java   
public static ShortcutAction buildShortcut(ActionMenuItem actionMenuItem) {
    String shortcutText = actionMenuItem.getFirstShortcutText();
    String description = actionMenuItem.getText();

    return new ShortcutAction(shortcutText, description);
}
项目:force-shortcuts-intellij-plugin    文件:ShortcutActionFactory.java   
private static boolean isActionMenuItem(Component component) {
    return ActionMenuItem.class.isAssignableFrom(component.getClass());
}
项目:intellij-ce-playground    文件:GtkMenuItemUI.java   
private boolean isCheckBoxItem() {
  return menuItem instanceof ActionMenuItem && ((ActionMenuItem)menuItem).isToggleable();
}
项目:intellij-ce-playground    文件:BegMenuItemUI.java   
public Dimension getPreferredSize(JComponent comp) {
  JMenuItem jmenuitem = (JMenuItem)comp;
  Icon icon1 = getIcon();
  Icon icon2 = getAllowedIcon();
  String text = jmenuitem.getText();
  String keyStrokeText;
  if (jmenuitem instanceof ActionMenuItem) {
    keyStrokeText = ((ActionMenuItem)jmenuitem).getFirstShortcutText();
  }else{
    keyStrokeText = getKeyStrokeText(jmenuitem.getAccelerator());
  }
  Font font = jmenuitem.getFont();
  FontMetrics fontmetrics = comp.getFontMetrics(font);
  FontMetrics fontmetrics1 = comp.getFontMetrics(acceleratorFont);
  initBounds();
  layoutMenuItem(fontmetrics, text, fontmetrics1, keyStrokeText, icon1, icon2, arrowIcon, jmenuitem.getVerticalAlignment(), jmenuitem.getHorizontalAlignment(), jmenuitem.getVerticalTextPosition(), jmenuitem.getHorizontalTextPosition(), f, l, j, c, h, d, text != null ? defaultTextIconGap : 0, defaultTextIconGap);
  i.setBounds(j);
  i = SwingUtilities.computeUnion(l.x, l.y, l.width, l.height, i);
  if (!(keyStrokeText == null || "".equals(keyStrokeText))){
    i.width += c.width;
    i.width += 7 * defaultTextIconGap;
  }
  if (useCheckAndArrow()){
    i.width += myMaxGutterIconWidth;
    i.width += defaultTextIconGap;
    i.width += defaultTextIconGap;
    i.width += d.width;
  }
  i.width += 2 * defaultTextIconGap;
  Insets insets = jmenuitem.getInsets();
  if (insets != null){
    i.width += insets.left + insets.right;
    i.height += insets.top + insets.bottom;
  }
  if (i.width % 2 == 0){
    i.width++;
  }
  if (i.height % 2 == 0){
    i.height++;
  }
  return i.getSize();
}
项目:tools-idea    文件:GtkMenuItemUI.java   
private boolean isCheckBoxItem() {
  return menuItem instanceof ActionMenuItem && ((ActionMenuItem)menuItem).isToggleable();
}
项目:tools-idea    文件:BegMenuItemUI.java   
public Dimension getPreferredSize(JComponent comp) {
  JMenuItem jmenuitem = (JMenuItem)comp;
  Icon icon1 = getIcon();
  Icon icon2 = getAllowedIcon();
  String text = jmenuitem.getText();
  String keyStrokeText;
  if (jmenuitem instanceof ActionMenuItem) {
    keyStrokeText = ((ActionMenuItem)jmenuitem).getFirstShortcutText();
  }else{
    keyStrokeText = getKeyStrokeText(jmenuitem.getAccelerator());
  }
  Font font = jmenuitem.getFont();
  FontMetrics fontmetrics = comp.getFontMetrics(font);
  FontMetrics fontmetrics1 = comp.getFontMetrics(acceleratorFont);
  initBounds();
  layoutMenuItem(fontmetrics, text, fontmetrics1, keyStrokeText, icon1, icon2, arrowIcon, jmenuitem.getVerticalAlignment(), jmenuitem.getHorizontalAlignment(), jmenuitem.getVerticalTextPosition(), jmenuitem.getHorizontalTextPosition(), f, l, j, c, h, d, text != null ? defaultTextIconGap : 0, defaultTextIconGap);
  i.setBounds(j);
  i = SwingUtilities.computeUnion(l.x, l.y, l.width, l.height, i);
  if (!(keyStrokeText == null || "".equals(keyStrokeText))){
    i.width += c.width;
    i.width += 7 * defaultTextIconGap;
  }
  if (useCheckAndArrow()){
    i.width += myMaxGutterIconWidth;
    i.width += defaultTextIconGap;
    i.width += defaultTextIconGap;
    i.width += d.width;
  }
  i.width += 2 * defaultTextIconGap;
  Insets insets = jmenuitem.getInsets();
  if (insets != null){
    i.width += insets.left + insets.right;
    i.height += insets.top + insets.bottom;
  }
  if (i.width % 2 == 0){
    i.width++;
  }
  if (i.height % 2 == 0){
    i.height++;
  }
  return i.getSize();
}
项目:consulo    文件:GtkMenuItemUI.java   
private boolean isCheckBoxItem() {
  return menuItem instanceof ActionMenuItem && ((ActionMenuItem)menuItem).isToggleable();
}
项目:consulo    文件:BegMenuItemUI.java   
@Override
public Dimension getPreferredSize(JComponent comp) {
  JMenuItem jmenuitem = (JMenuItem)comp;
  Icon icon1 = getIcon();
  Icon icon2 = getAllowedIcon();
  String text = jmenuitem.getText();
  String keyStrokeText;
  if (jmenuitem instanceof ActionMenuItem) {
    keyStrokeText = ((ActionMenuItem)jmenuitem).getFirstShortcutText();
  }
  else {
    keyStrokeText = getKeyStrokeText(jmenuitem.getAccelerator());
  }
  Font font = jmenuitem.getFont();
  FontMetrics fontmetrics = comp.getFontMetrics(font);
  FontMetrics fontmetrics1 = comp.getFontMetrics(acceleratorFont);
  initBounds();
  layoutMenuItem(fontmetrics, text, fontmetrics1, keyStrokeText, icon1, icon2, arrowIcon, jmenuitem.getVerticalAlignment(),
                 jmenuitem.getHorizontalAlignment(), jmenuitem.getVerticalTextPosition(), jmenuitem.getHorizontalTextPosition(), f, l, j, c, h, d,
                 text != null ? defaultTextIconGap : 0, defaultTextIconGap);
  i.setBounds(j);
  i = SwingUtilities.computeUnion(l.x, l.y, l.width, l.height, i);
  if (!(keyStrokeText == null || "".equals(keyStrokeText))) {
    i.width += c.width;
    i.width += 7 * defaultTextIconGap;
  }
  if (useCheckAndArrow()) {
    i.width += myMaxGutterIconWidth;
    i.width += defaultTextIconGap;
    i.width += defaultTextIconGap;
    i.width += d.width;
  }
  i.width += 2 * defaultTextIconGap;
  Insets insets = jmenuitem.getInsets();
  if (insets != null) {
    i.width += insets.left + insets.right;
    i.height += insets.top + insets.bottom;
  }
  if (i.width % 2 == 0) {
    i.width++;
  }
  if (i.height % 2 == 0) {
    i.height++;
  }
  return i.getSize();
}
项目:consulo    文件:ModernMenuItemUI.java   
@Override
public Dimension getPreferredSize(JComponent comp) {
  JMenuItem jmenuitem = (JMenuItem)comp;
  Icon icon1 = getIcon();
  Icon icon2 = getAllowedIcon();
  String text = jmenuitem.getText();
  String keyStrokeText;
  if (jmenuitem instanceof ActionMenuItem) {
    keyStrokeText = ((ActionMenuItem)jmenuitem).getFirstShortcutText();
  }
  else {
    keyStrokeText = getKeyStrokeText(jmenuitem.getAccelerator());
  }
  Font font = jmenuitem.getFont();
  FontMetrics fontmetrics = comp.getFontMetrics(font);
  FontMetrics fontmetrics1 = comp.getFontMetrics(acceleratorFont);
  initBounds();
  layoutMenuItem(fontmetrics, text, fontmetrics1, keyStrokeText, icon1, icon2, arrowIcon, jmenuitem.getVerticalAlignment(),
                 jmenuitem.getHorizontalAlignment(), jmenuitem.getVerticalTextPosition(), jmenuitem.getHorizontalTextPosition(), f, l, j, c, h, d,
                 text != null ? defaultTextIconGap : 0, defaultTextIconGap);
  i.setBounds(j);
  i = SwingUtilities.computeUnion(l.x, l.y, l.width, l.height, i);
  if (!(keyStrokeText == null || "".equals(keyStrokeText))) {
    i.width += c.width;
    i.width += 7 * defaultTextIconGap;
  }
  if (useCheckAndArrow()) {
    i.width += myMaxGutterIconWidth;
    i.width += defaultTextIconGap;
    i.width += defaultTextIconGap;
    i.width += d.width;
  }
  i.width += 2 * defaultTextIconGap;
  Insets insets = jmenuitem.getInsets();
  if (insets != null) {
    i.width += insets.left + insets.right;
    i.height += insets.top + insets.bottom;
  }
  if (i.width % 2 == 0) {
    i.width++;
  }
  if (i.height % 2 == 0) {
    i.height++;
  }
  return i.getSize();
}