package jp.ac.kyutech.mns.ist;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;

import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.event.PInputEventListener;
import edu.umd.cs.piccolo.nodes.PText;

public class InspectorPanel extends JPanel {

	private static final long serialVersionUID = 1137383242193843501L;
	JFrame jf;
	InspectorHandler handler;
	ArrayList<PNode> pnlist = new ArrayList<PNode>();
	public InspectorPanel(JFrame f, InspectorHandler h){
		jf = f;
		handler = h;
	}
	public void paintComponent(Graphics g){
		g.clearRect(0, 0, getWidth(), getHeight());
		int y = 13;

		for(PNode pn: pnlist){
			g.setColor(Color.black);
			g.drawString(pn.getClass().getSimpleName()+"     "+pn.hashCode(), 10, y); y+=13;

			g.drawString("xy      : "+f(pn.getX())+"  |  "+f(pn.getY()), 20, y); y+=13;
			g.drawString("wh      : "+f(pn.getWidth())+"  |  "+f(pn.getHeight()), 20, y); y+=13;
			g.setColor(Color.blue);

			g.drawString("offset: "+f(pn.getOffset().getX())+"  |  "+f(pn.getOffset().getY()), 20, y); y+=13;
			g.drawString("zoom: "+f(pn.getScale()), 20, y); y+=13;
			AffineTransform at = pn.getTransform();
			double[] d = new double[6];
			at.getMatrix(d);
			g.setColor(Color.black);
			g.drawString("affine: "+g(d[0])+"  "+g(d[2])+"  "+g(d[4]), 20, y); y+=13;
			g.drawString("         "+g(d[1])+"  "+g(d[3])+"  "+g(d[5]), 28, y); y+=13;

			g.setColor(Color.green);
			for(PInputEventListener pie: pn.getInputEventListeners()){
				if (pie.getClass().getSimpleName().length()<1){
					String fullname = pie.getClass().getName();
					int lastdotpos = fullname.lastIndexOf(".");
					g.drawString("event: "+fullname.substring(lastdotpos+1), 20, y); y+=13;
				} else {
					g.drawString("event: "+pie.getClass().getSimpleName(), 20, y); y+=13;
				}
			}
			g.setColor(Color.black);
			if (pn instanceof PText){
				g.drawString("text: "+((PText)pn).getText(), 20, y); y+=13;
			}
			if (pn instanceof ShortStroke){
				ShortStroke ss = (ShortStroke)pn;
				g.drawString("gentime: "+ss.getDateTime(), 20, y); y+=13;
			}
			g.setColor(Color.blue);
			g.drawString("children: "+pn.getChildrenCount(), 20, y); y+=13;

			y+=8;
		}
	}
	public String f(double d){
		return String.format("%5.1f", d);
	}
	public String g(double d){
		return String.format("%4.1f", d);
	}
}
