package yi.iu.ui;

import yi.iu.ui.*;
import java.beans.*;
import java.awt.*;

public class InfoFrame extends yi.iu.ui.DisplayFrame
{
    int[] info= null;
    int[][] info_2=null;
    
    boolean VERBOSE=true;

	public java.awt.Label specLabel = new java.awt.Label();

	public InfoFrame()
	{
	    super();
		setSize(402,346);
		specLabel.setAlignment(java.awt.Label.LEFT);
		add(specLabel);
		specLabel.setBounds(84,310,227,23);
	}
	
	public InfoFrame(int[] data, int w, int h) {
	    super(data,w,h);
		int dw=0;
		if (w<128) dw=(128-w)/2;
		setSize(w+24+dw*2,h+96);
		imageViewer.setBounds(12+dw,12,w,h);
		infLabel.setBounds(w/2+12-112+dw,h+36,224,24);
		specLabel.setAlignment(java.awt.Label.LEFT);
		add(specLabel);
		specLabel.setBounds(w/2+12-112+dw,h+72,224,24);
		//specLabel.setAlignment(java.awt.Label.LEFT);
	}
	
	public InfoFrame(int[] data, int w, int h, int[] _info)
	{
	    this(data,w,h);
	    info=_info;
	}
	
    public InfoFrame(String name, int[] data, int w, int h)
	{
  	    this(data,w,h);
        setTitle(name);
	}

   	public InfoFrame(String title, int[] data, int w, int h, int[] _info)
	{
	    this(title, data,w,h);
	    info=_info;
	}
	
	public InfoFrame(String title, int[] data, int w, int h, int[][] _info)
	{
	    this(title, data,w,h);
	    info_2=_info;
	}
	
	public void displayInfo(int x, int y)
	{
		int rgb= imageData[y*width+x];
		int r=rgb>>16&255,g=rgb>>8&255,b=rgb&255;
		infLabel.setText("("+x+","+y+"): "+"RGB("+r+","+g+","+b+")");
		if (info!=null) specLabel.setText(info[y*width+x]+" ");
		if (info_2!=null) {
		    String s="";
		    int index=y*width+x;
		    for (int i=0;i<info_2[index].length;i++) s=s+info_2[index][i]+" ";
		    specLabel.setText(s);
		}
	}

	public void selectInfo(int x1, int y1, int x2, int y2)
	{
		if (info_2!=null) {
		    int info_len=info_2[0].length;
		    if (x1>x2) {int temp=x2;x2=x1;x1=temp;}
		    if (y1>y2) {int temp=y2;y2=y1;y1=temp;}
		    String s="";
		    for (int i=0;i<info_len;i++) {
		        int sum=0;
		        for (int y=y1;y<=y2;y++) {
		            for (int x=x1;x<=x2;x++) {
		                int index= y*width+x;
		                sum+= info_2[index][i];
		            }
		        }
		        sum/=(y2-y1+1)*(x2-x1+1);
		        long v=0;
		        for (int y=y1;y<=y2;y++) {
		            for (int x=x1;x<=x2;x++) {
		                int index= y*width+x;
		                int d=info_2[index][i]-sum;
		                v+= d*d;
		            }
		        }
		        v/=(y2-y1+1)*(x2-x1+1);
		        v=(long)Math.sqrt(v);
		        s=s+"{"+sum+","+v+"} ";
		    }
		    specLabel.setText(s);
		    if (true) System.err.println(s);
		}
	}


	//{{DECLARE_CONTROLS
	//}}

	//{{DECLARE_MENUS
	//}}

}