px += insets.left;
py += insets.top;
}
if (menu != null) {
Action m = null;
FontMetrics fm = getFontMetrics(getFont());
// py += fm.getHeight() - fm.getDescent();
int i = 0;
for (Enumeration e = menu.children(); e.hasMoreElements();) {
m = (Action) e.nextElement();
if(m.getName().equals(ActionMenu.SEPARATOR.getName())) {
int h = separator.getPreferredSize().height;
int sw = s.width - ( insets == null ? 0 : ( ( insets.left + insets.right ) / 2 ) ) - ( borderWidth * 2 );
separator.setBounds(0, 0, sw, h);
int sx = (s.width - sw ) / 2;
g.translate(sx, py);
separator.paint(g);
g.translate(-sx, -py);
py += h;
}
else {
String n = (String) m.getValue(Action.SHORT_DESCRIPTION);
n = n == null ? m.getName() : n;
if (m.isEnabled()) {
if (i == sel) {
g.setColor(selectionBackground);
int ty = borderWidth + (insets != null ? insets.top : 0) + (py - borderWidth - insets.top );
g.fillRect(borderWidth, ty, s.width - (borderWidth * 2), itemHeight);
if (borderWidth != 0) {
g.setColor(borderColor);
g.drawLine(borderWidth, ty, (borderWidth * 2) + s.width - 1, ty);
g.drawLine(borderWidth, ty + itemHeight - 1, (borderWidth * 2) + s.width - 1, ty + itemHeight - 1);
}
g.setColor(selectionForeground);
} else {
g.setColor(getForeground());
}
} else {
g.setColor(disabledForeground);
}
String imagePath = null;
if (iconType.equals(ActionButton.SMALL_ICONS)) {
imagePath = (String) m.getValue(Action.SMALL_IMAGE_PATH);
} else if (iconType.equals(ActionButton.LARGE_ICONS)) {
imagePath = (String) m.getValue(Action.IMAGE_PATH);
}
int toff = 0;
if (imagePath != null) {
Image img = UIUtil.loadImage(m.getClass(), imagePath);
if(!m.isEnabled()) {
img = createImage(new FilteredImageSource(img.getSource(),
new GrayFilter()));
UIUtil.waitFor(img, this);
}
if (img != null) {
g.drawImage(img, px, py + ((itemHeight - img.getHeight(this)) / 2), this);
toff = imageTextGap + img.getWidth(this);
}
}
g.drawString(n, px + toff, py + fm.getHeight() - fm.getDescent() + ((itemHeight - fm.getHeight()) / 2));
py += itemHeight;
}
i++;
}
}