package jp.ac.kyutech.mns.ist;

import java.awt.Color;
import java.util.ArrayList;

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

public class FRPalette extends PPath {
	private static final long serialVersionUID = -971944466554582429L;
	FocusRectangle frect;
//	FocusFrame fframe;
	ArrayList<PPath> palettes; 
	public FRPalette(FocusRectangle fr){
//		fframe = ff;
		frect = fr;
		
		palettes = new ArrayList<PPath>();
		for(float f=0.0f; f<0.8f; f+=0.06f){
			PPath p = PPath.createRectangle(0, 0, 18, 15);
			p.setPaint(new Color(Color.HSBtoRGB(f, 0.6f, 0.7f)));
			addChild(p);
			p.offset(palettes.size()*18, 0);
			palettes.add(p);
			p.addAttribute("nozoom", true);
			
			p.addInputEventListener(new PBasicInputEventHandler(){
				public void mouseEntered(PInputEvent e){
					FRPalette.this.setVisible(true);
					frect.focussrc.sheet.isshowImage(true);
				}
				public void mousePressed(PInputEvent e){
					Color c = (Color)e.getPickedNode().getPaint();
					frect.focussrc.setColor(c);
					frect.focussrc.setPaint(c);
//					frect.event_onfr.pressEv = null;
//					e.setHandled(true);//ズームインしないため，とおもったが，エラーになるためやめる
				}
				public void mouseExited(PInputEvent e){
					FRPalette.this.setVisible(false);
					frect.focussrc.sheet.isshowImage(false);
				}
			});
		}
		PPath p = PPath.createRectangle(0, 0, 36, 15);
		p.setPaint(Color.white);
		addChild(p);
		p.offset(palettes.size()*18, 0);
		setBounds(getFullBounds());
		palettes.add(p);
		p.addAttribute("nozoom", true);
		
		p.addInputEventListener(new PBasicInputEventHandler(){
			public void mouseEntered(PInputEvent e){
				FRPalette.this.setVisible(true);
				frect.focussrc.sheet.isshowImage(true);
			}
			public void mousePressed(PInputEvent e){
				frect.focussrc.setColor(null);
				frect.focussrc.setPaint(null);
//				frect.event_onfr.pressEv = null;
//				e.setHandled(true);//ズームインしないため，とおもったが，エラーになるためやめる
			}
			public void mouseExited(PInputEvent e){
				FRPalette.this.setVisible(false);
				frect.focussrc.sheet.isshowImage(false);
			}
		});
		
		frect.addChild(this);

		fitToFR();
		
	}
	public void fitToFR(){
		setOffset(5 ,-this.getFullBounds().getHeight()*this.getScale()/3);
	}
}
