viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
SynthStyle style = context.getStyle();
Font f = style.getFont(context);
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
FontMetrics accFM = SwingUtilities2.getFontMetrics(c, g, accContext.getStyle().getFont(accContext));
// get Accelerator text
KeyStroke accelerator = b.getAccelerator();
String acceleratorText = "";
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += acceleratorDelimiter;
}
int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
acceleratorText += KeyEvent.getKeyText(keyCode);
} else {
acceleratorText += accelerator.getKeyChar();
}
}
// layoutl the text and icon
String text = layoutMenuItem(context, fm, accContext, b.getText(), accFM, acceleratorText, b.getIcon(), checkIcon, arrowIcon, b
.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect,
iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap,
defaultTextIconGap, useCheckAndArrow);
// Paint the Check
if (checkIcon != null && useCheckAndArrow) {
SeaGlassIcon.paintIcon(checkIcon, context, g, checkIconRect.x, checkIconRect.y, checkIconRect.width, checkIconRect.height);
}
// Paint the Icon
if (b.getIcon() != null) {
Icon icon;
if (!model.isEnabled()) {
icon = (Icon) b.getDisabledIcon();
} else if (model.isPressed() && model.isArmed()) {
icon = (Icon) b.getPressedIcon();
if (icon == null) {
// Use default icon
icon = (Icon) b.getIcon();
}
} else {
icon = (Icon) b.getIcon();
}
if (icon != null) {
SeaGlassIcon.paintIcon(icon, context, g, iconRect.x, iconRect.y, iconRect.width, iconRect.height);
}
}
// Draw the Text
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
g.setFont(style.getFont(context));
style.getGraphicsUtils(context).paintText(context, g, text, textRect.x, textRect.y, b.getDisplayedMnemonicIndex());
}
}
// Draw the Accelerator Text
if (acceleratorText != null && !acceleratorText.equals("")) {
// Get the maxAccWidth from the parent to calculate the offset.
int accOffset = 0;
Container parent = b.getParent();
if (parent != null && parent instanceof JPopupMenu) {
SeaGlassPopupMenuUI popupUI = (SeaGlassPopupMenuUI) ((JPopupMenu) parent).getUI();
if (popupUI != null) {
// Calculate the offset, with which the accelerator texts
// will be drawn with.
int max = popupUI.getMaxAcceleratorWidth();
if (max > 0) {
accOffset = max - acceleratorRect.width;
}
}
}
SynthStyle accStyle = accContext.getStyle();
g.setColor(accStyle.getColor(accContext, ColorType.TEXT_FOREGROUND));
g.setFont(accStyle.getFont(accContext));
accStyle.getGraphicsUtils(accContext).paintText(accContext, g, acceleratorText, acceleratorRect.x - accOffset,
acceleratorRect.y, -1);
}
// Paint the Arrow
if (arrowIcon != null && useCheckAndArrow) {