Java Code Examples for sun.swing.MenuItemLayoutHelper#createMaxRect()

The following examples show how to use sun.swing.MenuItemLayoutHelper#createMaxRect() . 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
Source File: SynthGraphicsUtils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 2
Source File: SynthGraphicsUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 3
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 4 votes vote down vote up
public static Dimension getPreferredMenuItemSize(SynthContext context, SynthContext accContext, JComponent c, Icon checkIcon,
    Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter, boolean useCheckAndArrow, String propertyPrefix) {

    JMenuItem mi = (JMenuItem) c;
    SeaGlassMenuItemLayoutHelper lh = new SeaGlassMenuItemLayoutHelper(context, accContext, mi, checkIcon, arrowIcon,
        MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap, acceleratorDelimiter, SeaGlassLookAndFeel.isLeftToRight(mi),
        useCheckAndArrow, propertyPrefix);

    Dimension result = new Dimension();

    // Calculate the result width
    int gap = lh.getGap();
    result.width = 0;
    MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
    MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
    MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
    // The last gap is unnecessary
    result.width -= gap;

    // Calculate the result height
    result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(), lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
        lh.getArrowSize().getHeight());

    // Take into account menu item insets
    Insets insets = lh.getMenuItem().getInsets();
    if (insets != null) {
        result.width += insets.left + insets.right;
        result.height += insets.top + insets.bottom;
    }

    // if the width is even, bump it up one. This is critical
    // for the focus dash lhne to draw properly
    if (result.width % 2 == 0) {
        result.width++;
    }

    // if the height is even, bump it up one. This is critical
    // for the text to center properly
    if (result.height % 2 == 0) {
        result.height++;
    }

    return result;

}
 
Example 4
Source File: SynthGraphicsUtils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 5
Source File: SynthGraphicsUtils.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 6
Source File: SynthGraphicsUtils.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 7
Source File: SynthGraphicsUtils.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 8
Source File: SynthGraphicsUtils.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 9
Source File: SynthGraphicsUtils.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 10
Source File: SynthGraphicsUtils.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 11
Source File: SynthGraphicsUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 12
Source File: SynthGraphicsUtils.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 13
Source File: SynthGraphicsUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 14
Source File: SynthGraphicsUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 15
Source File: SynthGraphicsUtils.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 16
Source File: SynthGraphicsUtils.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 17
Source File: SynthGraphicsUtils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }
 
Example 18
Source File: SynthGraphicsUtils.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * A quick note about how preferred sizes are calculated... Generally
  * speaking, SynthPopupMenuUI will run through the list of its children
  * (from top to bottom) and ask each for its preferred size.  Each menu
  * item will add up the max width of each element (icons, text,
  * accelerator spacing, accelerator text or arrow icon) encountered thus
  * far, so by the time all menu items have been calculated, we will
  * know the maximum (preferred) menu item size for that popup menu.
  * Later when it comes time to paint each menu item, we can use those
  * same accumulated max element sizes in order to layout the item.
  */
static Dimension getPreferredMenuItemSize(SynthContext context,
       SynthContext accContext, JComponent c,
       Icon checkIcon, Icon arrowIcon, int defaultTextIconGap,
       String acceleratorDelimiter, boolean useCheckAndArrow,
       String propertyPrefix) {

     JMenuItem mi = (JMenuItem) c;
     SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper(
             context, accContext, mi, checkIcon, arrowIcon,
             MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
             acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi),
             useCheckAndArrow, propertyPrefix);

     Dimension result = new Dimension();

     // Calculate the result width
     int gap = lh.getGap();
     result.width = 0;
     MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result);
     MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result);
     MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result);
     // The last gap is unnecessary
     result.width -= gap;

     // Calculate the result height
     result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
             lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
             lh.getArrowSize().getHeight());

     // Take into account menu item insets
     Insets insets = lh.getMenuItem().getInsets();
     if (insets != null) {
         result.width += insets.left + insets.right;
         result.height += insets.top + insets.bottom;
     }

     // if the width is even, bump it up one. This is critical
     // for the focus dash lhne to draw properly
     if (result.width % 2 == 0) {
         result.width++;
     }

     // if the height is even, bump it up one. This is critical
     // for the text to center properly
     if (result.height % 2 == 0) {
         result.height++;
     }

     return result;
 }