//
// Visuzalization module for TETDM 
// ScoreDist.java Version 0.30
// Copyright(C) 2011 WATARU SUNAYAMA ALL RIGHTS RESERVED.
//
// This program is provided under the license.
// You should read the README file.
//

package module.VisualizationModules.ScoreDist;		// Replace ALL [VisualizationStyle] with your [module name]

import source.*;
import source.TextData.*;
//import source.Utility.*;

import java.awt.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;


public class ScoreDist extends VisualizationModule
{
	int width;
	
	int lightscore[];
	int data_num;	
	
	public ScoreDist()
	{
		setModuleID(4);			// Set your module ID after you have got it
	}
	
	public void initializePanel(){}
	
	public void initializeData()
	{
		data_num = 1;
		lightscore = new int[data_num];	
	}
	
	public void displayOperations(int optionNumber)
	{
		switch(optionNumber)
		{
			case 0:			
				repaint();
				break;
		}		
	}
	
	public void setData(int dataID, double score[])
	{
		switch(dataID)
		{
			case 2:
				data_num = score.length;
				//		System.out.println("score.length"+data_num);
				lightscore = new int[data_num];
				for(int i=0;i<data_num;i++)
					lightscore[i] = (int)score[i];
				repaint();
				break;
		}
	}
	
//	public void setFont(){}	
	
	//background
	public void draw_background(Graphics2D g2)
	{
		getPanelSize();
		
		width = (sizeY-10)/data_num;		
		
        g2.setColor(Color.black);
        g2.fillRect(0,0, sizeX, sizeY);
        g2.setColor(Color.white);
		g2.drawRect(10,10, sizeX-20, data_num*width);
		g2.drawLine(sizeX*2/3,10,sizeX*2/3,10+data_num*width);	//410
	}
	
	public void draw_distribution(Graphics2D g2)
	{
		int max = 1;
		
		for(int i=0;i<data_num;i++)
			if(lightscore[i] > max)
				max = lightscore[i];
		
        g2.setColor(Color.yellow);
		for(int i=0;i<data_num;i++)
			g2.fillRect(10,10+width*i, (sizeX-20)*lightscore[i]/max, width);			
	}
	
	//////////paint
	public void paintComponent(Graphics g)
	{
		Graphics2D g2 = (Graphics2D)g;
		
		draw_background(g2);		//background
		draw_distribution(g2);
	}
	
	public void update(Graphics g)		//avoid from blinking
	{
		paintComponent(g);
	}	
}