package jp.ac.kyutech.mns.ist.sheetmap;

import java.awt.Color;

import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
import edu.umd.cs.piccolo.event.PInputEvent;

/**
 * 一般的な文字列ラベルを持つPMenuItem
 * @author miuramo
 *
 */
public class PMenuItem_String extends PMenuItem_Abstract {
	private static final long serialVersionUID = 1789811891741678164L;

	public PMenuItem_String(String arg, boolean m, Color c) {
		super(arg, m, c);

		addInputEventListener(new PBasicInputEventHandler() {
			public void mouseEntered(PInputEvent e) {
				setPaint(defaultcolor);
			}

			public void mouseExited(PInputEvent e) {
				setSelected(isSelected);
			}

			public void mousePressed(PInputEvent e) {
				setPaint(Color.red);
			}

			public void mouseReleased(PInputEvent e) {
				setSelected(isSelected);
			}

			public void mouseClicked(PInputEvent e) {
//				doClick(e);
			}
		});

	}

	
	/**
	 * e がnullの場合もある．（PageBrowserのツールボタンを共通化する処理のとき）
	 */
	public void doClick(PInputEvent e) {
//		System.out.println(text + " is clicked.");
		if (al != null){
			if (e != null) e.setActionCommand(text);
			al.actionPerformed(e);
		}
		if (isToggle) {
			isSelected = !isSelected;
			parent.setSelected(PMenuItem_String.this);
		}
	}
}
