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

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;

public class PopupMenu_forRegionSS extends JPopupMenu {

	private static final long serialVersionUID = -6251397654271977789L;
	RegionSS region;
	PInputEvent ie;
	PCanvas canvas;
	
	public PopupMenu_forRegionSS(RegionSS assg, PInputEvent _ie, PCanvas _canvas /*, JFrame _frame*/) {
		region = assg;
		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("check");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0));//メニュー表示時のショートカットキー
		menuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					region.checkSS();
			}
		});
		
		menuItem = new JMenuItem("delete");
		add(menuItem);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0));//メニュー表示時のショートカットキー
		menuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					region.delete();
			}
		});
		
		
		showPopup();
	}

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

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