package jp.ac.kyutech.mns.ist;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;

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

/**
 * フォーカスソース（メインウィンドウ上でドラッグして作成した領域）上での右クリックメニュー
 * @author miuramo
 *
 */
public class PopupMenu_forFS extends JPopupMenu {
	private static final long serialVersionUID = 7741402910818721975L;

	FocusSrc fsrc;
	PInputEvent ie;
	PCanvas canvas;

	public PopupMenu_forFS(FocusSrc aFR, PInputEvent _ie, PCanvas _canvas /*, JFrame _frame*/) {
		fsrc = aFR;
		ie = _ie;
		canvas = _canvas;

		setLightWeightPopupEnabled(false);

		JMenuItem menuItem;

		menuItem = new JMenuItem("cancel");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));//メニュー表示時のショートカットキー

		addSeparator();

		menuItem = new JMenuItem("focus on FocusFrame");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 0));//メニュー表示時のショートカットキー
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fsrc.fframe.toFront();
				fsrc.fframe.focus(fsrc.getNote().getNum());
			}
		});
		
		menuItem = new JMenuItem("toggle focus/reference (from Focus Src)");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0));//メニュー表示時のショートカットキー
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fsrc.fframe.toggleFocusReference();
			}
		});
		
		menuItem = new JMenuItem("delete");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));//メニュー表示時のショートカットキー
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fsrc.fframe.delete();
			}
		});

		showPopup();
	}

	public void showPopup() {
		Point2D cp = ie.getPositionRelativeTo(canvas.getCamera());

		show(canvas, (int)cp.getX(), (int)cp.getY());
	}
}
