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

package source.GameMode;

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.GroupLayout.Alignment;



public class DataPanel extends JPanel implements ActionListener
{
	ExpPanel exppanel;
	ExpData expdata;
	MissionPanel missionpanel;
	PopUpForKnowledgeCreation knowledge;
	PopUpForInterpretation interpretation;
	
	
	JPanel allTopPanel;
	JPanel middlePanel;
	JPanel centerPanel;
	
	JPanel buttonPanel;

	JPanel checkPanel;
	JPanel labelPanel;
	
	
	//Top
	JLabel message;
	JLabel message2;

    //Middle
	JScrollPane scroll[];
	
    JPanel checkBoxPanel1; 		
    JPanel checkBoxPanel2;	
    
	//checkBoxPanel1
    JLabel boxLabel[];
    JLabel data[];  
   	//JCheckBox setBoxA[];
	ButtonGroup modeGroup;	
	int sizeX;
    ButtonGroup leftGroup;
	
	String posString[] = new String[9];
	String periodString[] = new String[3];
	String sunaString;
	String[] strarray = new String[1000];
	

	//checkBoxPanel2
   	//JCheckBox setBoxB[];	//currently not used, these are prepared for task execution

	
	
	int fontsize = 16;
	int i = 0;
	int datanumber[] = new int[100];
	String datastring[] = new String[100]; 
	int k = 0;
	String menuInJapanese[];
	String menuInJapanese2[];
	String tutorial1[];
	String tutorial2[];
	String tutorial3[];
	String tutorial4[];
	
	int tutorialnumber1[];
	int totaltutorialnumber1 = 0;
	int tutorialnumber2[];
	int totaltutorialnumber2 = 0;
	int tutorialnumber3[];
	int totaltutorialnumber3 = 0;
	int tutorialnumber4[];
	int totaltutorialnumber4 = 0;
	
	int n1,n2,n3,n4 = 0;
	
	static int timeint = 0;
	
	SettingData settingData;
	
	boolean autoSet;
	Control control;
	PopUpForData popUp;
	
	ImageIcon icon,smallIcon,icon2,smallIcon2;
	Image smallImg;	
	
	DataPanel(Control control, PopUpForData popUp)
	{
		setLayout(new BorderLayout());
		
		settingData = control.sp1;
		this.control = control;
		this.popUp = popUp;
		
		menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "GameMode" + File.separator+ "Data.txt"));		
		
		menuInJapanese2 = FILEIO.TextFileAllReadCodeArray(new File(control.expFile));
		
		tutorial1 = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operateBeginner-1_clear.txt"));
		tutorial2 = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operatebeginner-2_clear.txt"));	
		tutorial3 = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operateDocumentPolish_clear.txt"));
		tutorial4 = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "operateForDeveloper" + File.separator+ "developerbeginner_clear.txt"));
		
		try{
		  BufferedReader fin = new BufferedReader(new FileReader(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operateBeginner-1_clear.txt"));
       		 String aLine;
      		while(null!=(aLine = fin.readLine())){
         	 n1++;
        	}
       		 fin.close();
     		}
  		catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
		
		try{
		  BufferedReader fin = new BufferedReader(new FileReader(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operateBeginner-2_clear.txt"));
       		 String aLine;
      		while(null!=(aLine = fin.readLine())){
         	 n2++;
        	}
       		 fin.close();
     		}
  		catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
		
		try{
		  BufferedReader fin = new BufferedReader(new FileReader(control.absolutePath + "source" + File.separator + "operateForUser" + File.separator+ "operateDocumentPolish_clear.txt"));
       		 String aLine;
      		while(null!=(aLine = fin.readLine())){
         	 n3++;
        	}
       		 fin.close();
     		}
  		catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
		
		try{
		  BufferedReader fin = new BufferedReader(new FileReader(control.absolutePath + "source" + File.separator + "operateForDeveloper" + File.separator+ "developerbeginner_clear.txt"));
       		 String aLine;
      		while(null!=(aLine = fin.readLine())){
         	 n4++;
        	}
       		 fin.close();
     		}
  		catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
		
		
		//if(check != 0 ){
		tutorialnumber1 = new int[n1];
		tutorialnumber2 = new int[n2];
		tutorialnumber3 = new int[n3];
		tutorialnumber4 = new int[n4];
		
		for(int t=0;t<n1;t++){
		tutorialnumber1[t] = Integer.parseInt(tutorial1[t]);
		totaltutorialnumber1 = totaltutorialnumber1 + tutorialnumber1[t];
		}
		
		for(int t=0;t<n2;t++){
		tutorialnumber2[t] = Integer.parseInt(tutorial2[t]);
		totaltutorialnumber2 = totaltutorialnumber2 + tutorialnumber2[t];
		}
		
		for(int t=0;t<n3;t++){
		tutorialnumber3[t] = Integer.parseInt(tutorial3[t]);
		totaltutorialnumber3 = totaltutorialnumber3 + tutorialnumber3[t];
		}
		
		
		for(int t=0;t<n4;t++){
		tutorialnumber4[t] = Integer.parseInt(tutorial4[t]);
		totaltutorialnumber4 = totaltutorialnumber4 + tutorialnumber4[t];
		}
		
		
		//ALL
		allTopPanel = new JPanel();
        	allTopPanel.setBackground(Color.blue);
		add(allTopPanel, BorderLayout.NORTH); //topmessage

		message = new JLabel();
		message.setFont(new Font(settingData.fontName, Font.BOLD, fontsize+2));
		message.setForeground(Color.white);
		
		setTitleNames();
		allTopPanel.add(message);
		
		//Center
		//centerPanel = new JPanel();
		centerPanel = new JPanel(new GridLayout(30,1));
        	centerPanel.setBackground(new Color(255,195,76));
		add(centerPanel);

		
        //add(middlePanel);
        scroll = new JScrollPane[2];
        
        //MIDDLE-INSIDE
		
		checkPanel = new JPanel(new GridLayout(2,1));
		labelPanel = new JPanel(new GridLayout(4,1));
		checkPanel.setBackground(new Color(0x7f,0xff,0xd4));
		checkPanel.setBackground(Color.blue);
		labelPanel.setBackground(new Color(0x7f,0xff,0xd4));
		labelPanel.setBackground(new Color(255,195,76));
		
		createCenterPanel();
		//initializeSetBox();		
		
		//BOTTOM
		buttonPanel = new JPanel(new GridLayout(2,1));
		add(buttonPanel, BorderLayout.SOUTH);	
		buttonPanel.setBackground(Color.white);		

	}
	
	public void createCenterPanel(){
	data = new JLabel[30];
    	 for(int i=0;i<30;i++)
        {
            data[i] = new JLabel();
            data[i].setFont(new Font(settingData.fontName, Font.BOLD, fontsize+2));
        }
	    
	for(int i=0;i<30;i++){
	centerPanel.add(data[i]);
	}  
	
	setTitleNames3();
	}
	
	
	

	public void setTitleNames()
	{
		if(settingData.inJapanese){
			
			message.setText(menuInJapanese[0]);
			//message.setText(datastring[0]);
			}
		else
			message.setText("Data");
	}
	

    
	public void setTitleNames3()
	{
	
	if(settingData.inJapanese){
	

	data[0].setText(menuInJapanese[1] + control.ex1.rank + "     " + menuInJapanese[2]  + control.ex1.exp + "     " + menuInJapanese[3]  + control.ex1.coin);
	
	data[1].setText(menuInJapanese[4]);
	
	data[2].setText(menuInJapanese[9] + expdata.controlButtonCount[0] +  "   " 
	+ menuInJapanese[10] + expdata.controlButtonCount[1] + "   " + menuInJapanese[11] + expdata.controlButtonCount[2] + "   " + menuInJapanese[12] + expdata.controlButtonCount[3]);
	
	data[3].setText(menuInJapanese[13] + expdata.controlButtonCount[4] + "   " + menuInJapanese[14] + expdata.controlButtonCount[5] + "   " + menuInJapanese[15] + expdata.controlButtonCount[6] +  "   " 
	+ menuInJapanese[16]  + expdata.controlButtonCount[7]);
	
	data[4].setText(menuInJapanese[17] + expdata.controlButtonCount[8] + "   " +  menuInJapanese[18] + expdata.controlButtonCount[9] +  "   " 
	+ menuInJapanese[19] + expdata.controlButtonCount[10] + "   " + menuInJapanese[20] + expdata.controlButtonCount[11]);
	
	data[5].setText(menuInJapanese[21] + expdata.controlButtonCount[12] + "   " + menuInJapanese[22] + expdata.controlButtonCount[13] + "   " + menuInJapanese[23] + expdata.controlButtonCount[14] + "   " + menuInJapanese[24] + expdata.controlButtonCount[15] +  "   " );
	
	data[6].setText(menuInJapanese[25] + expdata.controlButtonCount[16] + "   " + menuInJapanese[26] + expdata.controlButtonCount[17] +  "   " 
	+ menuInJapanese[27] + expdata.controlButtonCount[18] + "   "  + menuInJapanese[28] + expdata.controlButtonCount[19]);
	
	
	data[7].setText(menuInJapanese[51] + expdata.selectButtonCount[0] + "   " + menuInJapanese[52] + expdata.selectButtonCount[1] + "   " + menuInJapanese[53] + expdata.selectButtonCount[2] + "   " + menuInJapanese[54] + expdata.selectButtonCount[3]);
	
	data[8].setText(menuInJapanese[55] + expdata.miningButtonCount[0] + "   " + menuInJapanese[56] + expdata.miningButtonCount[1] + "   " + menuInJapanese[57] + expdata.miningButtonCount[2] + "   " + menuInJapanese[58] + expdata.miningButtonCount[3]);
	
	data[9].setText(menuInJapanese[59] + expdata.miningButtonCount[4] + "   " + menuInJapanese[60] + expdata.miningButtonCount[5] + "   " + menuInJapanese[61] + expdata.miningButtonCount[6] + "   " + menuInJapanese[62] + expdata.miningButtonCount[7]);
	
	data[11].setText(menuInJapanese[30] + ExpData.startingnumber);
	
	//for(int i=0;i<ExpData.miningModuleNumber;i++){
	//ExpData.miningmodule5 += ExpData.miningModuleSelectionCount[i];
	//}
	
	ExpData.miningmodule5 = 0;
	for(int i=0;i<ExpData.miningModuleNumber;i++){
	ExpData.miningmodule5 += ExpData.miningModuleSelectionCount[i];
	}
	
	ExpData.visualmodule5 = 0;
	for(int i=0;i<ExpData.visualizationModuleNumber;i++){
	ExpData.visualmodule5 += ExpData.visualizationModuleSelectionCount[i];
	}
	
	ExpData.miningmoduleoperation5 = 0;
	for(int i=0;i<ExpData.miningModuleNumber;i++){
	ExpData.miningmoduleoperation5 += ExpData.miningModuleOperationCount[i];
	}
	
	ExpData.visualmoduleoperation5 = 0;
	for(int i=0;i<ExpData.visualizationModuleNumber;i++){
	ExpData.visualmoduleoperation5 += ExpData.visualizationModuleOperationCount[i];
	}
	
	
	data[12].setText(menuInJapanese[31] + ExpData.miningmodule5); 
	//data[11].setText("first day:" + menuInJapanese2[22]);
	
	data[13].setText(menuInJapanese[32] + menuInJapanese[33]+ ExpData.miningmoduleoperation5 + menuInJapanese[34] +ExpData.visualmoduleoperation5);
	
	data[14].setText(menuInJapanese[35] + expdata.inputnumber);
	data[15].setText(menuInJapanese[36] + expdata.knowledgenumber);
	
	data[16].setText(menuInJapanese[37] + expdata.loginnumber);
	
	data[17].setText(menuInJapanese[38] + expdata.renzokuloginnumber);
	
	data[18].setText(menuInJapanese[29] + expdata.daymonth + menuInJapanese[39] + expdata.daymonthnumber);
	
	String timeinfo = String.format("%.0f", ACTIONLOG.getDiffTime());
	int timeint = Integer.parseInt(timeinfo);
	
	//data[13].setText("time" + " " + String.format("%.0f",control.getDiffTime()));
	data[19].setText(menuInJapanese[40] + " " + timeint/60 + menuInJapanese[43] + timeint%60 + menuInJapanese[44]);
	data[20].setText(menuInJapanese[41] + " " + expdata.totaltimeint/3600 + menuInJapanese[42] + ((expdata.totaltimeint/60) - (expdata.totaltimeint/3600 *60)) + menuInJapanese[43] + expdata.totaltimeint % 60  + menuInJapanese[44]);
	
	data[21].setText(menuInJapanese[45]);
	data[22].setText(menuInJapanese[46] + totaltutorialnumber1 + "/" + n1 + "   " + menuInJapanese[47] + totaltutorialnumber2 + "/" + n2);
	data[23].setText(menuInJapanese[48] + totaltutorialnumber3 + "/" + n3 +  "   " + menuInJapanese[49] + totaltutorialnumber4 + "/" +n4);
	//data[20].setText("" + expdata.expcollect);
	
	}
	
	}

	//Action listener
	public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;		
		
	}
	
	public void closeWindow()
	{		
	exppanel.data.setSelected(false);
        //control.closePopForTitle();
	exppanel.closePopForShop();
	
	timeint++;
	}
	
	
}

