/*
 * @(#)WindowsMenuItemUI.java	1.16 01/01/26
 *
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */

package com.sun.java.swing.plaf.windows;

import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;


/**
 * Windows rendition of the component.
 * <p>
 * <strong>Warning:</strong>
 * Serialized objects of this class will not be compatible with
 * future Swing releases.  The current serialization support is appropriate
 * for short term storage or RMI between applications running the same
 * version of Swing.  A future release of Swing will provide support for
 * long term persistence.
 */
public class WindowsMenuItemUI extends BasicMenuItemUI {

    public static ComponentUI createUI(JComponent c) {
	return new WindowsMenuItemUI();
    }

    /**
     * Method which renders the text of the current menu item.
     * <p>
     * @param g Graphics context
     * @param menuItem Current menu item to render
     * @param textRect Bounding rectangle to render the text.
     * @param text String to render
     */
    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
	ButtonModel model = menuItem.getModel();
	FontMetrics fm = g.getFontMetrics();
	int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
	// W2K Feature: Check to see if the Underscore should be rendered.
	if (WindowsLookAndFeel.isMnemonicHidden() == true) {
	    mnemonicIndex = -1;
	}

	if(!model.isEnabled()) {
	    // *** paint the text disabled
	    if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {
		g.setColor( UIManager.getColor("MenuItem.disabledForeground") );
		BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
                                              mnemonicIndex,
					      textRect.x, 
					      textRect.y + fm.getAscent());
	    } else {
		g.setColor(menuItem.getBackground().brighter());
		BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
                                              mnemonicIndex, 
					      textRect.x, 
					      textRect.y + fm.getAscent());
		g.setColor(menuItem.getBackground().darker());
		BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
                                              mnemonicIndex, 
					      textRect.x - 1, 
					      textRect.y + fm.getAscent() - 1);
	    }
	} else {
	    // *** paint the text normally
	    if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
		g.setColor(selectionForeground); // Uses protected field.
	    }
	    BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
                                          mnemonicIndex,
					  textRect.x, 
					  textRect.y + fm.getAscent());
	}
    }

}

