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;

public class Event_onSheet extends PBasicInputEventHandler {
	Sheet sheet;

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

	public Event_onSheet(Sheet _sheet) {
		sheet = _sheet;
	}
	public void mouseEntered(PInputEvent aEvent){
		sheet.isshowImage(true);
		
		FocusFrame.updateFocusReference(sheet.getNote().penid);
		
		//ポップアップ
		sheet.getNote().satn.showSheetInfoOnCamera(sheet,true);
	}
	public void mouseExited(PInputEvent aEvent){
		sheet.isshowImage(false);
		
		//ポップアップ消す
		sheet.getNote().satn.showSheetInfoOnCamera(sheet,false);
	}

	public void mousePressed(final PInputEvent aEvent) {
		pressEv = aEvent;
		pressN = aEvent.getPickedNode();
		dragCount = 0;
		System.out.println(pressN.globalToLocal(aEvent.getPosition()).toString());
	}
	public void mouseDragged(final PInputEvent aEvent) {
		dragCount++;
	}
	public void mouseReleased(final PInputEvent aEvent) {
//		System.out.println("zoomlevel = "+SimpleATN.theapp.getZoomLevel());
		if (dragCount < 3){
			if (pressEv.getButton()==MouseEvent.BUTTON3){
				//ポップアップメニュー
				new PopupMenu_forSheet(sheet, pressEv, sheet.canvas);
			} else if (pressEv.getButton()==MouseEvent.BUTTON1){
				if (SimpleATN.theapp.zrh.selection == null){
					//すこしでも，表示領域の高さがノートの高さよりも大きければ，getZoomLevelは0になる
					if (pressN == sheet && SimpleATN.theapp.getZoomLevel()<1) sheet.focus(aEvent);
				} else {
					//集約する
					new PopupMenu_forZoomRegion(sheet, aEvent, sheet.canvas, SimpleATN.theapp.zrh);
				}
			}
		}
	}	

}
