@Override
  public void paint(Graphics g, JComponent comp) {
    checkArrowIcon();
    UISettings.setupAntialiasing(g);
    JMenuItem menuItem = (JMenuItem)comp;
    ButtonModel buttonModel = menuItem.getModel();
    Icon icon = getIcon();
    Icon secondaryIcon = getSecondaryIcon();
    Icon checkIcon = getCheckIcon();
    checkEmptyIcon(comp);
    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();
    initBounds();
    ourViewRect.setBounds(0, 0, menuWidth, menuHeight);
    JBInsets.removeFrom(ourViewRect, comp.getInsets());
    Font oldFont = g.getFont();
    Font font = comp.getFont();
    g.setFont(font);
    FontMetrics fontMetrics = g.getFontMetrics(font);
    FontMetrics keyStrokeMetrics = g.getFontMetrics(acceleratorFont);
    String keyStrokeText = getKeyStrokeText(menuItem);
    String text = layoutMenuItem(fontMetrics, menuItem.getText(), keyStrokeMetrics, keyStrokeText, icon, secondaryIcon, checkIcon, arrowIcon,
                                 menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(), menuItem.getVerticalTextPosition(),
                                 menuItem.getHorizontalTextPosition(),
                                 ourViewRect, ourIconRect, ourSecondaryIconRect, ourTextRect, ourAcceleratorRect, ourCheckIconRect, ourArrowIconRect,
                                 menuItem.getText() != null ? defaultTextIconGap : 0, defaultTextIconGap);
    Color oldColor = g.getColor();
    if (comp.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
      if (isSelected(menuItem)) {
        g.setColor(selectionBackground);
        if (ExperimentalUI.isNewUI() || IdeaPopupMenuUI.isRoundBorder()) {
          IdeaMenuUI.paintRoundSelection(g, comp, menuWidth, menuHeight);
        }
        else {
          g.fillRect(0, 0, menuWidth, menuHeight);
        }
      }
      g.setColor(oldColor);
    }
    if (checkIcon != null) {
      if (isSelected(menuItem)) {
        g.setColor(selectionForeground);
      }
      else {
        g.setColor(menuItem.getForeground());
      }
      if (useCheckAndArrow()) {
        IconUtil.paintSelectionAwareIcon(checkIcon, menuItem, g, ourCheckIconRect.x, ourCheckIconRect.y, isSelected(menuItem));
      }
      g.setColor(oldColor);
    }
    if (icon != null) {
      if (!buttonModel.isEnabled()) {
        icon = menuItem.getDisabledIcon();
      }
      else if (buttonModel.isPressed() && buttonModel.isArmed()) {
        icon = menuItem.getPressedIcon();
        if (icon == null) {
          icon = menuItem.getIcon();
        }
      }
      if (icon != null) {
        IconUtil.paintSelectionAwareIcon(icon, menuItem, g, ourIconRect.x, ourIconRect.y, isSelected(menuItem));
      }
    }
    if (text != null && !text.isEmpty()) {
      int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
      if (buttonModel.isEnabled()) {
        if (isSelected(menuItem)) {
          g.setColor(selectionForeground);
        }
        else{
          g.setColor(menuItem.getForeground());
        }
        BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontMetrics.getAscent());
      }
      else {
        final Object disabledForeground = UIUtil.getMenuItemDisabledForegroundObject();
        if (disabledForeground instanceof Color disabledColor) {
          g.setColor(disabledColor);
          BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontMetrics.getAscent());
        }
        else{
          g.setColor(menuItem.getBackground().brighter());
          BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontMetrics.getAscent());
          g.setColor(menuItem.getBackground().darker());
          BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex, ourTextRect.x - 1,
                                                       (ourTextRect.y + fontMetrics.getAscent()) - 1);
        }
      }
    }
    if (secondaryIcon != null) {
      IconUtil.paintSelectionAwareIcon(secondaryIcon, menuItem, g, ourSecondaryIconRect.x, ourSecondaryIconRect.y, isSelected(menuItem));
    }
    if (keyStrokeText != null && !keyStrokeText.isEmpty()) {
      g.setFont(acceleratorFont);
      if (buttonModel.isEnabled()) {
        if (UIUtil.isUnderAquaBasedLookAndFeel() && isSelected(menuItem)) {
          g.setColor(selectionForeground);
        }
        else {
          if (isSelected(menuItem)) {
            g.setColor(acceleratorSelectionForeground);
          }
          else {
            g.setColor(acceleratorForeground);
          }
        }
        BasicGraphicsUtils.drawString(g, keyStrokeText, 0, ourAcceleratorRect.x, ourAcceleratorRect.y + keyStrokeMetrics.getAscent());
      }
      else
        if (disabledForeground != null) {
          g.setColor(disabledForeground);
          BasicGraphicsUtils.drawString(g, keyStrokeText, 0, ourAcceleratorRect.x, ourAcceleratorRect.y + keyStrokeMetrics.getAscent());
        }
        else {
          g.setColor(menuItem.getBackground().brighter());
          BasicGraphicsUtils.drawString(g, keyStrokeText, 0, ourAcceleratorRect.x, ourAcceleratorRect.y + keyStrokeMetrics.getAscent());
          g.setColor(menuItem.getBackground().darker());
          BasicGraphicsUtils.drawString(g, keyStrokeText, 0, ourAcceleratorRect.x - 1,
                                        (ourAcceleratorRect.y + keyStrokeMetrics.getAscent()) - 1);
        }
    }
    if (arrowIcon != null) {
      if (isSelected(menuItem)) {
        g.setColor(selectionForeground);
      }
      if (useCheckAndArrow()){
        IconUtil.paintSelectionAwareIcon(arrowIcon, comp, g, ourArrowIconRect.x, ourArrowIconRect.y, isSelected(menuItem));
      }
    }
    g.setColor(oldColor);
    g.setFont(oldFont);
  }
@Override
  public void paint(Graphics g, JComponent comp)