package jp.ac.kyutech.mns.ist;

import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;

import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
import edu.umd.cs.piccolo.event.PInputEvent;
import edu.umd.cs.piccolo.nodes.PPath;

public class Event_onFF extends PBasicInputEventHandler {
	FocusFrame frame;

	PInputEvent pressEv = null;
	PNode pressPN;
	Point2D pressP = null;
	int dragCount = 0;

	public Event_onFF(FocusFrame _ff) {
		frame = _ff;
	}

	public void mousePressed(final PInputEvent aEvent) {
		pressEv = aEvent;
		pressPN = aEvent.getPickedNode();
		dragCount = 0;
	}
	public void mouseDragged(final PInputEvent aEvent) {
		dragCount++;
	}
	public void mouseReleased(final PInputEvent aEvent) {
		if (pressEv == null) return;
		if (pressPN.getAttribute("nozoom") != null) return;//nozoomタグがついていたら，ズームインしない（色付けボタン:FRPaletteのPPathなので）
//		System.out.println(pressPN.getClass().getName());
		if (pressPN instanceof PPath){ //May be FocusRect
			if (dragCount < 3){
				if (pressEv.getButton()==MouseEvent.BUTTON3){
					//ポップアップメニュー
					FocusRectangle fr = (FocusRectangle) pressPN.getParent();
					new PopupMenu_forFR(fr, pressEv, frame.getCanvas());
				} else if (pressEv.getButton()==MouseEvent.BUTTON1){
					//				if (SimpleATN.theapp.zrh.selection == null){
					//					frame.focus();
					//				}
				}
			}	
		} else {
			if (dragCount < 3){
				if (pressEv.getButton()==MouseEvent.BUTTON3){
					//ポップアップメニュー
					new PopupMenu_forFF(frame, pressEv, frame.getCanvas());
				} else if (pressEv.getButton()==MouseEvent.BUTTON1){
					//				if (SimpleATN.theapp.zrh.selection == null){
					//					frame.focus();
					//				}
				}
			}	
		}
	}
	//マウスカーソルが外にでたら，ボタンを隠す
	public void mouseExited(final PInputEvent aEvent){
		frame.insideToolbar.setVisible(false);
	}
}