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

import java.awt.Color;
import java.awt.Dimension;

import jp.ac.kyutech.mns.ist.FocusFrame;
import jp.ac.kyutech.mns.ist.Note;
import jp.ac.kyutech.mns.ist.util.CameraFitConstraint;
import jp.ac.kyutech.mns.ist.util.CameraFitConstraint.PositionEnum;
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;
import edu.umd.cs.piccolo.nodes.PText;

public class InsideToolbar_SeatMap extends PPath {
	private static final long serialVersionUID = -7048236395728223700L;
	SeatmapController cont;
	PPath[] buttons = new PPath[6];
	//	ArrayList<PPath> palettes;
	String[] lbls = {"Home", "0", "90","180","270","Layout"};
	public InsideToolbar_SeatMap(SeatmapController _satn){
		cont = _satn;

		int pos = 0;
		for(int i=0;i<6;i++){
			PPath p = PPath.createRectangle(0, 0, lbls[i].length()*10+20, 25);
			p.setPaint(Color.orange);
			PText pt = new PText(lbls[i]);
			pt.setScale(1.4f);
			pt.setOffset((p.getWidth()-pt.getWidth()*pt.getScale())/2,(p.getHeight()-pt.getHeight()*pt.getScale())/2);
			p.addChild(pt);
			pt.setPickable(false);
			addChild(p);
			p.offset( pos, 0);
			pos += p.getWidth();
			buttons[i]=p;
			p.addAttribute("nozoom", true);
			p.addAttribute("label", lbls[i]);

			p.addInputEventListener(new PBasicInputEventHandler(){
				public void mouseEntered(PInputEvent e){
					PNode pn = e.getPickedNode();
					if (pn instanceof PPath){
						((PPath)e.getPickedNode()).setStroke(Note.getCachedBasicStroke(2f));
						e.getPickedNode().moveToFront();
					}
					//						InsideToolbar_SheetVisible.this.setVisible(true);
				}
				public void mousePressed(PInputEvent e){
					PNode pn = e.getPickedNode();
					if (pn instanceof PPath){
						String lbl = (String)((PPath)e.getPickedNode()).getAttribute("label");
						System.out.println(lbl);
						if (lbl.equals("0")){
							cont.setWorldRotation(0);
						} else if (lbl.equals("90")){
							cont.setWorldRotation(1);
						} else if (lbl.equals("180")){
							cont.setWorldRotation(2);
						} else if (lbl.equals("270")){
							cont.setWorldRotation(3);
						} else if (lbl.equals("Home")){
							cont.home();
							cont.satn.upview(-1);
							for(FocusFrame ff: FocusFrame.frames){
								ff.upview(-1);
							}
							
						} else if (lbl.equals("Layout")){
							cont.satn.upview(-1);
							for(FocusFrame ff: FocusFrame.frames){
								ff.sortBySeat();
							}
						}
						updateStatus();
					}
				}
				public void mouseExited(PInputEvent e){
					PNode pn = e.getPickedNode();
					if (pn instanceof PPath){
						((PPath)e.getPickedNode()).setStroke(Note.getCachedBasicStroke(1f));
					}
				}
			});
		}

		//		satn.getCanvas().getCamera().addChild(this);
		setBounds(getFullBoundsReference());
		//		fitToFR();

		CameraFitConstraint cfc = new CameraFitConstraint(this, cont.getCamera(), PositionEnum.TOPLEFT, new Dimension(0,0));
		cfc.fitTo(cont.getCamera().getBoundsReference());
		cont.getCamera().addPropertyChangeListener(cfc);

		setTransparency(0.8f);
		setVisible(false);

	}
	public void setVisible(boolean f){
		super.setVisible(f);
		updateStatus();
	}
	public void updateStatus(){
	}
}
