Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap) {
JMenuItem b = (JMenuItem) c;
ButtonModel model = b.getModel();
int menuWidth = b.getWidth();
int menuHeight = b.getHeight();
resetRects();
viewRect.setBounds( 0, 0, menuWidth, menuHeight );
Font holdf = g.getFont();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = c.getFontMetrics(f);
// get Accelerator text
KeyStroke accelerator = b.getAccelerator();
String acceleratorText = "";
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+";
}
int keyCode = accelerator.getKeyCode();
if (keyCode != 0)
acceleratorText += KeyEvent.getKeyText(keyCode);
else
acceleratorText += accelerator.getKeyChar();
}
// layout the text and icon
String text = layoutMenuItem(
fm, b.getText(), acceleratorText, b.getIcon(),
checkIcon, arrowIcon,
viewRect, iconRect, textRect, acceleratorRect,
b.getText() == null ? 0 : defaultTextIconGap,
defaultTextIconGap
);
// Paint background
paintBackground(g, b, background);
Color holdc = g.getColor();
// Paint the Check
boolean isCheckOrRadio = (c instanceof JCheckBoxMenuItem) ||
(c instanceof JRadioButtonMenuItem);
if (checkIcon != null && isCheckOrRadio)
paintCheck(g, menuItem);
// Paint the Icon
if(b.getIcon()!=null && !isCheckOrRadio)
paintIcon(g, menuItem);
// Draw the Text
paintText(g, b, textRect, text);
// Draw the Accelerator Text
if(!acceleratorText.equals("")) {
//Get the maxAccWidth from the parent to calculate the offset.
int accOffset = 0;
Container parent = menuItem.getParent();
if (parent != null && parent instanceof JComponent) {
JComponent p = (JComponent) parent;
Integer maxValueInt = (Integer) p.getClientProperty(OfficeXPMenuItemUI.MAX_ACC_WIDTH);
int maxValue = maxValueInt != null ?
maxValueInt.intValue() : acceleratorRect.width;
//Calculate the offset, with which the accelerator texts will be drawn.
accOffset = maxValue - acceleratorRect.width;
}
// Ensure all accelerators are right-aligned for RTL.
if (!c.getComponentOrientation().isLeftToRight()) {
Integer maxValueInt = null;
if (parent!=null && parent instanceof JComponent) {
maxValueInt = (Integer)((JComponent)b.getParent()).
getClientProperty(OfficeXPMenuItemUI.MAX_ACC_WIDTH);
}
int maxValue = maxValueInt!=null ? maxValueInt.intValue() :
acceleratorRect.width;
accOffset = 0;
acceleratorRect.x = 20 + maxValue - acceleratorRect.width;
}
if(!model.isEnabled()) {
// *** paint the acceleratorText disabled
if ( disabledForeground != null ) {
g.setColor( disabledForeground );
OfficeXPGraphicsUtils.drawString(g,fm,acceleratorText,0,