Java Code Examples for sun.swing.MenuItemLayoutHelper

The following examples show how to use sun.swing.MenuItemLayoutHelper. These examples are extracted from open source projects. 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
static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
Example 2
Source Project: jdk8u_jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh,
                          MenuItemLayoutHelper.LayoutResult lr) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    paintCheckIcon(g, lh, lr);
    paintIcon(g, lh, lr);
    paintText(g, lh, lr);
    paintAccText(g, lh, lr);
    paintArrowIcon(g, lh, lr);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}
 
Example 3
Source Project: darklaf   Source File: DarkMenuItemUIBase.java    License: MIT License 6 votes vote down vote up
protected void paintIcon(final Graphics g, final JMenuItem mi, final MenuItemLayoutHelper lh,
                         final MenuItemLayoutHelper.LayoutResult lr, final Color holdc) {
    if (lh.getIcon() != null) {
        Icon icon;
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            icon.paintIcon(mi, g, lr.getIconRect().x, lr.getIconRect().y);
            g.setColor(holdc);
        }
    }
}
 
Example 4
Source Project: openjdk-8   Source File: SynthMenuItemUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 5
static void paintText(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (!lh.getText().equals("")) {
        if (lh.getHtmlView() != null) {
            // Text is HTML
            lh.getHtmlView().paint(g, lr.getTextRect());
        } else {
            // Text isn't HTML
            g.setColor(lh.getStyle().getColor(
                    lh.getContext(), ColorType.TEXT_FOREGROUND));
            g.setFont(lh.getStyle().getFont(lh.getContext()));
            lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(),
                    lr.getTextRect().x, lr.getTextRect().y,
                    lh.getMenuItem().getDisplayedMnemonicIndex());
        }
    }
}
 
Example 6
Source Project: seaglass   Source File: SeaGlassGraphicsUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon,
    String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SeaGlassLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SeaGlassMenuItemLayoutHelper lh = new SeaGlassMenuItemLayoutHelper(context, accContext, mi, checkIcon, arrowIcon, viewRect,
        defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example 7
Source Project: jdk8u_jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paint(SynthContext context, SynthContext accContext, Graphics g,
           Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter,
           int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
            context, accContext, mi, checkIcon, arrowIcon, viewRect,
            defaultTextIconGap, acceleratorDelimiter, leftToRight,
            MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example 8
Source Project: seaglass   Source File: SeaGlassGraphicsUtils.java    License: Apache License 2.0 6 votes vote down vote up
static void paintText(Graphics g, SeaGlassMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (!lh.getText().equals("")) {
        if (lh.getHtmlView() != null) {
            // Text is HTML
            lh.getHtmlView().paint(g, lr.getTextRect());
        } else {
            // Text isn't HTML
            g.setColor(lh.getStyle().getColor(
                    lh.getContext(), ColorType.TEXT_FOREGROUND));
            g.setFont(lh.getStyle().getFont(lh.getContext()));
            lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(),
                    lr.getTextRect().x, lr.getTextRect().y,
                    lh.getMenuItem().getDisplayedMnemonicIndex());
        }
    }
}
 
Example 9
Source Project: jdk8u-jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
Example 10
Source Project: jdk8u-jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paint(SynthContext context, SynthContext accContext, Graphics g,
           Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter,
           int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
            context, accContext, mi, checkIcon, arrowIcon, viewRect,
            defaultTextIconGap, acceleratorDelimiter, leftToRight,
            MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example 11
Source Project: dragonwell8_jdk   Source File: SynthMenuUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 12
static void paint(SynthContext context, SynthContext accContext, Graphics g,
           Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter,
           int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
            context, accContext, mi, checkIcon, arrowIcon, viewRect,
            defaultTextIconGap, acceleratorDelimiter, leftToRight,
            MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example 13
Source Project: jdk8u-jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh,
                          MenuItemLayoutHelper.LayoutResult lr) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    paintCheckIcon(g, lh, lr);
    paintIcon(g, lh, lr);
    paintText(g, lh, lr);
    paintAccText(g, lh, lr);
    paintArrowIcon(g, lh, lr);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}
 
Example 14
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh,
                          MenuItemLayoutHelper.LayoutResult lr) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    paintCheckIcon(g, lh, lr);
    paintIcon(g, lh, lr);
    paintText(g, lh, lr);
    paintAccText(g, lh, lr);
    paintArrowIcon(g, lh, lr);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}
 
Example 15
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 16
Source Project: hottub   Source File: SynthMenuUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 17
Source Project: hottub   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
Example 18
Source Project: jdk8u60   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintText(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (!lh.getText().equals("")) {
        if (lh.getHtmlView() != null) {
            // Text is HTML
            lh.getHtmlView().paint(g, lr.getTextRect());
        } else {
            // Text isn't HTML
            g.setColor(lh.getStyle().getColor(
                    lh.getContext(), ColorType.TEXT_FOREGROUND));
            g.setFont(lh.getStyle().getFont(lh.getContext()));
            lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(),
                    lr.getTextRect().x, lr.getTextRect().y,
                    lh.getMenuItem().getDisplayedMnemonicIndex());
        }
    }
}
 
Example 19
Source Project: jdk8u60   Source File: SynthMenuItemUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 20
Source Project: hottub   Source File: SynthMenuItemUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 21
Source Project: jdk8u-jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
Example 22
Source Project: JDKSourceCode1.8   Source File: SynthGraphicsUtils.java    License: MIT License 6 votes vote down vote up
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh,
                          MenuItemLayoutHelper.LayoutResult lr) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    paintCheckIcon(g, lh, lr);
    paintIcon(g, lh, lr);
    paintText(g, lh, lr);
    paintAccText(g, lh, lr);
    paintArrowIcon(g, lh, lr);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}
 
Example 23
Source Project: jdk8u-jdk   Source File: SynthMenuUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 24
Source Project: JDKSourceCode1.8   Source File: SynthGraphicsUtils.java    License: MIT License 6 votes vote down vote up
static void paintText(Graphics g, SynthMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (!lh.getText().equals("")) {
        if (lh.getHtmlView() != null) {
            // Text is HTML
            lh.getHtmlView().paint(g, lr.getTextRect());
        } else {
            // Text isn't HTML
            g.setColor(lh.getStyle().getColor(
                    lh.getContext(), ColorType.TEXT_FOREGROUND));
            g.setFont(lh.getStyle().getFont(lh.getContext()));
            lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(),
                    lr.getTextRect().x, lr.getTextRect().y,
                    lh.getMenuItem().getDisplayedMnemonicIndex());
        }
    }
}
 
Example 25
Source Project: JDKSourceCode1.8   Source File: SynthMenuItemUI.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                                 Icon checkIcon,
                                                 Icon arrowIcon,
                                                 int defaultTextIconGap) {
    SynthContext context = getContext(c);
    SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
    Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
            context, accContext, c, checkIcon, arrowIcon,
            defaultTextIconGap, acceleratorDelimiter,
            MenuItemLayoutHelper.useCheckAndArrow(menuItem),
            getPropertyPrefix());
    context.dispose();
    accContext.dispose();
    return value;
}
 
Example 26
Source Project: jdk8u-jdk   Source File: SynthGraphicsUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh,
                          MenuItemLayoutHelper.LayoutResult lr) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    paintCheckIcon(g, lh, lr);
    paintIcon(g, lh, lr);
    paintText(g, lh, lr);
    paintAccText(g, lh, lr);
    paintArrowIcon(g, lh, lr);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}
 
Example 27
Source Project: darklaf   Source File: DarkRadioButtonMenuItemUI.java    License: MIT License 5 votes vote down vote up
@Override
protected MenuItemLayoutHelper getMenuItemLayoutHelper(final Icon checkIcon, final Icon arrowIcon,
                                                       final int defaultTextIconGap, final JMenuItem mi,
                                                       final Rectangle viewRect) {
    if (mi.getIcon() == null) {
        layoutDelegate.setDelegate(mi);
        return super.getMenuItemLayoutHelper(null, arrowIcon, defaultTextIconGap, layoutDelegate, viewRect);
    } else {
        return super.getMenuItemLayoutHelper(checkIcon, arrowIcon, defaultTextIconGap, mi, viewRect);
    }
}
 
Example 28
Source Project: darklaf   Source File: DarkRadioButtonMenuItemUI.java    License: MIT License 5 votes vote down vote up
@Override
protected void paintCheckIcon(final Graphics g2, final JMenuItem mi,
                              final MenuItemLayoutHelper lh,
                              final MenuItemLayoutHelper.LayoutResult lr,
                              final Color holdc, final Color foreground) {
    Rectangle rect = lr.getCheckRect();
    if (mi.getIcon() == null) {
        rect.y = lr.getIconRect().y;
        rect.height = lr.getIconRect().height;
    }
    getStateIcon(mi).paintIcon(mi, g2, rect.x, rect.y + iconBaselineOffset);
}
 
Example 29
Source Project: darklaf   Source File: DarkMenuItemUIBase.java    License: MIT License 5 votes vote down vote up
private static void rightAlignAccText(final MenuItemLayoutHelper lh,
                                      final MenuItemLayoutHelper.LayoutResult lr) {
    Rectangle accRect = lr.getAccRect();
    ButtonModel model = lh.getMenuItem().getModel();
    if (model.isEnabled()) {
        accRect.x = lh.getViewRect().x + lh.getViewRect().width
                    - lh.getMenuItem().getIconTextGap() - lr.getAccRect().width;
    }
}
 
Example 30
Source Project: darklaf   Source File: DarkMenuItemUIBase.java    License: MIT License 5 votes vote down vote up
protected void paintMenuItem(final Graphics g, final JComponent c,
                             final Icon checkIcon, final Icon arrowIcon,
                             final Color background, final Color foreground,
                             final int defaultTextIconGap) {
    // Save original graphics font and color
    Font holdf = g.getFont();
    Color holdc = g.getColor();

    JMenuItem mi = (JMenuItem) c;
    g.setFont(mi.getFont());

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    DarkUIUtil.applyInsets(viewRect, mi.getInsets());

    MenuItemLayoutHelper lh = getMenuItemLayoutHelper(checkIcon, arrowIcon, defaultTextIconGap, mi, viewRect);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintBackground(g, mi, background);
    paintCheckIcon(g, mi, lh, lr, holdc, foreground);
    paintIcon(g, mi, lh, lr, holdc);
    g.setColor(foreground);
    paintText(g, mi, lh, lr);
    paintAccText(g, mi, lh, lr);
    paintArrowIcon(g, mi, lh, lr, foreground);

    // Restore original graphics font and color
    g.setColor(holdc);
    g.setFont(holdf);
}