//
// Core Program for TETDM 
// Support.java Version 1.00
// Copyright(C) 2013-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source;

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

import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.GroupLayout.Alignment;


public class Support extends JPanel implements ActionListener
{	
	JToggleButton countbutton;
	JComboBox cb = new JComboBox();
	JScrollBar scroll_bar;
	JPanel upperpanel,basepane;
	CardLayout layout;
	JTextArea touch_task;
	
    int width;
	int frameSize = 30;
	int fontSize = frameSize - 15;
	int door_x,door_y;

	public int oldSizeX, oldSizeY;
	int sizeX,sizeY,testpane_sizeY=0;
	public double changeX, changeY;
	int scroll_pos = 0;
	int pressPointx=0,pressPointy=0;
	int movePointx=0,movePointy=0;

	Control control;
	Color base_color = new Color(0x00,0xff,0xff);
	Color click_color = new Color(0x41,0x69,0xE1);
	Color clear_color = Color.pink;
	Color thema_color = new Color(0xf0,0xff,0xff);

	PopUpForSupport popForSupport2[];
	Image [] door = new Image[3];
	
	String pic_ad;
	MakeSupportTaskData data;
	Task_Panel testpane;
	
	String version [] = {"ForUser","ForDeveloper"};
	String ver = "";
	int version_num = 0;
	
    String japaneseWords[];
	String label_name [] = {"Let's try!"," SKILL LEVEL	: "," EXP	: "};
	JTextArea texttitle[] = new JTextArea[label_name.length];
	
	int classstage_num = 0;
	
	String classstage[];
	String classStageInJapanese[];
	int modeChallenge[];
	
	Task_Panel task_list_panel[];
	MakeSupportTaskData makedata [];
	


	Support(Control control,String ver,int sizeX,int sizeY,String textname)
	{
		this.control = control;
		this.ver = ver;
		
		String input_stageinfo[];
		
		String file_add = control.absolutePath + "source" + File.separator +"operate"+ ver + File.separator;
		
		input_stageinfo = FILEIO.TextFileAllReadCodeArray(new File(file_add + ver + "_trystage.txt"));
		String [] stagestr = input_stageinfo[0].split(",");
		String [] stagestrJapanese = input_stageinfo[1].split(",");
		String [] challenge = input_stageinfo[2].split(",");		
		
		classStageInJapanese = new String[stagestr.length - 1];
		classstage = new String[stagestr.length - 1];
		modeChallenge = new int[stagestr.length - 1];
		for(int i = 1;i < stagestr.length;i++)
		{
			classstage[i-1] = stagestr[i];
			classStageInJapanese[i-1] = stagestrJapanese[i];
			modeChallenge[i-1] = Integer.parseInt(challenge[i]);
		}
			

		task_list_panel = new Task_Panel[classstage.length];
		makedata = new MakeSupportTaskData [classstage.length];
		
		this.sizeX = sizeX;
		this.sizeY = sizeY;
		
        width = getWidth();

		setLayout(new BorderLayout());
		
		this.addMouseListener(new MyMouseL());
		this.addMouseMotionListener(new MyMouseL());
		
		for(int i=0;i<classstage.length;i++){
			makedata[i] = new MakeSupportTaskData(control, this, i, version_num, "operate"+ver,textname);
		}
		
		classstage_num = Integer.parseInt(stagestr[0]);
		data = makedata[classstage_num];
		
        pic_ad = data.file_add;
        
        
		for(int i=0;i<3;i++){
			door[i] = Toolkit.getDefaultToolkit().getImage(pic_ad + "door"+(i+1)+".png");
		}
		
        japaneseWords = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "japaneseText" + File.separator+ "JapaneseSupport.txt"));
		
		upperpanel = new JPanel();
		upperpanel.setLayout(new BoxLayout(upperpanel,BoxLayout.Y_AXIS));
		add("North",upperpanel);
		
///////////////////////////classStageInJapanese

		for(int i=0;i<classstage.length;i++)
		if(modeChallenge[i] <= control.sp1.mode)	 //CHALLENGE LIMITATION BY MODE NUMBER
		{
			if(control.sp1.inJapanese)
				cb.addItem(classStageInJapanese[i]);
			else
				cb.addItem(classstage[i]);
		}
		cb.addActionListener(this);
		
		countbutton = new JToggleButton("count",false);			
		countbutton.addActionListener(this);
		countbutton.setFont(new Font(control.sp1.fontName, Font.BOLD, fontSize));
		
		JPanel upper_top_panel = new JPanel();
		upper_top_panel.setLayout(new GridLayout(1,3));
		upper_top_panel.setBackground(Color.white);
		upper_top_panel.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.white, Color.blue));
		
		for(int i=0;i<label_name.length;i++){
			texttitle[i] = new JTextArea(label_name[i]);
			texttitle[i].setFont(new Font(control.sp1.fontName, Font.BOLD, fontSize+5));
			texttitle[i].setLineWrap(true);
			texttitle[i].setEnabled(false);
			texttitle[i].setDisabledTextColor(Color.black);
			if(i == 0){
				upper_top_panel.add(texttitle[i]);
				upper_top_panel.add(cb);
				upperpanel.add(upper_top_panel);
			}else {
				texttitle[i].setBackground(new Color(0xad, 0xff, 0x2f));
				upperpanel.add(texttitle[i]);
			}
		}	
		///////////////////////////

		touch_task = new JTextArea(japaneseWords[0]);
		touch_task.setFont(new Font(control.sp1.fontName, Font.BOLD, fontSize+5));
		touch_task.setLineWrap(true);
		touch_task.setEnabled(false);
		touch_task.setBackground(Color.WHITE);
		touch_task.setDisabledTextColor(Color.black);
		touch_task.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.white, Color.black));
		upperpanel.add(touch_task);
	
		popForSupport2 = new PopUpForSupport[data.task_num];
		
		basepane = new JPanel();
		layout = new CardLayout();
		basepane.setLayout(layout);
		add("Center",basepane);
		
		for(int i = 0; i < classstage.length; i++){
			data = makedata[i];
			check_can_open();
			task_list_panel[i] = new Task_Panel(control,data,this,sizeX,sizeY,i);
			task_list_panel[i].addMouseListener(new MyMouseL());
			task_list_panel[i].addMouseMotionListener(new MyMouseL());
			basepane.add(task_list_panel[i],classstage[i]);
		}

		data = makedata[classstage_num];
		cb.setSelectedIndex(classstage_num);
		layout.show(basepane,classstage[classstage_num]);
		
//		countpanel = new Count_Panel(control, this);
//		countpanel.addMouseListener(new MyMouseL());
//		countpanel.addMouseMotionListener(new MyMouseL());
//		basepane.add(countpanel,"countpanel");
		
		set_position();
		oldSizeX = sizeX;
		oldSizeY = sizeY;
		check_exp();
	}
	
	public void writeActionLog(String data)
	{
		ACTIONLOG.writeActionLog("SUPPORT*"+data);
	}

    public void closeAllWindows()
    {
        if(popForSupport2 != null)
        for(int i=0;i<popForSupport2.length;i++)
            if(popForSupport2[i] != null)
            {
                if(popForSupport2[i].p != null)
                {
                    popForSupport2[i].p.dispose();
                    popForSupport2[i].p = null;
                }
                if(popForSupport2[i].pop_detail != null)
                {
                    popForSupport2[i].pop_detail.closeFigureWindow();
                    popForSupport2[i].pop_detail.dispose();
                    popForSupport2[i].pop_detail = null;
                }
                if(popForSupport2[i].pop_answer != null)
                {
                    popForSupport2[i].pop_answer.dispose();
                    popForSupport2[i].pop_answer = null;
                }
                
                
                popForSupport2[i].dispose();
                popForSupport2[i] = null;
            }
    }
    
	public void actionPerformed(ActionEvent e)
    {
		for(int i=0;i < classstage.length; i++)
        {
			if((String)cb.getSelectedItem() == classstage[i] || (String)cb.getSelectedItem() == classStageInJapanese[i])
            {
                closeAllWindows();
                
				classstage_num = i;
				layout.show(basepane,classstage[classstage_num]);
				data = makedata[classstage_num];
//				data.preserve_try_stage(classstage_num);
				data.sendtimeData(classstage_num," Window open");/////
				check_exp();
			}
		}
		
		if(e.getSource() == countbutton)		
		{
			if(countbutton.isSelected())
			{
				layout.show(basepane,"countpanel");
			} else {
				layout.show(basepane,classstage[classstage_num]);
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////	
	class MyScroll implements AdjustmentListener
	{
		public void adjustmentValueChanged(AdjustmentEvent e){
			if (e.getAdjustable() == scroll_bar){
				scroll_pos = scroll_bar.getValue();
				set_position();
				repaint();
			}
		}
	}
	int click_task = -1;
	
	class MyMouseL implements MouseListener,MouseMotionListener
	{
		public void mouseClicked(MouseEvent me){}
        
		public void mouseMoved(MouseEvent me)
        {
			movePointx = me.getX();
			movePointy = me.getY();
			
			click_task = -1;
			click_task = check_item_area(movePointx,movePointy);			
			if(click_task != -1){
				touch_task.setText(data.task[click_task].goal);
			}
			set_position();
			repaint();
		}
        
		public void mousePressed(MouseEvent me){
			pressPointx = me.getX();
			pressPointy = me.getY();
			click_task = -1;
			click_task = check_item_area(pressPointx,pressPointy);			
			
			if(click_task != -1)
            {
                closeAllWindows();
                
				data.task[click_task].click_num += 1;
                
//                writeActionLog("Question "+(click_task+1)+": ");
                
//				System.out.println(data.task[click_task].no);
				if(data.task[click_task].click_num % 2 == 1){
					data.task[click_task].color = click_color;	
					data.sendtimeData(classstage_num,"Q "+(click_task+1)+" : open");/////
				}else{ 
					data.task[click_task].color = base_color;
					data.sendtimeData(classstage_num,"Q "+(click_task+1)+" : close");/////
				}
				repaint();
				make_window(click_task);
				touch_task.setText(data.task[click_task].goal);
			}
		}
		public void mouseDragged(MouseEvent me){}
		public void mouseReleased(MouseEvent me){}			
		public void mouseEntered(MouseEvent me){}	//Enter an area	
		public void mouseExited(MouseEvent me){}	//Exit an area
	}

	boolean change = false;
	public boolean getPanelSize()
	{
		change = false;
		
//		oldSizeX = sizeX;
//		oldSizeY = sizeY;		
		sizeX = getWidth();
		sizeY = getHeight();
		
		testpane_sizeY = basepane.getHeight();
		
		if(sizeX != oldSizeX || sizeY != oldSizeY)
			change = true;
		
		changeX = changeY = 1.0;
		if(oldSizeX != 0)
			changeX = sizeX / (double)oldSizeX;
		if(oldSizeY != 0)
			changeY = sizeY / (double)oldSizeY;
	
		return change;
	}

	public void resizeData()
    {		
		frameSize = 30;
		fontSize = frameSize - 15;
		
		if(change == true){
			frameSize *= changeY;
			fontSize *= changeY;
			set_position();
		}
//		changeY = 1;
	}
	
	public int check_item_area(int mouse_x, int mouse_y)
	{
		for(int i=0;i<data.task_num;i++)
        {
			if(mouse_y > data.task[i].posy + frameSize && mouse_y < data.task[i].posy + frameSize + door_y)
            {
				if(mouse_x > data.task[i].posx - frameSize/2 && mouse_x < data.task[i].posx + door_x - frameSize/2)
                {
		//			System.out.println(data.task[i].goal);
					if(data.task[i].canopen == true)
						return i;
				}
			}
		}
		return -1;
	}
	
	public void make_window(int num)
	{
		int x,y,width;
		x = width = getWidth();
		y = getHeight();
		if(x > 950)x = 950;
		if(y > 900)y = 900;
		Point position = getLocationOnScreen();
		
		if(data.task[num].click_num % 2 == 1){
			popForSupport2[num] 
            = new PopUpForSupport((int)width+5, (int)position.getY()-20, x, y, control, num ,data, this);
		}
		else {
			
            if(popForSupport2[num] != null)
            {
                if(popForSupport2[num].p != null)
                {
                    popForSupport2[num].p.dispose();
                    popForSupport2[num].p = null;
                }

                popForSupport2[num].dispose();
                popForSupport2[num] = null;
            }
		}
	}
	
	void set_position()
	{	
		for(int i=0;i<data.thema_num;i++)
        {
			data.theme[i].posy = testpane_sizeY / (data.thema_num) * (i);
		}
        
	    int iw=door[0].getWidth(this);
	    int ih=door[0].getHeight(this);
	    
        
		door_y = data.theme[1].posy - data.theme[0].posy - frameSize/2;
        
//////////		door_y = data.theme[1].posy - data.theme[0].posy;
        door_x = iw * door_y/ih;

		for(int i=0;i<data.task_num;i++){
			data.task[i].posy = 0;
			data.task[i].posy += data.theme[data.task[i].level].posy;
			int task_pos = 1;
			task_pos = sizeX / (data.theme[data.task[i].level].num + 1);
			data.task[i].posx = data.task[i].id*task_pos -door_x/2;
		}
	}
	
    void setAnsweredFlagTrue(int level, int number)
    {
        if(makedata[level].task[number].canopen == true)
        {
            makedata[level].task[number].clear = true;
//            writeActionLog("Question "+(number+1)+": clear");
            makedata[level].sendtimeData(classstage_num,"Q "+(number+1)+" :"+data.task[number].goal+" clear");/////
			
			int lastTotalExp = total_exp;			///EXP///
			
            check_exp();
			
			System.out.println("GET EXP:"+(total_exp - lastTotalExp) );			
			control.ex1.addExp(total_exp - lastTotalExp);
			control.ex1.addExptutorial(total_exp - lastTotalExp);
			if(control.expPanel != null)
				control.expPanel.repaint();	
			
            repaint();
        }
    }
    
    boolean isEmpty(String str){
    	if(str == null || str.length() == 0)return true;
    	else return false;
    }
    
	
	//interpretation mission
//    void checkAnswer(String text_name,String Miningname,String Visualizationname,String result, String meaning, int importance)
    void checkAnswer(String result, String meaning, int importance)
	{
		//check answer 
		
		//give flag
		//setAnsweredFlagTrue(*,*);  should be identified the question that a user is trying before you call this method
		boolean judge = true;
		boolean alljudge = false;
		
		for(int i=0;i<data.task_num;i++)
        {
			judge = true;
			if(data.task[i].click_num >= 1){

				if(isEmpty(data.task[i].AssignMiningname) == false){
//					if(Miningname.equals(data.task[i].AssignMiningname) == false)judge = false;
					if(judge == false)continue;
				}
				
				if(isEmpty(data.task[i].AssignVisualizationname) == false){
//					if(Visualizationname.equals(data.task[i].AssignVisualizationname) == false)judge = false;
					System.out.println("Tool="+judge);////
					if(judge == false)continue;
				}
				
				System.out.println("result=" +result +" : "+data.task[i].result_txt);////
				
				if(isEmpty(data.task[i].result_txt) == false){
					String [] strAry = data.task[i].result_txt.split(" ");
					for(int j=0;j<strAry.length;j++){
						if(result.indexOf(strAry[j]) == -1){
							judge = false;
							System.out.println("result=" +result +"  "+strAry[j]);////
						}
						if(judge == false)continue;
					}
				}
				if(judge == false)continue;
				
				if(result.length() < data.task[i].result_len)judge = false;
				if(judge == false)continue;
				
				if(isEmpty(data.task[i].meaning_txt) == false){
					String [] strAry2 = data.task[i].meaning_txt.split(" ");
					for(int j=0;j<strAry2.length;j++){
						if(meaning.indexOf(strAry2[j]) == -1)judge = false;
						if(judge == false)continue;
					}
				}
				if(judge == false)continue;

				if(meaning.length() < data.task[i].meaning_len)judge = false;
						
				if(importance < data.task[i].importance)judge = false;
				
				if(judge == true){
					data.task[i].clear = true;
//					System.out.println("Question "+(i+1)+"  "+data.task[i].goal+"  : clear");
//	                writeActionLog("Question "+(i+1)+"  "+data.task[i].goal+"  : clear");
	        		data.sendtimeData(classstage_num,"Q "+(i+1)+" :"+data.task[i].goal+"clear "+" ("+result+","+meaning+","+importance+")");/////

			int lastTotalExp = total_exp;					
					
	                check_exp();////////////////////////////////////////EXP///
					
					System.out.println("GET EXP:"+(total_exp - lastTotalExp) );					
					control.ex1.addExp(total_exp - lastTotalExp);
					control.ex1.addExptutorial(total_exp - lastTotalExp);
					if(control.expPanel != null)					
						control.expPanel.repaint();					
					
					repaint();
					alljudge = true;
				}
			}
        }
		
	//	System.out.println("Answer="+result+","+meaning+","+importance);////
		if(alljudge == false)data.sendtimeData(classstage_num,"all Q :false"+" ("+result+","+meaning+","+importance+")");/////
	}
	
    
	int total_exp = 0;
	
	int getSkillLevel(int exp)
	{
		int sum = 0;
		
		for(int i=0;;i++)
			if(exp < sum)
				return i;
			else
				sum += (i+1)*100;
	}
	
	void check_exp(){	//check total exp
		data.preserve_clear_list(classstage_num);
		
		total_exp = 0;
		
		boolean allClear = true;
		
		for(int i=0;i<data.task_num;i++){
			if(data.task[i].clear == true){
				total_exp += data.task[i].exp;
			}
			else
				allClear = false;
		}

		if(allClear)
			texttitle[1].setText(japaneseWords[1] + (getSkillLevel(total_exp)+1) + "(MAX) MASTER !!");
		else
			texttitle[1].setText(japaneseWords[1] + getSkillLevel(total_exp));
		texttitle[2].setText(japaneseWords[2] + total_exp);
		
		check_can_open();
		task_list_panel[classstage_num].repaint();
	}
	
	void check_can_open(){	//check can choice task
		for(int i = 0; i<data.task_num;i++){
			if(data.task[i].canopen == true)continue;
			else {
				if(data.task[i].open == 0)data.task[i].canopen = true;
				for(int j=0;j<data.task_num;j++){
					if(data.task[j].no == data.task[i].open){
						if(data.task[j].clear == true)
							data.task[i].canopen = true;
					}
				}
			}
		}
	}
	
}

class Task_Panel extends JPanel
{
	MakeSupportTaskData data;
	Support support;
	Control control;
	Image [] door = new Image[4];
	Image [] essentialbox = new Image[4];
	Image [] introduction = new Image[4];
	String pic_ad;
	int class_num = -1;
	
	Task_Panel(Control control,MakeSupportTaskData data, Support support,int sizeX,int sizeY,int class_num)
	{	
		this.control = control;
		this.data = data;
		this.support = support;
		this.class_num = class_num;
		
		pic_ad = data.file_add;

		for(int i=0;i<4;i++){
			door[i] = Toolkit.getDefaultToolkit().getImage(pic_ad + "door"+(i+1)+".png");
			essentialbox[i] = Toolkit.getDefaultToolkit().getImage(pic_ad + "essentialbox"+(i+1)+".png");
			introduction[i] = Toolkit.getDefaultToolkit().getImage(pic_ad + "introduction"+(i+1)+".png");
		}
	}

	void draw_background1(Graphics2D g2)
	{
		boolean change = support.getPanelSize();
		if(change)support.resizeData();
        
//		g2.setColor(new Color(0xE0,0xFF,0xFF));
//		g2.setColor(new Color(0x33,0x33,0x66));
		g2.setColor(new Color(0xad, 0xff, 0x2f));
//		if(class_num == 0)g2.setColor(Color.cyan);	
//		if(class_num == 1)g2.setColor(Color.red);
//		if(class_num == 2)g2.setColor(Color.blue);
		
        g2.fillRect(0,0, support.sizeX, support.sizeY);
	}
	
	int space = 5;
	
	void draw_letter1(Graphics2D g2)
	{	
		for(int i=0;i<data.task_num;i++){
			if(data.task[i].posx == -1)continue;
			
		    int iw=data.task[i].image.getWidth(this);
		    int ih=data.task[i].image.getHeight(this);
	        
//			door_y = data.theme[1].posy - data.theme[0].posy;
	        int img_width = iw * support.door_y/ih;
			
//			g2.drawImage(data.task[i].image, data.task[i].posx,data.task[i].posy+support.frameSize, support.door_x, support.door_y, this);
			g2.drawImage(data.task[i].image, data.task[i].posx,data.task[i].posy+support.frameSize,img_width, support.door_y, this);
		}
		for(int i=0;i<data.thema_num;i++){			
			if(data.theme[i].posy == -1)
                continue;
			g2.setColor(Color.white);
			g2.fillRect(0,data.theme[i].posy, support.sizeX, support.frameSize);
			g2.setColor(Color.black);
			g2.drawRect(0,data.theme[i].posy, support.sizeX, support.frameSize);			
			g2.setColor(Color.black);
			g2.setFont(new Font(control.sp1.fontName, Font.BOLD, support.fontSize+2));
			g2.drawString("MISSION "+data.theme[i].level+":  "+data.theme[i].goal,10,data.theme[i].posy+support.frameSize/3*2);
		}		
	}
	
	void set_image1(Graphics2D g2,int i)
	{	
		if(data.task[i].pictype.equals("normalbox")){
			data.task[i].image = door[0];	//can't open
			if(data.task[i].canopen == true)data.task[i].image = door[1];//can open
			if(i == support.click_task)data.task[i].image = door[3];	// click or touch now
			else if(data.task[i].click_num % 2 == 1) data.task[i].image = door[3]; //click(open) now
			if(data.task[i].clear == true)data.task[i].image = door[2]; //clear
		}
		
		if(data.task[i].pictype.equals("essentialbox")){
			data.task[i].image = essentialbox[0];	//can't open
			if(data.task[i].canopen == true)data.task[i].image = essentialbox[1];//can open
			if(i == support.click_task)data.task[i].image = essentialbox[2];	// click or touch now
			else if(data.task[i].click_num % 2 == 1) data.task[i].image = essentialbox[2]; //click(open) now
			if(data.task[i].clear == true)data.task[i].image = essentialbox[3]; //clear
		}
		if(data.task[i].pictype.equals("introduction")){
			data.task[i].image = introduction[0];	//can't open
			if(data.task[i].canopen == true)data.task[i].image = introduction[1];//can open
			if(i == support.click_task)data.task[i].image = introduction[2];	// click or touch now
			else if(data.task[i].click_num % 2 == 1) data.task[i].image = introduction[2]; //click(open) now
			if(data.task[i].clear == true)data.task[i].image = introduction[3]; //clear
		}
	}

	void set_images1(Graphics2D g2)
	{	
		for(int i=0;i<data.task_num;i++){
			set_image1(g2,i);
		}
	}
    
	public void paintComponent(Graphics g)
	{        
		Graphics2D g2 = (Graphics2D)g;
		
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);		
		
		draw_background1(g2);	//Set background
		set_images1(g2);
		draw_letter1(g2);
	}
	
	public void update(Graphics g)
	{
		paintComponent(g);
	}

}
/*
class Count_Panel extends JPanel
{
	Support support;
	String pic_ad = "";
	Image countback;
	String counter_name[] = {"tool_num","mining_num","visual_num","focus_num","option_num"};
	int counter_threshold [] = {10,10,10,20,40};		//test threshold
	int counter_num [] = {4,24,21,46,90};				//test count times

	int space = 10;
	int round = 10;
	int flamex = 0, flamey = 0;
	int flamewidth = 0, flameheight = 0;

	
	Count_Panel(Control control, Support support)
	{
		this.support = support;	
		pic_ad = control.absolutePath + "source" + File.separator + "operate" + File.separator + "countback.png";
		countback = Toolkit.getDefaultToolkit().getImage(pic_ad);
	}

	void draw_background1(Graphics2D g2)
	{
		boolean change = support.getPanelSize();
		if(change)support.resizeData();
        
		g2.setColor(new Color(0xff,0xff,0x99));		
        g2.fillRect(0,0, support.sizeX, support.sizeY);
	}
	
	void draw_count_flames(Graphics2D g2)
	{
		for(int i=0; i<counter_name.length; i++){
			//draw flame
			flamex = space;
			flamey = support.testpane_sizeY/counter_name.length * i + space ;
			flamewidth = support.sizeX - space*2;
			flameheight = support.testpane_sizeY/counter_name.length - space*2;
			g2.drawImage(countback, flamex, flamey, flamewidth, flameheight , this);
			
			//draw counter name
			g2.setColor(Color.black);
			g2.fillRoundRect(flamex -1 , flamey + flameheight - support.fontSize*2-1 , flamewidth , support.fontSize*2, round, round);
			g2.setColor(Color.white);
			g2.fillRoundRect(flamex, flamey + flameheight - support.fontSize*2 , flamewidth - space/2 , support.fontSize*2 - space/2, round, round);
			g2.setColor(Color.black);
			g2.setFont(new Font(control.sp1.fontName, Font.BOLD,support.fontSize+2));
			g2.drawString(counter_name[i], flamex + space, flamey + flameheight - space);
		}
	}
	
	void draw_count_view(Graphics2D g2)
	{
		for(int i=0; i<counter_name.length; i++){

			float[] dash = { 20.0f, 5.0f,3.0f,5.0f };
			float[] dash2 = {10.0f, 5.0f,5.0f,5.0f };
			float[] dash3 = {15.0f, 2.0f,5.0f,2.0f };
			
			int ovalx = 0, ovaly = 0;
			int ovalwidth = 0, ovalheight = 0;
			
			flamey = support.testpane_sizeY/counter_name.length * i + space ;
			
			ovalx = flamex + flamewidth - flameheight*4/5;
			ovaly = flamey + flameheight  - flameheight*4/5;
			ovalwidth = flameheight*4/5;
			ovalheight = flameheight*4/5;
			
			int a = 20;
			g2.setColor(Color.darkGray);
			g2.setStroke(new BasicStroke(1.0f));
			g2.fillOval(ovalx, ovaly, ovalwidth, ovalheight);
			
//			int counter_threshold [] = {10,10,10,20,40};		//test threshold
//			int counter_num [] = {4,24,21,46,90};				//test count times
			
			int count_rest = counter_num[i]%counter_threshold[i];
			int count_level = (int)(counter_num[i]/counter_threshold[i]);
			double count_per = (double)count_rest/(double)counter_threshold[i];
//			System.out.println(i+" rest : "+count_rest +" level : " +count_level);
			
			double arcround = (double)((double)count_per * (double)360);
			
			g2.setColor(Color.cyan);
			g2.fillArc(ovalx, ovaly, ovalwidth, ovalheight, 0, (int)arcround);

			g2.setColor(Color.blue);
//			g2.setStroke(new BasicStroke(2.0f,BasicStroke.JOIN_ROUND,
//						BasicStroke.CAP_BUTT,1.0f,dash,0.0f));
			g2.drawArc(ovalx+3, ovaly+3, ovalwidth-2*3, ovalheight-2*3, 0, (int)arcround);
			
			g2.setColor(Color.black);
			g2.setFont(new Font(control.sp1.fontName, Font.BOLD,support.fontSize+5));
			g2.drawString("Level :	"+count_level,  flamewidth/9, flamey + flameheight/3 );
			g2.setFont(new Font(control.sp1.fontName, Font.BOLD,support.fontSize+2));
			g2.drawString("next level with another "+count_rest + "times !", flamewidth/7, flamey + flameheight/3*2);
			g2.setColor(Color.red);
			g2.setFont(new Font(control.sp1.fontName, Font.BOLD,flameheight/3));
			g2.drawString((int)(count_per*100) +" %", ovalx - ovalwidth/4, ovaly + ovalheight/5*4);
		}
//		g2.setStroke(new BasicStroke(1.0f));
	}
    
	public void paintComponent(Graphics g)
	{        
		Graphics2D g2 = (Graphics2D)g;
 
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 
 
		draw_background1(g2);	//Set background
		draw_count_flames(g2);
		draw_count_view(g2);
	}
	
	public void update(Graphics g)
	{
		paintComponent(g);
	}

}
*/

class Pic_Panel extends JPanel
{
	int sizeX,sizeY;
	Image arrowImage;
	
	Pic_Panel(String pic_ad)
	{	
		arrowImage = Toolkit.getDefaultToolkit().getImage(pic_ad);
	}

    public void getPanelSize()
	{
		sizeX = getWidth();
		sizeY = getHeight();
	}
    
    void draw_background(Graphics2D g2)
	{
		getPanelSize();
		g2.setColor(Color.white);
        g2.fillRect(0,0, sizeX, sizeY);
	}
    
    void draw_image(Graphics2D g2)
    {
	    int iw=arrowImage.getWidth(this);
	    int ih=arrowImage.getHeight(this);

        
		if(iw > ih)
        {
            if(ih*sizeX/iw <= sizeY)
                g2.drawImage(arrowImage, 0, 0, sizeX, ih*sizeX/iw, this);
            else
                g2.drawImage(arrowImage, 0, 0, sizeX, sizeY, this);
        }
		else
			g2.drawImage(arrowImage, 0, 0, iw*sizeY/ih, sizeY, this);
    }
	
	public void paintComponent(Graphics g)
	{        
		Graphics2D g2 = (Graphics2D)g;
		
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);		
		
		draw_background(g2);	//Set background
		draw_image(g2);
	}
	
	public void update(Graphics g)
	{
		paintComponent(g);
	}
}
