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


package source;

import source.TextData.*;
import source.GameMode.*;
import source.Tutorial.*;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.io.*;

import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;


import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.image.*;
import javax.imageio.ImageIO;

import java.util.regex.*;
import java.util.Comparator;
import java.util.Arrays;

//Control panel :YELLOW
public class Control extends JPanel implements ActionListener, ComponentListener
{
	MainFrame mainf;
	final int MAX_PANEL = 10;
	int defaultPanelNumber = 2;
	int panelNumber = 0;
	int defaultPanelSizeY;
	int balancedPanelSizeX[];
	boolean first = true;
	boolean sizeBalance = false;
	
//	public int windowSizeX;
	
//	boolean createNewActionLog = false;
	boolean createNewActionLog = true;
	
	JPanel upperPanel;//upper select and setting panel
	
	JSplitPane splitpane[];

	//for Setting
	String settingFile;	
	public SettingData sp1;
	
	SettingPanel settingPanel;

	//for Exp
	public String expFile;
	public ExpData ex1;
	
	public ExpPanel expPanel;	
	
	
	JPanel selectPanel;	//panel for modules	
	
	Select panel[];
	Select stealthPanel;
	

    
	JPanel buttonPanel;	//lower button panel
	JPanel subButtonPanel[];
    JPanel subLabelPanel[];
    JLabel buttonLabel[];

	JButton bt10;
	JButton bt20;
	JButton bt30;
	JButton bt40;
	JButton bt50;
//	JToggleButton bt1 = new JToggleButton();
//	JToggleButton bt2 = new JToggleButton();
//	JToggleButton bt3 = new JToggleButton();
//	ButtonGroup bg = new ButtonGroup();
	JButton bt99;
	JButton bt52;
	JButton bt55;
	JButton bt60;	//Undo panel Set
	JButton bt70;
	JToggleButton bt72;
	JButton bt71;
	JButton bt90;
	JToggleButton bt0;	//keyword setting
	JToggleButton bt00;	//mode setting
	JToggleButton btx;
	JToggleButton btxImage;
    JToggleButton btxTree;
	public JToggleButton btTutorial; //tutorial(character assist)
public 	JToggleButton btxx; //tutorial
public 	JToggleButton btxxx; //tutorial
	JToggleButton bt77;	//KNOWLEDGE CREATION
	JToggleButton bt78;	//KNOWLEDGE CREATION
    
    JToggleButton bt79;    //INTERPRETATION
    JToggleButton bt81;    //GAME MODE
    
public    JButton btd1;       //data shrink
public    JButton btd2, btd2x;       //data shrink reset
    JToggleButton btd3;       //data shrink information window
	
    public int characterTutorial = 0;   //1: character assist tutorial from menu window, 2: character assist tutorial from module, 0: no character assist tutorial is go on
    
	boolean autoSet = false;
	
	PopUpWindow pop;	//popup menu window
	
	public PopUpForSupport popForSupport, popForSupportDeveloper;//SUPPORT

    PopUpForStory popForStory;  //Character Assist
	
	PopUpForSelectionAssist popUpForSelectionAssist;	//SELECTION ASSIST
	SelectionAssistData selectionAssistData;
    
    PopUpForInterpretation popForInterpretation;    //Result and Interpretation
    
    PopUpForShrinkInformation shrinkInformationWindow;  //Shrink Information
    int baseHeight = 50+25;
	
	String buttonNamesInEnglish[] = {"Reload text and Restructure", "FontSize--", "FontSize++", "Add Panel", "Reduce Panel", 
										"Quit", "Load Directory", "Load New File", "Combination Panel", "Save Combination", 
										"Keyword","ALL", "SEG", "SEN","Balance",
										"Save Image","Tool Settings","Character Size","Set Panels","Tutorial",
										"Settings","Input Text","Quit TETDM","Combination","User",
										"Developer","By Name","By Image","Knowledge Creation","List",
										"Creation","Mode","Char.","Result","Game","Shrink",
                                        "Reset","Data Shrink","Disp.","By Tree"};
	String buttonNamesInJapanese[];
	String inJapanese[] = new String[17];
	
	public String windowNameInJapanese[]; //WINDOW NAME
	
	public ModuleData readModuleData, moduleData;

	//TEXT DATA
	String original_file="", read_filename;
    boolean utf8code = false;
	public TextData text;		//temporarily public    //NOT A PARTIAL TEXT
    
    public String last_original_file = null;        //FOR TUTORIAL USE ONLY
	
	public String absolutePath;
    
    ////NAVIGATION
    public NavigationControl navigationControl;

	
    //FOR USE R
    public boolean initializeR = true;
    
	
	int interpretationNumber;	//INTERPRETATION	///////
	int maxInterpretationNumber = 60;
	Interpretation interpretation[]; ////////
	
	
    /*
	public class Interpretation
	{
		TextData text;
		int miningID, visualizationID;
		int interpretationID;
		String result, meaning;
		
		Interpretation(TextData text, int miningID, int visualizationID, String result, String meaning)
		{
			this.text = text;
			this.miningID = miningID;
			this.visualizationID = visualizationID;
			this.result = result;
			this.meaning = meaning;
		}
	}
	*/

    //        PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    //        System.out.println("Location of Mouse : " + pointerInfo.getLocation());
    
    /////////////RUN///////////////

    XYThread th;
    
    //START PROGRAM
    //  if(th != null)
    //      th.stopThread();
    //  th = new XYThread();
    //  th.start();

    //STOP PROGRAM
    //  th.stopThread();
    
    public class XYThread extends Thread
    {
        private boolean isActive = true;
        
        public void stopThread()
        {
            System.out.println("STOP Thread");
            this.isActive = false;
        }
        
        public void run()
        {
            System.out.println("Start Thread");
            
            while(this.isActive)
            {
                PointerInfo pointerInfo = MouseInfo.getPointerInfo();
                System.out.println("Location of Mouse : " + pointerInfo.getLocation());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            
            System.out.println("Stop Thread");
        }
    }

    /////////////RUN///////////////
    
	public class Interpretation
	{
		int interpretationID;
		
        String sourceFilename;
		String result, meaning;
		int importance;
        
        int allPanelNumber;
        int allMiningIDs[];
        int allVisualizationIDs[];
        int allTextIDs[];
        int allSizeX[];
        
        boolean noticedPanelNumber[];
		
		ImageIcon icon, smallIcon;
		Image smallImg;			
		
        Interpretation(){}
        
		Interpretation(int interpretationID, String sourceFilename, String result, String meaning, int importance, int miningIDs[], int visualizationIDs[], int textIDs[], int sizeX[], boolean noticedPanelNumber[])
		{
			this.interpretationID = interpretationID;
			
			this.sourceFilename = sourceFilename;
			this.result = result;
			this.meaning = meaning;
			this.importance = importance;
            
            allPanelNumber = miningIDs.length;
            allMiningIDs = new int[allPanelNumber];
            allVisualizationIDs = new int[allPanelNumber];
            allTextIDs = new int[allPanelNumber];
            allSizeX = new int[allPanelNumber];
            
            this.noticedPanelNumber = noticedPanelNumber;
            
            for(int i=0;i<allPanelNumber;i++)
            {
                allMiningIDs[i] = miningIDs[i];
                allVisualizationIDs[i] = visualizationIDs[i];
                allTextIDs[i] = textIDs[i];
                allSizeX[i] = sizeX[i];
            }
			
			System.out.println("interpretationID= "+(interpretationID+1));
            for(int i=0;i<allPanelNumber;i++)
                System.out.println("textID = "+allTextIDs[i]);
			
			icon = new ImageIcon(absolutePath+"interpretation"+File.separator+"situation"+(interpretationID+1)+".png");
			smallImg = icon.getImage().getScaledInstance(160, 200, Image.SCALE_SMOOTH);
			smallIcon = new ImageIcon(smallImg);			
		}
	}

	public class Focus
	{
		public boolean mainFocusBoolean, subFocusBoolean, focusBooleanArray[], focusBooleanArray2[][];
		public int mainFocusInteger, subFocusInteger, focusIntegerArray[], focusIntegerArray2[][];
		public double mainFocusDouble, subFocusDouble, focusDoubleArray[], focusDoubleArray2[][];		
		public String mainFocusString, subFocusString, focusStringArray[];

        ShrinkData shrinkData[];
        int maxShrink = 20;     //global max
        int shrinkCount;        //current
        int shrinkCurrentMax;   //current max (Number of initialized shrinkData)
        

        
		Focus()
		{
			clearAllFocus();
            shrinkData = new ShrinkData[maxShrink+1];
            shrinkCount = 0;
            shrinkCurrentMax = 0;
		}
		
		public void clearAllFocus()
		{
			mainFocusBoolean = subFocusBoolean = false;
			mainFocusInteger = subFocusInteger = -1;			
			mainFocusDouble = subFocusDouble = -1.0;
			mainFocusString = subFocusString = "";

			focusBooleanArray = new boolean[]{false};
			focusIntegerArray = new int[]{-1};
			focusDoubleArray = new double[]{-1.0};			
			focusStringArray = new String[]{""};

			focusBooleanArray2 = new boolean[][]{{false}};
			focusIntegerArray2 = new int[][]{{-1}};
			focusDoubleArray2 = new double[][]{{-1.0}};
		}
        
        public void reviseCondition(int toolType, int toolID, int objectType, String japaneseCondition, String englishCondition, String example, int number)
        {
            String toolName="";
            String condition="";

            if(sp1.inJapanese)
            {
                if(toolType == 1)//MiningModule
                    toolName = moduleData.getModuleNameInJapanese(toolID);
                else if(toolType == 2)//VisualizationModule
                {
                    toolName = moduleData.getVisualizationModuleNameInJapanese(toolID);
                    if(japaneseCondition.equals(""))
                        japaneseCondition = inJapanese[16];
                }
                condition = japaneseCondition;
            }
            else
            {
                if(toolType == 1)//MiningModule
                    toolName = moduleData.getModuleName(toolID);
                else if(toolType == 2)//VisualizationModule
                {
                    toolName = moduleData.getVisualizationModuleName(toolID);
                    if(englishCondition.equals(""))
                        englishCondition = "Selected";
                }
                condition = englishCondition;
            }
            
            System.out.println("condition="+condition+" number="+number);


            if(shrinkInformationWindow != null)
            {
                if(shrinkInformationWindow.reviseData(toolName, condition, objectType, example, number, text.segmentNumber, shrinkData, shrinkCount) == true)
                {
                    btd1.setEnabled(true);
                    shrinkInformationWindow.invertion.setEnabled(true);
                }
                else
                {
                    btd1.setEnabled(false);
                    shrinkInformationWindow.invertion.setEnabled(false);
                }
            }
            btd2.setEnabled(true);
        }
        
        public void setInvertionCondition()
        {
            for(int i=0;i<panelNumber;i++)
                if(panel[i].text.textID == 1)
                {
                    panel[i].text.focus.setInvertionFocusSegments();
                    return;
                }
            text.focus.setInvertionFocusSegments();
        }
        
        public void reviseInvertionCondition(int number)
        {
            System.out.println("reviseInvertion: number="+number);
            if(number == 0 || number == text.segmentNumber)
                return;
            if(shrinkData[shrinkCount] == null)
                return;
            
            if(shrinkInformationWindow != null)
                shrinkInformationWindow.reviseInvertionData(number, shrinkData, shrinkCount);
        }
        
        public void writeToolNameLog()
        {
            ACTIONLOG.writeActionLog("FOCUS*SHRINK*TOOLNAME*"+shrinkData[shrinkCount].toolName);
        }
        
        public void addCondition()
        {
            writeToolNameLog();
            
            if(shrinkCount >= maxShrink)
            {
                shrinkCount = maxShrink;
                btd1.setEnabled(false);
                if(shrinkInformationWindow != null)
                    shrinkInformationWindow.invertion.setEnabled(false);
                    
                return;
            }
            else
            {
                shrinkCount++;
                shrinkData[shrinkCount] = new ShrinkData();
                shrinkCurrentMax = shrinkCount;
                if(shrinkInformationWindow != null)
                {
                    shrinkInformationWindow.reSize(baseHeight, shrinkCount, sp1.fontSize);
                    shrinkInformationWindow.undo.setEnabled(true);
                    shrinkInformationWindow.redo.setEnabled(false);
                }
            }
        }
        
        public void setCondition()
        {

            if(shrinkInformationWindow != null)
                shrinkInformationWindow.recallData(shrinkData, shrinkCount);

            if(shrinkCount == 0)
            {
                setPartialDocument(0, false);
                text.focus.clearAllFocus();
                
//                focus.resetCondition();
                
                for(int i=0;i<panelNumber;i++)
                    sp1.textID[i] = panel[i].text.textID;
                sp1.createBackupTextID(0); //BACKUP for TEXTID ONLY
                
                for(int i=0;i<panelNumber;i++)
                    if(panel[i].reExecution != null)
                        panel[i].reExecution.doClick();
            }
            else
            {
                TextData setText = getSetText();
                
                System.out.println("Shrink base textID= "+setText.textID);
                
                if(setText.textID == 0)
                    setPartialDocument(2, true);
//                else
                    text.focus.setFocusSegments(0,0,shrinkData[shrinkCount-1].originalFocusSegments,"","",false); //ALL  ////
                
//                focus.addCondition();       ////
                
                resetBySegmentPartialData(0);
                
                btd1.setEnabled(false);
                if(shrinkInformationWindow != null)
                    shrinkInformationWindow.invertion.setEnabled(false);
                btd2.setEnabled(true);
                
                for(int i=0;i<panelNumber;i++)
                    sp1.textID[i] = panel[i].text.textID;
                sp1.createBackupTextID(1); //BACKUP for TEXTID ONLY
            }
            
            if(shrinkCount > 0)
                for(int i=0;i<shrinkData[shrinkCount-1].originalFocusSegments.length;i++)
                    System.out.println("<>"+shrinkData[shrinkCount-1].originalFocusSegments[i]);
        }
        
        public void resetCondition()
        {
            shrinkCount = 0;
            shrinkCurrentMax = 0;
            if(shrinkInformationWindow != null)
                shrinkInformationWindow.resetPanel();
            
            btd1.setEnabled(false);
            if(shrinkInformationWindow != null)
            {
                shrinkInformationWindow.invertion.setEnabled(false);
                shrinkInformationWindow.undo.setEnabled(false);
                shrinkInformationWindow.redo.setEnabled(false);
            }
            btd2.setEnabled(false);

            /*
            //Window close
            if(shrinkInformationWindow != null)
                shrinkInformationWindow.dispose();
            shrinkInformationWindow = null;
             */
        }
        


	}
	public Focus focus;
	


	public Control(MainFrame mainf, String file, String absolute, boolean english, boolean utf8code)
	{
		this.mainf = mainf;
		absolutePath = absolute;
        this.utf8code = utf8code;

		setBackground(Color.white);
		
		splitpane = new JSplitPane[MAX_PANEL];
		
		addComponentListener(this);
		

        ACTIONLOG.setStartTime();
        ACTIONLOG.createPClog(mainf);
        
        ACTIONLOG.setLogDirectory(absolutePath);
        ACTIONLOG.initializeLogDirectoryNameList();
        ACTIONLOG.createLogDirectory();


        
		
		System.out.println("S1");
		
		//Panel Creation 1
		setLayout(new BorderLayout());
		upperPanel = new JPanel(new GridLayout());
		add(upperPanel);
		
		selectPanel = new JPanel(new GridLayout());
		upperPanel.add(selectPanel, "select");
		
		System.out.println("S2");		
		
		//Data Settings - 1
		readModuleData = new ModuleData(absolutePath);	
		

		
		settingFile = absolutePath + "tetdm.conf";
		sp1 = new SettingData(settingFile, readModuleData);			//NOTICE: moduleData in sp1 is different from control.moduleData
        
        if(sp1.windowSizeX == 0)
            sp1.windowSizeX = mainf.windowSizeX;
        if(sp1.windowSizeY == 0)
            sp1.windowSizeY = mainf.windowSizeY;
        
        sp1.popSizeY = mainf.popSizeY;
		
        if(english)
        {
            sp1.isEnglish = true;
            sp1.excludeHankaku = false;
        }

		expFile = absolutePath + "source" + File.separator + "GameMode" + File.separator + "tetdm.exp";
		ex1 = new ExpData(expFile);
		
		System.out.println("S3");		
		
		//Data Settings - 2

		mainf.reSize(sp1.windowSizeX, sp1.windowSizeY, sp1.popSizeY, sp1.gameMode);


        
		resetModuleData();		//ModuleDataCreation from readModuleData to ModuleData

		

		if(sp1.panels > 0)
			panelNumber = sp1.panels;
		else
			panelNumber = defaultPanelNumber;
		
		balancedPanelSizeX = sp1.balancedPanelSizeX;
		
		
		focus = new Focus(); //////
		
		System.out.println("S4");		
	

		windowNameInJapanese = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "japaneseText" + File.separator + "windowName.txt"));
		
		//Panel Creation 2		
//		settingPanel = new SettingPanel(sp1);
//		upperPanel.add(settingPanel, "setting");
		
		panel = new Select[MAX_PANEL];

		readJapaneseLabels();
		initializeButtonPanel();
        
//		this.windowSizeX = mainf.windowSizeX;
		createMenuWindow();
//        PopUpWindow pop = new PopUpWindow(0,0, mainf.windowSizeX, mainf.popSizeY);
	
		
		selectionAssistData = new SelectionAssistData(this);
/*		openCombinationWindow();
		autoSet = true;	
		bt72.setSelected(true);
		autoSet = false;	*/
        

        if(sp1.gameMode == true)
        {
            autoSet = true;
            bt81.setSelected(true);
            autoSet = false;
            System.out.println("--------GAME MODE ON--------");
        }
        
		System.out.println("S5");
        
        
        //SHRINK WINDOW
        btd1.setEnabled(false);
        btd2.setEnabled(false);
        
        mainf.logStart = true;
        if(popUpForSelectionAssist != null)
            popUpForSelectionAssist.logStart = true;
        
        //        System.out.println("ID = 1,1");
        //        System.out.println("Name"+readModuleData.miningModuleNamesInJapanese[readModuleData.findModule(39)]);
        //        System.out.println("Name"+readModuleData.visualizationModuleNamesInJapanese[readModuleData.findVisualizationModule(1101)]);
        
        /*
         int a[]={1,11};
         int b[]={1,8};
         
         panelSetForHistoryReplay(a,b);
         */
        
        if(sp1.isWindows)
            baseHeight += menuMargin;
        

        
        if(sp1.inJapanese)
            shrinkInformationWindow = new PopUpForShrinkInformation(sp1.windowSizeX-800, sp1.popSizeY, 800, baseHeight, sp1.fontSize, sp1.fontName, inJapanese[15], absolutePath, this);
        else
            shrinkInformationWindow = new PopUpForShrinkInformation(sp1.windowSizeX-800, sp1.popSizeY, 800, baseHeight, sp1.fontSize, sp1.fontName, "Data (Segment: Paragraph, Document) Shrink Condition >Hit Number", absolutePath, this);
        
        autoSet = true;
        btd3.setSelected(true);
        autoSet = false;
        
        
        
        
        System.out.println("S6");

		createProcessingPop();
        
        if(file.indexOf(File.separator) != 0)  //without absolutePATH
            textDataLoading(absolutePath+file);
        else
            textDataLoading(file);          //activated from TETDM.app
        
		initializeSelectPanel(2);		//need selection assist data
		
		System.out.println("S7");
		
        //INTERPRETATION
		interpretationNumber = 0;
//		bt77.setEnabled(false);
		bt78.setEnabled(false);		
		interpretation = new Interpretation[maxInterpretationNumber];
        
        readInterpretation();
		
        //NAVIGATION
        navigationControl = new NavigationControl(this);
        
        
        {
            String clearCheckerOperation[];
            clearCheckerOperation = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "Tutorial" + File.separator + "serif" + File.separator+ "ClearCheckOperation.txt"));
        
            if(Integer.parseInt(clearCheckerOperation[0]) < 5)
            {
                firstActivationConfirmation();
                sp1.saveActivationFile();
            }
            else if(sp1.navigation == true)
            {
                navigationControl.setSoundNumber(102);
            }
            
            
        }

	}

    //SET MODE
    public void setMode(int n)
    {
        focus.clearAllFocus();
        text.focus.clearAllFocus();
        
        sp1.mode = n;
        sp1.setMode();
        
        switch(sp1.mode)
        {
            case 0:
                break;
                
            case 1:
                break;
                
            case 2:
                break;
                
            case 3:
                text.initializePartialText();
                break;
        }
        
        closeAllWindows();
        
        reSizeWindow();
        resetModuleData();
        
        pop.popPanel.remove(buttonPanel);
        initializeButtonPanel();
        pop.popPanel.add(buttonPanel,BorderLayout.SOUTH);
        pop.popPanel.revalidate();
        
        panelsReConstruction(1);
        
        selectionAssistData.countNumber();
        //        openCombinationWindow();
        
        System.out.println("Mode Changed to "+sp1.mode);
    }
    
	public void resetModuleData()
	{
		moduleData = new ModuleData(readModuleData, sp1.mode);
		
		for(int i=0;i<sp1.panels;i++)
		{
			int mindex = moduleData.findModule(sp1.miningID[i]);
			if(mindex != -1)
				moduleData.miningModuleSelection[mindex] = true;
		}
		moduleData.initializeVisualiationModuleSelection();
		
		for(int i=0;i<sp1.panels;i++)
		{
			int vindex = moduleData.findVisualizationModule(sp1.visualizationID[i]);
			if(vindex != -1)
				moduleData.visualizationModuleSelection[vindex] = true;
		}
		
		moduleData.initializeModuleSubset();
	}
    

	
	public void reSizeWindow() //MODE CHANGE
	{
        createMenuWindow();
        mainf.reSize(sp1.windowSizeX, sp1.windowSizeY, sp1.popSizeY, sp1.gameMode);
        shrinkInformationWindow.setLocation(sp1.windowSizeX-800, sp1.popSizeY);
	}
	
	public void createMenuWindow()
	{
		if(sp1.gameMode == true)
			pop = new PopUpWindow(0,0, sp1.windowSizeX, sp1.popSizeY*2, this);
		else
			pop = new PopUpWindow(0,0, sp1.windowSizeX, sp1.popSizeY);
	}
	
    public void reSizeFont()
    {
//        buttonPanel
        resetFontsizeForButtonPanel();
// //     shrinkWindow
        
//      SelectPanel
//      MiningModule, VisualizationModule
//      Tutorial
    
    }
 
/*	
	void calculateDefaultPanelSizeInitial(int panelNum)
	{
		if(panelNum == 1)
			defaultPanelSizeX = sp1.windowSizeX;
		else
			defaultPanelSizeX = (sp1.windowSizeX - (11*(panelNum-1)))/panelNum;

		defaultPanelSizeY = sp1.windowSizeY - 194;
	}
	
	void calculateDefaultPanelSize(int panelNum)
	{
		if(panelNum == 1)
			defaultPanelSizeX = getWidth();
		else
			defaultPanelSizeX = (getWidth() - (11*(panelNum-1)))/panelNum;
		
		defaultPanelSizeY = getHeight() - 194;		
	}
*/
	void initializePanelSizeX()
	{
		for(int i=0;i<balancedPanelSizeX.length;i++)
			balancedPanelSizeX[i] = 1;			
	}
	
	void calculateBalancedPanelSizeInitial(int panelNum)
	{
		if(panelNum == 1)
			balancedPanelSizeX[0] = sp1.windowSizeX;
		else
		{
			int sum=0;
			for(int i=0;i<panelNum;i++)
				sum += balancedPanelSizeX[i];
			
			int max=0;
			max = sp1.windowSizeX - (11*(panelNum-1));
			
			for(int i=0;i<panelNum;i++)
				balancedPanelSizeX[i] = (int)((double)max * (double)balancedPanelSizeX[i]/(double)sum);
			for(int i=panelNum;i<MAX_PANEL;i++)
				balancedPanelSizeX[i] = (sp1.windowSizeX - (11*i))/(i+1);
		}		
		defaultPanelSizeY = sp1.windowSizeY - 194;
	}	

	void calculateBalancedPanelSize(int panelNum)
	{
		if(panelNum == 1)
			balancedPanelSizeX[0] = getWidth();
		else
		{
			int sum=0;
			for(int i=0;i<panelNum;i++)
				sum += balancedPanelSizeX[i];
			
			int max=0;
			max = getWidth() - (11*(panelNum-1));
			
			for(int i=0;i<panelNum;i++)
				balancedPanelSizeX[i] = (int)((double)max * (double)balancedPanelSizeX[i]/(double)sum);
			for(int i=panelNum;i<MAX_PANEL;i++)
				balancedPanelSizeX[i] = (getWidth() - (11*i))/(i+1);			
		}
		defaultPanelSizeY = getHeight() - 194;		
	}
	
	void getBalancedPanelSize(int panelNum)
	{
		if(panelNum == 1)
			balancedPanelSizeX[0] = getWidth();
		else
			for(int i=0;i<panelNum;i++)
				balancedPanelSizeX[i] = panel[i].getWidth();
	}	


	
	void textDataLoading(String loadFile)
	{
		//TEXT READ
		original_file = loadFile;		//Original text file
		read_filename = loadFile+"2";	//Copied text file

            String originalText = EXECUTE.fileReadCopy(loadFile, read_filename, "SHIFT-JIS", utf8code);	//make copy, ALL procedures only for this copy
			
			if(System.getProperty("line.separator").equals("\r\n"))
			{
				originalText = originalText.replaceAll("\r\n","KAIGYORN");
				originalText = originalText.replaceAll("\r","KAIGYORN");
				originalText = originalText.replaceAll("\n","KAIGYORN");
				originalText = originalText.replaceAll("KAIGYORN",System.getProperty("line.separator"));
			}
			if(System.getProperty("line.separator").equals("\r"))
			{
				originalText = originalText.replaceAll("\r\n",System.getProperty("line.separator"));
				originalText = originalText.replaceAll("\n",System.getProperty("line.separator"));
			}
			if(System.getProperty("line.separator").equals("\n"))
			{
				originalText = originalText.replaceAll("\r\n",System.getProperty("line.separator"));
				originalText = originalText.replaceAll("\r",System.getProperty("line.separator"));
			}
			
			textDataReset(originalText);
        

	}
	
	public void textDataLoadingAgain()
	{
            String originalText = EXECUTE.fileReadCopy(original_file, read_filename, "SHIFT-JIS", utf8code);	//make copy, ALL procedures only for this copy
			
		if(System.getProperty("line.separator").equals("\r\n"))
		{
			originalText = originalText.replaceAll("\r\n","KAIGYORN");
			originalText = originalText.replaceAll("\r","KAIGYORN");
			originalText = originalText.replaceAll("\n","KAIGYORN");
			originalText = originalText.replaceAll("KAIGYORN",System.getProperty("line.separator"));
		}
		if(System.getProperty("line.separator").equals("\r"))
		{
			originalText = originalText.replaceAll("\r\n",System.getProperty("line.separator"));
			originalText = originalText.replaceAll("\n",System.getProperty("line.separator"));
		}
		if(System.getProperty("line.separator").equals("\n"))
		{
			originalText = originalText.replaceAll("\r\n",System.getProperty("line.separator"));
			originalText = originalText.replaceAll("\r",System.getProperty("line.separator"));
		}
			
			textDataReset(originalText);		
	}

	public void textDataReset(String originalText)
	{
		String source_filename = new File(read_filename).getAbsolutePath();
		String ext = "";
		
		int point = source_filename.lastIndexOf(".");
		if (point != -1) 
		{
			ext = source_filename.substring(point + 1);
		}		
		
		sp1.isCsv = false;
		if(sp1.isEnglish == true)
		{
            sp1.excludeHankaku = false;
			System.out.println("English Mode ON");
		}
		else if(ext.equals("csv2"))
		{
			sp1.isCsv = true;
			System.out.println("CSV Mode ON");
		}
		
        sp1.resetTempNoise();
        text = new TextData(0, source_filename, originalText, sp1, absolutePath, this);
        
        ////////////////
        if(sp1.minimumFrequency != 1)
        {
            sp1.createTempNoiseByFrequency(text.keyword, text.keywordNumber, sp1.minimumFrequency);
            text = new TextData(0, source_filename, originalText, sp1, absolutePath, this);
        }
        ////////////////
        
        checkPosiNega();
        
        //CHECK NEW DATA LOADING
        if(originalText.length() > 0)
            if(navigationControl != null)
                navigationControl.setSoundNumber(220);
	}
    
    public void checkPosiNega()
    {
        String posiDic[];
        String negaDic[];
        String forwardNegation[];
        String backwardNegation[];
       
        posiDic = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "japaneseText" + File.separator + "posiDic.txt"), "UTF-8");
        negaDic = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "japaneseText" + File.separator + "negaDic.txt"), "UTF-8");
        forwardNegation = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "japaneseText" + File.separator + "forwardNegationDic.txt"));
        backwardNegation = FILEIO.TextFileAllReadCodeArray(new File(absolutePath + "source" + File.separator + "japaneseText" + File.separator + "backwardNegationDic.txt"));
        
        String temp[];
        
        /*
        for(int i=0;i<posiDic.length;i++)
        {
            temp = posiDic[i].split(",");
            if(temp.length == 2)
                posiDic[i] = temp[0];
        }
        
        for(int i=0;i<negaDic.length;i++)
        {
            temp = negaDic[i].split(",");
            if(temp.length == 2)
                negaDic[i] = temp[0];
        }
        */
        Comparator<String> c = new Comparator<String>() {
            public int compare(String str1, String str2) {
                return str1.compareTo(str2);
            }
        };
        
        Arrays.sort(posiDic, c);
        Arrays.sort(negaDic, c);

        //Keywords
        for(int i=0;i<text.keywordNumber;i++)
        {
            if(Arrays.binarySearch(posiDic, text.keyword[i].word, c) >= 0)
                text.keyword[i].posiNega = 1;
            else if(Arrays.binarySearch(negaDic, text.keyword[i].word, c) >= 0)
                text.keyword[i].posiNega = -1;
        }

        //Words except Keywords //jishoni hinshigaareba sonohinshiwonozoitamonodakede loopwo mawaseru
        for(int i=0;i<text.sentenceNumber;i++)
            for(int j=0;j<text.sentence[i].wordNumber;j++)
            {
                if(text.sentence[i].wordIDList[j] > 0)
                    text.sentence[i].wordPosiNega[j] = text.keyword[text.sentence[i].wordIDList[j]].posiNega;
                else
                {
                    if(Arrays.binarySearch(posiDic, text.sentence[i].wordEndForm[j], c) >= 0)
                        text.sentence[i].wordPosiNega[j] = 1;
                    else if(Arrays.binarySearch(negaDic, text.sentence[i].wordEndForm[j], c) >= 0)
                        text.sentence[i].wordPosiNega[j] = -1;
                }
            
                if(text.sentence[i].wordPosiNega[j] != 0)
                {                
                    if(j != 0)
                        if(forwardNegationCheck(forwardNegation, text.sentence[i].word[j-1]))
                           text.sentence[i].wordPosiNega[j] *= -1;
                           
                    int border = j+5;
                    if(border > text.sentence[i].wordNumber)
                        border = text.sentence[i].wordNumber;
                    for(int k=j+1;k<border;k++)
                        if(forwardNegationCheck(backwardNegation, text.sentence[i].word[k]))
                            text.sentence[i].wordPosiNega[j] *= -1;         // not using [break] for considering double negation

                    /*
                    String word = "";
                    int border = j+5;
                    if(border > text.sentence[i].wordNumber)
                        border = text.sentence[i].wordNumber;
                    for(int k=j+1;k<border;k++)
                        word += text.sentence[i].word[k];
                        
                    if(backwardNegationCheck(backwardNegation, word))
                        text.sentence[i].wordPosiNega[j] *= -1;
                     */
                }
            }
        
        //2. Adjective adjustment   // Verb adjustment : forward only
        for(int i=0;i<text.sentenceNumber;i++)
            for(int j=0;j<text.sentence[i].wordNumber;j++)
                if(text.sentence[i].wordPosiNega[j] !=0 && text.sentence[i].wordIDList[j] >= 0)
                    if(text.keyword[text.sentence[i].wordIDList[j]].partOfSpeech == 3)  //Adjective
                    {
                        backwardAdjectiveAdjustment(text.sentence[i],j);
                        forwardAdjectiveAdjustment(text.sentence[i],j);
                    }
                    else if(text.keyword[text.sentence[i].wordIDList[j]].partOfSpeech == 2) //Verb
                        forwardAdjectiveAdjustment(text.sentence[i],j);
        
        //3. Compound Noun adjustment
        for(int i=0;i<text.sentenceNumber;i++)
            for(int j=0;j<text.sentence[i].wordNumber;j++)
                if(text.sentence[i].wordPosiNega[j] !=0 && text.sentence[i].wordIDList[j] >= 0)
                    if(text.keyword[text.sentence[i].wordIDList[j]].partOfSpeech == 1)
                        forwardCompoundNounAdjustment(text.sentence[i],j);
        
        //4. Compound adjustment
        for(int i=0;i<text.sentenceNumber;i++)
            for(int j=1;j<text.sentence[i].wordNumber;j++)
                if(text.sentence[i].wordPosiNega[j] !=0 && text.sentence[i].wordPosiNega[j-1] !=0)
                    text.sentence[i].wordPosiNega[j-1] = 0;
        
        
        //Sentences
        for(int i=0;i<text.sentenceNumber;i++)
        {
            text.sentence[i].posiNega = 0;
            for(int j=0;j<text.sentence[i].wordNumber;j++)
                text.sentence[i].posiNega += text.sentence[i].wordPosiNega[j];
        }
        
        //Segments
        for(int i=0;i<text.segmentNumber;i++)
        {
            text.segment[i].posiNega = 0;
            for(int j=0;j<text.segment[i].sentenceNumber;j++)
                text.segment[i].posiNega += text.segment[i].sentence[j].posiNega;
        }
        
        System.out.println("-------------LOADED POSI-NEGA DIC words (posi = "+posiDic.length+" , nega = "+negaDic.length+")-------------");
    }
    
    public boolean forwardNegationCheck(String forwardNegation[], String word)// check forward : true if matched
    {
        for(int i=0;i<forwardNegation.length;i++)
            if(word.equals(forwardNegation[i]))
                return true;

        return false;
    }
    
    public boolean backwardNegationCheck(String backwardNegation[], String word)// check backward : true if matched
    {
        for(int i=0;i<backwardNegation.length;i++)
            if(word.equals(backwardNegation[i]))
                return true;
        
        return false;
    }
    
    /*
    public boolean backwardNegationCheck(String backwardNegation[], String word)// check backward : true if matched
    {
        for(int i=0;i<backwardNegation.length;i++)
            if(word.contains(backwardNegation[i]))
                return true;
        
        return false;
    }*/
    
    public void backwardAdjectiveAdjustment(SentenceData sentence, int wordPosition)
    {
//        System.out.println("backwardAdjectiveAdjustment");
        
        for(int i=wordPosition+1; i<sentence.wordNumber; i++)
        {
            if(sentence.wordIDList[i] < 0)
                return;
             
            if(text.keyword[sentence.wordIDList[i]].partOfSpeech != 1)
                return;
            else
                sentence.wordPosiNega[i] = 0;
        }
    }
    
    public void forwardAdjectiveAdjustment(SentenceData sentence, int wordPosition)
    {
//        System.out.println("forwardAdjectiveAdjustment");
        
        if(wordPosition <= 1)
            return;
        
        if(sentence.wordPosiNega[wordPosition-1] != 0)
            return;
        
        for(int i=wordPosition-2; i>=0; i--)
        {
            if(sentence.wordIDList[i] < 0)
                return;
             
            if(text.keyword[sentence.wordIDList[i]].partOfSpeech != 1)
                return;
            else
                sentence.wordPosiNega[i] = 0;
        }
    }
    
    public void forwardCompoundNounAdjustment(SentenceData sentence, int wordPosition)
    {
//        System.out.println("forwardCompoundNounAdjustment");
        
        if(wordPosition < 1)
            return;
        
        for(int i=wordPosition-1; i>=0; i--)
        {
            if(sentence.wordIDList[i] < 0)
                return;
             
            if(text.keyword[sentence.wordIDList[i]].partOfSpeech != 1)
                return;
            else
                sentence.wordPosiNega[i] = 0;
        }
    }
    

    
	////////////FOR TUTORIAL
    public MiningModule getPanel0Mining()
    {
        return panel[0].mining[panel[0].selected_module];
    }
    
	void setBalancedSplitDivider(int n)
	{
		int divideLine=0;
		for(int i=0;i<=n;i++)
			divideLine += balancedPanelSizeX[i];
		if(n > 0)
			divideLine += 11 * (n - 1);
		splitpane[n].setDividerLocation(divideLine);		
	}		
	
	void setPanels()
	{
		if(panelNumber == 1)
			selectPanel.add(panel[0]);
		else
		{
			for(int i=0;i<panelNumber-1;i++)
			{
				splitpane[i] = new JSplitPane();
				splitpane[i].setOneTouchExpandable(true);
				splitpane[i].setContinuousLayout(true);				
				
				setBalancedSplitDivider(i);
				
				splitpane[i].setRightComponent(panel[i+1]);
				if(i==0)
					splitpane[0].setLeftComponent(panel[0]);
				else
					splitpane[i].setLeftComponent(splitpane[i-1]);
			}
			selectPanel.add(splitpane[panelNumber-2]);
		}
		
		writePanelSizeLog();		
	}
	
	PopUpForProcessing processingPanel = null;
	
	//DISPLAY PROCESS
	public void createProcessingPop()
	{
		String windowTitle = "Data Processing";
		if(sp1.inJapanese)
			windowTitle = windowNameInJapanese[15];		
		
		if(processingPanel == null)
			processingPanel = new PopUpForProcessing(sp1.windowSizeX/2 - 250, 300,500,300, "Now Processing", Color.yellow, absolutePath, sp1.fontName, windowTitle);
	}
	
	public void setProcessingPercent(int percent)
	{
		if(processingPanel != null)
			processingPanel.setPercent(percent);
	}		
	
	public void disposeProcessingPop()
	{
		if(processingPanel != null)
		{
			processingPanel.dispose();
			processingPanel = null;
		}
	}	
	
    //CLOSE WINDOWS
    
    public void closePanelWindow()
    {
        for(int i=0;i<panelNumber;i++)
            panel[i].closeAllWindows();
    }
    
    public void closeAllWindows()
    {
        disposeProcessingPop();        //Processing pop
       	closeCombinationWindow();        //tool set combination window
        closePopForSetModule();
        closePopForSetModuleImage();
        closePopForWordToolSelect();
        closePopForSupport();
        closePopForSupportDeveloper();
        closePopForInterpretationList();
        closePopForKnowledgeCreation();
        closePopForSetting();
        closePopForModeSetting();
        closePopForNavigation();
        closePopForStory();
        
        closePanelWindow();
        
        focus.resetCondition();//////////////
    }
    /*
	void initializeSelectPanel(int a)
	{
		
		if(sp1.mode == 0)
		{
			panelNumber = selectionAssistData.originalPanelNumber[0];
            sp1.panels = panelNumber;
            
			for(int i=0;i<panelNumber;i++)
            {
				balancedPanelSizeX[i] = selectionAssistData.originalSizeX[0][i];
                sp1.balancedPanelSizeX[i] = selectionAssistData.originalSizeX[0][i];
            }
		}
		
		
		if(first)
		{
			calculateBalancedPanelSizeInitial(panelNumber);	
			//			calculateDefaultPanelSizeInitial(panelNumber);	
			first = false;
		}
		else
			//			calculateDefaultPanelSize(panelNumber);
			calculateBalancedPanelSize(panelNumber);
		
		stealthPanel = new Select(text, 10000, moduleData, inJapanese, 0, 0);
		
		setProcessingPercent((int)(1*100/(panelNumber+1)));
		
		
		if(sp1.mode == 0)
		{
			for(int i=0;i<panelNumber;i++)
			{
				panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);			
				panel[i].setMinimumSize(new Dimension(0,0));
				panel[i].changePanel(selectionAssistData.originalMiningIDs[0][i],selectionAssistData.originalVisualizationIDs[0][i]);
				
				System.out.println(selectionAssistData.originalMiningIDs[0][i]+" : "+selectionAssistData.originalVisualizationIDs[0][i]);
				
				setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
                
                sp1.miningID[i] = selectionAssistData.originalMiningIDs[0][i];
                sp1.visualizationID[i] = selectionAssistData.originalVisualizationIDs[0][i];
			}
            
			
            
		}
		else
		{
			for(int i=0;i<panelNumber;i++)
			{
				//				panel[i] = new Select(text, i, moduleData, inJapanese, defaultPanelSizeX, defaultPanelSizeY);
				panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);			
				panel[i].setMinimumSize(new Dimension(0,0));
				panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i]);
				
				System.out.println(sp1.miningID[i]+" : "+sp1.visualizationID[i]);
				
				setProcessingPercent((int)((1+i)*100/(panelNumber+1)));			
			}
		}
		
		setPanels();
		
		disposeProcessingPop();
	}
    */
	
    void resetFontsizeForButtonPanel()
    {
        /*
        bt52.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        bt40.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        bt50.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        bt70.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        bt99.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        btTutorial.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        bt81.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        btd1.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
        btd3.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
*/
        
        switch(sp1.mode)
        {
            case 0:
                bt55.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt0.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//keyword
                bt00.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//mode
                bt77.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//list
                bt78.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//list
                bt79.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//list
                bt71.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//balance
                bt90.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//camera image
                bt72.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//appli
                bt10.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//reload
                
                //                btTutorial.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //character assist
                btxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//user
                btxxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//developer
                
                btx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//name
                btxImage.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//image
                btxTree.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//tool
                bt60.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//back
                
                bt20.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font-
                bt30.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font+
                
                btd2.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink reset
                break;
                
            case 1:
                bt55.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt0.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt00.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt77.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt78.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt79.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt71.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt90.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt72.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt10.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                
                //                btTutorial.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //character assist
                btxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//user
                btxxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//developer
                
                btx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//name
                btxImage.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//image
                btxTree.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//tool
                bt60.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//back
                
                bt20.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font-
                bt30.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font+
                break;
                
            case 2:
                bt55.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt0.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt00.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt77.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt78.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt79.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt71.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt90.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt72.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                bt10.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));
                
                //                btTutorial.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //character assist
                btxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//user
                btxxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//developer
                
                btx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//name
                btxImage.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//image
                btxTree.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize));//tool
                bt60.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));//back
                
                bt20.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font-
                bt30.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize)); //font+
                
                btd1.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink
                btd2.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink reset
                btd3.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink information window
                break;
                
            case 3:
                bt55.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt0.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt00.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));
                bt77.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt78.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt79.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt71.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));
                bt90.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));
                bt72.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));
                bt10.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));
                
                //                btTutorial.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //character assist
                btxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));//user
                btxxx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4));//developer
                
                btx.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));//name
                btxImage.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));//image
                btxTree.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));//tool
                bt60.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-2));//back
                
                
                bt40.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //+
                bt71.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //=
                bt20.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //font-
                bt30.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //font+
                
                
                btd1.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink
                btd2.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink reset
                btd3.setFont(new Font(sp1.fontName, Font.PLAIN, sp1.fontSize-4)); //shrink information window
                break;
        }
    }
    
	void initializeSelectPanel(int option) //0:normal, 1:mode changed, 2:after just activated(only once)
	{
		if(option == 1 || option == 2)
            resetFontsizeForButtonPanel();
        
		if(sp1.mode == 0 || option == 1)// mode changed
		{
			panelNumber = selectionAssistData.originalPanelNumber[0];
            sp1.panels = panelNumber;
            
			for(int i=0;i<panelNumber;i++)
            {
				sp1.miningID[i] = selectionAssistData.originalMiningIDs[0][i];
				sp1.visualizationID[i] = selectionAssistData.originalVisualizationIDs[0][i];
                sp1.textID[i] = selectionAssistData.originalTextIDs[0][i];
				
				balancedPanelSizeX[i] = selectionAssistData.originalSizeX[0][i];
//                sp1.balancedPanelSizeX[i] = selectionAssistData.originalSizeX[0][i];  //same pointer with the above
            }
			
			sp1.createBackupID();	//BACKUP				
		}        

		if(first)
		{
			calculateBalancedPanelSizeInitial(panelNumber);
			sp1.createBackupID();	//BACKUP			
			first = false;
		}
		else
			calculateBalancedPanelSize(panelNumber);
		
        //////////////////////////
        TextData settingText;
        if(option == 0)
            settingText = getSetText();
        else
            settingText = text; //ALL

  //       stealthPanel = new Select(text, 10000, moduleData, inJapanese, 0, 0);
       stealthPanel = new Select(settingText, 10000, moduleData, inJapanese, 0, 0);
		
		setProcessingPercent((int)(1*100/(panelNumber+1)));
		
		
		
		if(sp1.mode == 0 || option == 1)// mode changed
			resetModuleData();
			
        System.out.println("---------------SET START---------------");
        
		for(int i=0;i<panelNumber;i++)
		{
//                        panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);
            if(sp1.miningID[i] != 44) //SetSegment
                panel[i] = new Select(settingText, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);
            else
                panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);
            
			panel[i].setMinimumSize(new Dimension(0,0));
			panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i]);
				
            System.out.println("Mode="+sp1.mode+" "+sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : <<textID = "+settingText.textID+">> : "+balancedPanelSizeX[i]);
//            System.out.println("Mode="+sp1.mode+" "+sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : "+balancedPanelSizeX[i]);
            
			setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
		}
        
        System.out.println("---------------SET END---------------");

		setPanels();
		disposeProcessingPop();
        
        if(option == 1 || option == 2)
        {
            btd2.doClick();
        }
	}
/*
	void checkPanelCreated()
	{
		for(int i=0;i<panelNumber;i++)
			panel[i].mining[panel[i].selected_module].visualization.panelCreated = true;		
	}
*/
    
    void initializeSelectPanelwithoutSegSegment(int panelID, int textID)
    {
        if(first)
        {
            calculateBalancedPanelSizeInitial(panelNumber);
            //			calculateDefaultPanelSizeInitial(panelNumber);
            first = false;
        }
        else
            //			calculateDefaultPanelSize(panelNumber);
            calculateBalancedPanelSize(panelNumber);
        
        stealthPanel = new Select(text, 10000, moduleData, inJapanese, 0, 0);
        
        setProcessingPercent((int)(1*100/(panelNumber+1)));
        

        
        for(int i=0;i<panelNumber;i++)
            if(i != panelID)
            {
                //			panel[i] = new Select(text, i, moduleData, inJapanese, defaultPanelSizeX, defaultPanelSizeY);
                panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);
                panel[i].setMinimumSize(new Dimension(0,0));
//                panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i], textID);//tIDs[i]);
                panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i], sp1.textID[i]);
                
//                System.out.println(sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : "+textID+" from SetSegment");
                System.out.println(sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : "+sp1.textID[i]+" from SetSegment");
                
                setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
            }
        

        
        setPanels();
        disposeProcessingPop();
    }    
	
//    void initializeSelectPanel(int tIDs[])
    void initializeSelectPanel()
	{
		if(first)
		{
			calculateBalancedPanelSizeInitial(panelNumber);	
			//			calculateDefaultPanelSizeInitial(panelNumber);	
			first = false;
		}
		else
			//			calculateDefaultPanelSize(panelNumber);
			calculateBalancedPanelSize(panelNumber);
		
		stealthPanel = new Select(text, 10000, moduleData, inJapanese, 0, 0);
		
		setProcessingPercent((int)(1*100/(panelNumber+1)));
		
		for(int i=0;i<panelNumber;i++)
		{
			//			panel[i] = new Select(text, i, moduleData, inJapanese, defaultPanelSizeX, defaultPanelSizeY);
			panel[i] = new Select(text, i, moduleData, inJapanese, balancedPanelSizeX[i], defaultPanelSizeY);			
			panel[i].setMinimumSize(new Dimension(0,0));			
//            panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i], tIDs[i]);
            panel[i].changePanel(sp1.miningID[i],sp1.visualizationID[i], sp1.textID[i]);
			
//            System.out.println(sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : "+tIDs[i]);
            System.out.println(sp1.miningID[i]+" : "+sp1.visualizationID[i]+" : "+sp1.textID[i]);
			
			setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
		}
		
		
		
		setPanels();
        
        
		for(int i=0;i<panelNumber;i++)
        {
//            if(tIDs[i] < 0)       // for Diff Panel
            if(sp1.textID[i] < 0)       // for Diff Panel
                panel[i].createDiffPanel();
        }
		
		disposeProcessingPop();		
	}
	
	//ADD PANEL
	public void addNewPanel(TextData text)
	{
		if(panelNumber > MAX_PANEL - 1)
			return;	
		
		sp1.createBackupID();	//BACK UP		
		
//		calculateDefaultPanelSize(panelNumber+1);
		calculateBalancedPanelSize(panelNumber+1);
//		panel[panelNumber] = new Select(text, panelNumber, moduleData, inJapanese, defaultPanelSizeX, defaultPanelSizeY);
		panel[panelNumber] = new Select(text, panelNumber, moduleData, inJapanese, balancedPanelSizeX[panelNumber], defaultPanelSizeY);		
		panel[panelNumber].setMinimumSize(new Dimension(0,0));
		
		splitpane[panelNumber-1] = new JSplitPane();
		
		for(int i=0;i<panelNumber;i++)
//			setSplitDivider(i);			
			setBalancedSplitDivider(i);			

		
		splitpane[panelNumber-1].setRightComponent(panel[panelNumber]);
		
		if(panelNumber == 1)
		{
			selectPanel.remove(panel[0]);
			splitpane[0].setLeftComponent(panel[0]);
		}
		else
		{
			selectPanel.remove(splitpane[panelNumber-2]);			
			splitpane[panelNumber-1].setLeftComponent(splitpane[panelNumber-2]);
		}
		
		selectPanel.add(splitpane[panelNumber-1]);
		selectPanel.revalidate();			
		panelNumber++;
		
		sp1.panels = panelNumber;
	}	
	
	//DELETE PANEL
	void deleteSplitPane(int deleteNumber)
	{
		for(int i=deleteNumber;i<panelNumber-2;i++)
			splitpane[i] = splitpane[i+1];
	}
	
	void deletePanel(int deleteNumber)
	{
		for(int i=deleteNumber;i<panelNumber-1;i++)
		{
			panel[i] = panel[i+1];
			panel[i].setPanelID(i);
			panel[i].setTitle2();
			
			sp1.miningID[i] = sp1.miningID[i+1];
			sp1.visualizationID[i] = sp1.visualizationID[i+1];
            sp1.textID[i] = sp1.textID[i+1];
		}
		panelNumber--;
		sp1.panels = panelNumber;
	}

	void delete(int deleteNumber)
	{
		if(panelNumber == 1 || deleteNumber >= panelNumber || deleteNumber < 0)
			return;	
		
		sp1.createBackupID();	//BACK UP
		
//		calculateDefaultPanelSize(panelNumber-1);
		calculateBalancedPanelSize(panelNumber-1);
		
		selectPanel.remove(splitpane[panelNumber-2]);		
		for(int i=0;i<panelNumber-1;i++)
			splitpane[i].removeAll();
		
		deletePanel(deleteNumber);

		setPanels();		
		selectPanel.revalidate();		
	}	
    

	/*
    //Partial for Segments    
    public void resetBySegmentPartialData()
    {
        text.setSegmentPartialTextData(0);
        
		stealthPanel.resetAll_for_stealth(text.segmentPartialTextData[0]);	//FOR reset moduleData /////////// now 0 only

		for(int i=0;i<panelNumber;i++)
            if(panel[i].mining[panel[i].selected_module].combinationPanel.setFocusSegmentsButton.isSelected())
                panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();
    }
   
    //Partial for Sentences
    public void resetBySentencePartialData()
    {
        text.setSentencePartialTextData();
        
		stealthPanel.resetAll_for_stealth(text.sentencePartialTextData[0]);	//FOR reset moduleData /////////// now 0 only
        
		for(int i=0;i<panelNumber;i++)
            if(panel[i].mining[panel[i].selected_module].combinationPanel.setFocusSentencesButton.isSelected())
                panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();
    }
	 */
    //Partial for Segments   newly half created
    
    public void resetBySegmentPartialData(int number)
    {
        text.setSegmentPartialTextData(number);		//create Partial Data
        
		stealthPanel.resetAll_for_stealth(text.segmentPartialTextData[number]);
		
		for(int i=0;i<panelNumber;i++)		// this part should be modified
		{
//            panel[i].text = text.segmentPartialTextData[number];
            
			if(number == 0)
            {
				if(panel[i].mining[panel[i].selected_module].partialDocumentA == 2)
					panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();
            }
			
			if(number == 1)
            {
				if(panel[i].mining[panel[i].selected_module].partialDocumentA == 3)
					panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();
            }
		}
    }
    
    //Partial for Sentences   newly half created 
    public void resetBySentencePartialData(int number)
    {
        text.setSentencePartialTextData(number);
        
		stealthPanel.resetAll_for_stealth(text.sentencePartialTextData[number]);
        
		for(int i=0;i<panelNumber;i++)		// this part should be modified
		{
			if(number == 0)
				if(panel[i].mining[panel[i].selected_module].partialDocumentA == 4)
					panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();
			
			if(number == 1)
				if(panel[i].mining[panel[i].selected_module].partialDocumentA == 5)
					panel[i].mining[panel[i].selected_module].combinationPanel.resetModuleForPartialData();			
		}
    }
	
    public void setPartialDocument(int part, boolean autoSet)
    {
        for(int i=0;i<panelNumber;i++)
        {
            if(panel[i].mining[panel[i].selected_module].cancelPartialDocument == true)
                continue;
            
            panel[i].mining[panel[i].selected_module].partialDocumentA = part;
            panel[i].mining[panel[i].selected_module].setPartialDocument();
            
            if(autoSet)
                panel[i].mining[panel[i].selected_module].combinationPanel.autoSet = true;
            panel[i].mining[panel[i].selected_module].combinationPanel.partialDocument.setSelectedIndex(part);
            if(autoSet)
                panel[i].mining[panel[i].selected_module].combinationPanel.autoSet = false;
        }
    }
    /*
    public void setPartialSegment1()
    {
        for(int i=0;i<panelNumber;i++)
        {
            panel[i].mining[panel[i].selected_module].partialDocumentA = 2;
            panel[i].mining[panel[i].selected_module].setPartialDocument();
            panel[i].mining[panel[i].selected_module].combinationPanel.autoSet = true;
            panel[i].mining[panel[i].selected_module].combinationPanel.partialDocument.setSelectedIndex(2);
            panel[i].mining[panel[i].selected_module].combinationPanel.autoSet = false;
        }
    }
	*/
    /*
    public void resetStealthBySentencePartialData()
    {
		stealthPanel.resetAll_for_stealth(text.sentencePartialTextData[0]);	//FOR reset moduleData /////////// now 0 only
    }
    */
	
	//			createProcessingPop();
	//			setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
	//			disposeProcessingPop();
	
	
	public void resetSelectpanelData()
	{
		createProcessingPop();
		
		stealthPanel.resetAll_for_stealth(text);	//FOR reset moduleData
		
		for(int i=0;i<panelNumber;i++)
		{
			panel[i].resetAll(text);
			setProcessingPercent((int)((1+i)*100/(panelNumber+1)));			
		}
		
		disposeProcessingPop();
	}	
	
	public void resetSelectpanelData(TextData newText)
	{
		createProcessingPop();
		
		stealthPanel.resetAll_for_stealth(newText);	//FOR reset moduleData
		
		for(int i=0;i<panelNumber;i++)
		{
			panel[i].resetAll(newText);
			setProcessingPercent((int)((1+i)*100/(panelNumber+1)));
		}
		
		disposeProcessingPop();
	}

    //NEW FOCUS
    public void setDisplayOthersByFocus(int panelID)
    {
        for(int i=0;i<panelNumber;i++)
            if(i != panelID)
                panel[i].setDisplayByFocus();
    }
    //NEW FOCUS FROM SHRINK WINDOW
    public void setDisplayAllByFocus()
    {
        for(int i=0;i<panelNumber;i++)
            panel[i].setDisplayByFocus();
    }
    //NEW FOCUS
    public void resetSelectPanelDataByFocus(int panelID)
    {
        for(int i=0;i<panelNumber;i++)
            if(i != panelID)
                panel[i].resetMiningByFocus();
    }
    //NEW FOCUS    ALL
    public void resetSelectPanelDataByFocusAll(int panelID)
    {
        panel[panelID].resetMiningByFocus();
        resetSelectPanelDataByFocus(panelID);
    }
    //NEW FOCUS    ALL
    public void resetSelectPanelDataByFocusAll()
    {
        for(int i=0;i<panelNumber;i++)
            panel[i].resetMiningByFocus();
    }
    /*
	//FOCUS	
	public void setDisplayOthersByTouchFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
			if(i != panelID)
				panel[i].setDisplayByTouchFocus();
	}
	//FOCUS	
	public void setDisplayOthersByClickFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
			if(i != panelID)
				panel[i].setDisplayByClickFocus();
	}
	//FOCUS	
	public void setDisplayOthersByTimingFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
			if(i != panelID)
				panel[i].setDisplayByTimingFocus();
	}	
	//FOCUS
	public void resetSelectPanelDataByTouchFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
		    if(i != panelID)
				panel[i].resetMiningByTouchFocus();
	}
	//FOCUS
	public void resetSelectPanelDataByClickFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
		    if(i != panelID)
				panel[i].resetMiningByClickFocus();
	}
	//FOCUS
	public void resetSelectPanelDataByTimingFocus(int panelID)
	{
		for(int i=0;i<panelNumber;i++)
		    if(i != panelID)
				panel[i].resetMiningByTimingFocus();
	}	
	//FOCUS	ALL
	public void resetSelectPanelDataByTouchFocusAll(int panelID)
	{
		panel[panelID].resetMiningByTouchFocus();		
		resetSelectPanelDataByTouchFocus(panelID);
	}	
	//FOCUS	ALL
	public void resetSelectPanelDataByClickFocusAll(int panelID)
	{
		panel[panelID].resetMiningByClickFocus();
		resetSelectPanelDataByClickFocus(panelID);
	}
	//FOCUS	ALL
	public void resetSelectPanelDataByTimingFocusAll(int panelID)
	{
		panel[panelID].resetMiningByTimingFocus();
		resetSelectPanelDataByTimingFocus(panelID);
	}	
	*/
	
	public void resetFontSize()
	{
		for(int i=0;i<panelNumber;i++)
			panel[i].reset_font_size();
	}
	
	
	//FOR MODULE EXECUTION
	public int findModule(int moduleID, boolean flags[])
	{
		for(int i=0;i<panelNumber;i++)
		{
//			System.out.println(i+":"+moduleID+"ID:panelmoduleID "+panel[i].miningIDs[panel[i].selected_module]);
			
			if(panel[i].miningIDs[panel[i].selected_module] == moduleID && flags[i] == false)
				return i;
			
		}
		
		return -1;
	}
	
    //getModuleName
	public String getModuleName(int miningModuleID)
	{
        return moduleData.getModuleName(miningModuleID);
	}
    
	public String getVisualizationModuleName(int visualizationModuleID)
	{
        return moduleData.getVisualizationModuleName(visualizationModuleID);
	}	
	
	public int findVisualizationModule(int visuModuleID, boolean flags[])
	{
		for(int i=0;i<panelNumber;i++)
		{
//			System.out.println(i+":"+visuModuleID+"ID:panelmoduleID "+panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]]);
			
			if(panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]] == visuModuleID && flags[i] == false)
				return i;
		}
		
		return -1;
	}	
	
	
	//Mainly For Character Assist
	//get assigned module information
	
	public boolean isSetMiningModule(int miningModuleID)
	{
		for(int i=0;i<panelNumber;i++)
			if(panel[i].miningIDs[panel[i].selected_module] == miningModuleID)
				return true;
		return false;
	}
	
	public boolean isSetVisualizationModule(int visualizationModuleID)
	{
		for(int i=0;i<panelNumber;i++)
			if(panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]] == visualizationModuleID)
				return true;
		return false;
	}
	
	public boolean isSetModule(int miningModuleID, int visualizationModuleID)
	{
		for(int i=0;i<panelNumber;i++)
        {
            if(panel[i] == null)
                break;
            
			if(panel[i].miningIDs[panel[i].selected_module] == miningModuleID && panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]] == visualizationModuleID)
				return true;
        }
		return false;
	}	
	
    //NAVIGATION
    public void firstActivationConfirmation()
    {
        int option;
        if(sp1.inJapanese)
            option = JOptionPane.showConfirmDialog(this, buttonNamesInJapanese[62],  buttonNamesInJapanese[63], JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        else
            option = JOptionPane.showConfirmDialog(this, "Do you utilize voice navigation?", "YES", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        
        if(option == JOptionPane.YES_OPTION)
        {
            sp1.navigation = true;
            
            if(sp1.firstTime == true)
            {
                sp1.firstTime = false;
                navigationControl.setSoundNumber(100);
            }
            else
                navigationControl.setSoundNumber(101);
        }
        else
        {
            sp1.navigation = false;
            if(sp1.inJapanese)
                JOptionPane.showMessageDialog(this, buttonNamesInJapanese[64]);
            else
                JOptionPane.showMessageDialog(this, "You can use voice navigation by selecting [Use Navigation] from the [Mode] button in the menu window.");
        }
    }
    
	
	//INTERPRETATION
	
    public void addInterpretation(String sourceFilename, String result, String meaning, int importance, int miningIDs[], int visualizationIDs[], int textIDs[], int sizeX[], int noticedPanelID)
    {
        boolean noticedPanelNumber[] = new boolean[panelNumber];
        for(int i=0;i<panelNumber;i++)
            if(i == noticedPanelID)
                noticedPanelNumber[i] = true;
            else
                noticedPanelNumber[i] = false;
        
        addInterpretation(sourceFilename, result, meaning, importance, miningIDs, visualizationIDs, textIDs, sizeX, noticedPanelNumber);
    }
    
	public void addInterpretation(String sourceFilename, String result, String meaning, int importance, int miningIDs[], int visualizationIDs[], int textIDs[], int sizeX[], boolean noticedPanelNumber[])
	{		
		interpretation[interpretationNumber] = new Interpretation(interpretationNumber, sourceFilename, result, meaning, importance, miningIDs, visualizationIDs, textIDs, sizeX, noticedPanelNumber);
		interpretationNumber++;
//		bt77.setEnabled(true);
		bt78.setEnabled(true);
	}	
	
    public void deleteInterpretationFile()
    {
        String interpretationFilename = absolutePath+"interpretation"+File.separator+"INTERPRETATION";
        
        try
        {
            BufferedWriter bw1;
            bw1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(interpretationFilename, false), "Shift_JIS"));
            bw1.close();
        }
        catch(Exception e){
            System.out.println("File Writing ERROR INTERPRETATION in Control-0");
        }
        
    }
    
    public void writeInterpretation(int interpretationN)
    {
        String interpretationFilename = absolutePath+"interpretation"+File.separator+"INTERPRETATION";
		
		if(interpretationN == 0)
			return;
		
        try
        {
			BufferedWriter bw1;
			
			if(interpretationN == 1)
				bw1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(interpretationFilename, false), "Shift_JIS"));			
			else			
				bw1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(interpretationFilename, true), "Shift_JIS"));
			
			
			int number = interpretationN-1;
//            int noticed = interpretation[number].noticedPanelNumber;
            
	//		String miningName = moduleData.module_names[moduleData.findModule(interpretation[number].allMiningIDs[noticed])];
		//	String visualizationName = moduleData.visu_module_names[moduleData.findVisualizationModule(interpretation[number].allVisualizationIDs[noticed])];
			
			bw1.write("INTERPRETATION "+(number+1));
			bw1.newLine();
			bw1.write(interpretation[number].result);
			bw1.newLine();
			bw1.write(interpretation[number].meaning);
			bw1.newLine();
            bw1.write("importance="+interpretation[number].importance);
			bw1.newLine();			
            bw1.write("source text="+interpretation[number].sourceFilename);
			bw1.newLine();
		//	bw1.write("mining="+interpretation[number].allMiningIDs[noticed]+" "+miningName);
			//bw1.newLine();
//			bw1.write("visualization="+interpretation[number].allVisualizationIDs[noticed]+" "+visualizationName);
	//		bw1.newLine();
		//	bw1.write("noticedPanelNumber="+noticed);
			//bw1.newLine();

            
            bw1.write("panelNumber="+interpretation[number].allPanelNumber);
            bw1.newLine();
            
            for(int i=0;i<interpretation[number].allPanelNumber;i++)
            {
                bw1.write(interpretation[number].allMiningIDs[i]+" "+interpretation[number].allVisualizationIDs[i]+" "+interpretation[number].allTextIDs[i]+
                          " "+moduleData.module_names[moduleData.findModule(interpretation[number].allMiningIDs[i])]+
                          " "+moduleData.visu_module_names[moduleData.findVisualizationModule(interpretation[number].allVisualizationIDs[i])]+
                          " "+interpretation[number].noticedPanelNumber[i]);
                
                bw1.newLine();
            }
            
            bw1.write("#Panel Balance");
            bw1.newLine();
            for(int i=0;i<interpretation[number].allPanelNumber;i++)
                bw1.write(interpretation[number].allSizeX[i]+" ");
            bw1.newLine();
            
            
            bw1.close();
        }
        catch(Exception e){
            System.out.println("File Writing ERROR INTERPRETATION in Control-1");
        }		
    }
    
	public void readInterpretation()
	{
        String interpretationFilename = absolutePath+"interpretation"+File.separator+"INTERPRETATION";
		String interpretationText = FILEIO.TextFileAllReadCode(new File(interpretationFilename));
		
		interpretationNumber = 0;
		String ss;
		
		try
		{
			BufferedReader br1 = new BufferedReader(new StringReader(interpretationText));
			
			while((ss = br1.readLine()) != null)
			{
				interpretationNumber++;
				
                for(int i=0;i<5;i++)
                    ss = br1.readLine();    //interpretation
                
				String lineData[] = ss.split("=");
				for(int i=0;i<Integer.parseInt(lineData[1]);i++)
					ss = br1.readLine();
				
				ss = br1.readLine();//Comment
				ss = br1.readLine();//Balance
			}
		}
		catch(Exception e){
			System.out.println("Text Reading ERROR INTERPRETATION");
		}
        
        if(interpretationNumber > maxInterpretationNumber)
            interpretationNumber = maxInterpretationNumber;
        

        for(int i=0;i<interpretationNumber;i++)
            interpretation[i] = new Interpretation();

        if(interpretationNumber > 0)
		{
//			bt77.setEnabled(true);
			bt78.setEnabled(true);				
		}
        else
            bt78.setEnabled(false);
		
		//manually saved data
		try
		{
			BufferedReader br1 = new BufferedReader(new StringReader(interpretationText));
			
			for(int i=0;i<interpretationNumber;i++)
			{
                ss = br1.readLine();// INTERPRETATION NUMBER
                
                interpretation[i].result = br1.readLine();
                interpretation[i].meaning = br1.readLine();
				
                ss = br1.readLine();
				String lineData[] = ss.split("=");
                interpretation[i].importance = Integer.parseInt(lineData[1]);				
                
                ss = br1.readLine();
                lineData = ss.split("=");
                interpretation[i].sourceFilename = lineData[1];
/*
                
                ss = br1.readLine(); //noticedPanelNumber
				lineData = ss.split("=");
                interpretation[i].noticedPanelNumber = Integer.parseInt(lineData[1]);
                */
                
                //panelNumber
				ss = br1.readLine();
				lineData = ss.split("=");
				interpretation[i].allPanelNumber = Integer.parseInt(lineData[1]);
				
				interpretation[i].allMiningIDs = new int[interpretation[i].allPanelNumber];
				interpretation[i].allVisualizationIDs = new int[interpretation[i].allPanelNumber];
				interpretation[i].allTextIDs = new int[interpretation[i].allPanelNumber];
				interpretation[i].allSizeX = new int[interpretation[i].allPanelNumber];
                interpretation[i].noticedPanelNumber = new boolean[interpretation[i].allPanelNumber];
				
				for(int j=0;j<interpretation[i].allPanelNumber;j++)
				{
					ss = br1.readLine();
					lineData = ss.split(" ");
					interpretation[i].allMiningIDs[j] = Integer.parseInt(lineData[0]);
					interpretation[i].allVisualizationIDs[j] = Integer.parseInt(lineData[1]);
					interpretation[i].allTextIDs[j] = Integer.parseInt(lineData[2]);
                    interpretation[i].noticedPanelNumber[j] = Boolean.parseBoolean(lineData[5]);
				}
				
				ss = br1.readLine(); // comment
				
				ss = br1.readLine();
				lineData = ss.split(" ");
				for(int j=0;j<interpretation[i].allPanelNumber;j++)
					interpretation[i].allSizeX[j] = Integer.parseInt(lineData[j]);
				
				interpretation[i].icon = new ImageIcon(absolutePath+"interpretation"+File.separator+"situation"+(i+1)+".png");
				interpretation[i].smallImg = interpretation[i].icon.getImage().getScaledInstance(160, 200, Image.SCALE_SMOOTH);
				interpretation[i].smallIcon = new ImageIcon(interpretation[i].smallImg);				
			}
		}
		catch(Exception e){
			System.out.println("Text Reading ERROR INTERPRETATION-2");
		}
		
		
	}
	
	public boolean deleteInterpretation(int deleteNumber)
	{
		File deleteFile = new File(absolutePath + "interpretation" + File.separator + "situation"+(deleteNumber+1)+".png");
		deleteFile.delete();
		System.out.println("delete situation"+(deleteNumber+1)+".png");
		
		for(int i=deleteNumber+1;i<interpretationNumber;i++)
		{
			File renameFile = new File(absolutePath + "interpretation" + File.separator + "situation"+(i+1)+".png");
			File newFile = new File(absolutePath + "interpretation" + File.separator + "situation"+i+".png");
			renameFile.renameTo(newFile);
			System.out.println("rename situation"+(i+1)+".png to situation"+i+".png");
		}
		
		if(deleteNumber < 0 || deleteNumber >= interpretationNumber)
			return false;
		
		for(int i=deleteNumber;i<interpretationNumber-1;i++)
			interpretation[i] = interpretation[i+1];
		
		interpretationNumber--;
		
		if(interpretationNumber == 0)
		{
//			bt77.setEnabled(false);
			bt78.setEnabled(false);			
		}
        bt79.setEnabled(true);
        
        if(interpretationNumber == 0)
            deleteInterpretationFile();
        else
            for(int i=0;i<interpretationNumber;i++)
                writeInterpretation(i+1);
		
		return true;
	}
	


	// PANEL SIZE LOG DATA
    public void writePanelSizeLog()
    {
        String logData = "SYSTEM*PC*PANELSIZE*";
        
        for(int i=0;i<panelNumber-1;i++)
            logData += balancedPanelSizeX[i]+",";
        logData += balancedPanelSizeX[panelNumber-1];
        
        ACTIONLOG.writeActionLog(logData);
    }	

    // TOOL SET LOG DATA
    public void writeSetModules(String windowName)
    {
        ACTIONLOG.checkLogFile();//delete log if the log was too short

        closePopForInterpretation();
        autoSet = true;
        bt79.setSelected(false);
        autoSet = false;
        
        ACTIONLOG.setLogStartTime();
        ACTIONLOG.createLogDirectory();
        
        String moduleNames = windowName+"*TOOL*SET*";
        
        for(int i=0;i<panelNumber;i++)
            if(panel[i] != null)
                moduleNames += ("("+panel[i].miningIDs[panel[i].selected_module]+","+panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]]+")");
        
        ACTIONLOG.writeActionLog(moduleNames);
    }
	
    
    
	public boolean fileChoose()
	{
		JFileChooser fc = new JFileChooser(absolutePath+File.separator+"text");
		FileFilter filter1;
		FileFilter filter2;
        FileFilter filter3;
		
		
		if(sp1.inJapanese)
		{
			filter1 = new FileNameExtensionFilter(buttonNamesInJapanese[13], "txt");
			filter2 = new FileNameExtensionFilter(buttonNamesInJapanese[14], "txt");
            filter3 = new FileNameExtensionFilter(buttonNamesInJapanese[61], "txt");
		}
		else 
		{
			filter1 = new FileNameExtensionFilter("Text in Japanese", "txt");
			filter2 = new FileNameExtensionFilter("Text in English", "txt");
            filter3 = new FileNameExtensionFilter("UTF-8 Text in Japanese", "txt");
		}

		fc.addChoosableFileFilter(filter2);
		fc.addChoosableFileFilter(filter1);
        fc.addChoosableFileFilter(filter3);
		
		int selected = fc.showOpenDialog(this);
		
		if (selected != JFileChooser.APPROVE_OPTION)
			return false;

		File inputFile = fc.getSelectedFile();
		original_file = inputFile.getAbsolutePath();
			
		if(fc.getFileFilter() == filter2)
			sp1.isEnglish = true;
		else
			sp1.isEnglish = false;
		
		System.out.println("English = "+sp1.isEnglish);
        
        utf8code = false;
        if(fc.getFileFilter() == filter3)
            utf8code = true;
        
        StoryControl.TextSelectCheck(inputFile.getName());        

		return true;
	}
	
	public boolean fileChooseFromDirectory()
	{
		JFileChooser fc = new JFileChooser(absolutePath);
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        
        FileFilter filter1;
        FileFilter filter3;
        
        if(sp1.inJapanese)
        {
            filter1 = new FileNameExtensionFilter(buttonNamesInJapanese[13], "txt");
            filter3 = new FileNameExtensionFilter(buttonNamesInJapanese[61], "txt");
        }
        else
        {
            filter1 = new FileNameExtensionFilter("Text in Japanese", "txt");
            filter3 = new FileNameExtensionFilter("UTF-8 Text in Japanese", "txt");
        }
        
        fc.addChoosableFileFilter(filter1);
        fc.addChoosableFileFilter(filter3);
		
		int selected = fc.showOpenDialog(this);
		
		if (selected != JFileChooser.APPROVE_OPTION)
			return false;
		
		File inputFile = fc.getSelectedFile();
        
        utf8code = false;
        if(fc.getFileFilter() == filter3)
            utf8code = true;
        
        original_file = FILEIO.makeOne(inputFile,absolutePath,"SJIS",sp1.segment_tag, utf8code);  //WRITE CODE
        utf8code = false;
        
        StoryControl.TextSelectCheck(inputFile.getName());
		
		return true;
	}	

	public void panelSetFromModule(int panelID, int moduleIDs[], int displayIDs[])
	{		
		int tIDs[];		
		
        closePanelWindow();
		createProcessingPop();
		initializePanelSizeX();		
		
		tIDs = new int[moduleIDs.length];
		for(int i=0;i<moduleIDs.length;i++)
			tIDs[i] = panel[panelID].mining[panel[panelID].selected_module].text.textID;
		
        System.out.println("A:PANEL ID = "+panelID+" TEXTID = "+panel[panelID].mining[panel[panelID].selected_module].text.textID);
        
		panelSet(moduleIDs,displayIDs,tIDs,balancedPanelSizeX);
	}	
	
	public void panelSetFromModule(int panelID, int moduleIDs[], int displayIDs[], int sizeX[])
	{
		int tIDs[];		
		
        closePanelWindow();
		createProcessingPop();
		
		tIDs = new int[moduleIDs.length];
		for(int i=0;i<moduleIDs.length;i++)
			tIDs[i] = panel[panelID].mining[panel[panelID].selected_module].text.textID;
		
        System.out.println("B:PANEL ID = "+panelID+" TEXTID = "+panel[panelID].mining[panel[panelID].selected_module].text.textID);
		
		panelSet(moduleIDs,displayIDs,tIDs,sizeX);
	}	
	
	public void panelSetWithKeep(int panelID, int moduleIDs[], int displayIDs[], int textIDs[], int sizeX[])
	{
        closePanelWindow();
        
		int mIDs[];
		int dIDs[];
		int tIDs[];
		boolean keepList[] = new boolean[panelNumber];
		int count=0;
		
		createProcessingPop();
		
//		initializePanelSizeX();
		
		for(int i=0;i<panelNumber;i++)
			if(panel[i].mining[panel[i].selected_module].keep)
			{
				keepList[i] = true;
				count++;
			}
			else
				keepList[i] = false;
		
		if(count == 0)
		{
			initializePanelSizeX();
			panelSet(moduleIDs,displayIDs,textIDs,sizeX);
			return;
		}
		
		//WITH KEEP
		
		sp1.createBackupID();		//BACK UP
		
		initializePanelSizeX();		
		
		mIDs = new int[moduleIDs.length+count];
		dIDs = new int[moduleIDs.length+count];
		tIDs = new int[moduleIDs.length+count];
		
		count=0;
		for(int i=0;i<panelID;i++)
			if(keepList[i])
			{
				mIDs[count] = panel[i].miningIDs[panel[i].selected_module];
				dIDs[count] = panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]];
				tIDs[count] = panel[i].mining[panel[i].selected_module].text.textID;
				count++;
			}
		
		for(int i=0;i<moduleIDs.length;i++)
		{
			mIDs[count+i] = moduleIDs[i];
			dIDs[count+i] = displayIDs[i];
			tIDs[count+i] = textIDs[i];
		}		
		
		for(int i=panelID;i<panelNumber;i++)
		{
			if(keepList[i])
			{
				mIDs[moduleIDs.length + count] = panel[i].miningIDs[panel[i].selected_module];
				dIDs[moduleIDs.length + count] = panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]];
				tIDs[moduleIDs.length + count] = panel[i].mining[panel[i].selected_module].text.textID;
				count++;
			}
		}
		
		panelNumber = moduleIDs.length + count;
		

		
		setModulesToPanels(mIDs,dIDs);
		panelsReConstruction(tIDs);
        
	}	
	
	public void setModulesToPanels(int minID[], int visID[])
	{

        
		sp1.panels = minID.length;
		for(int i=0;i<sp1.panels;i++)
		{
			for(int j=0;j<moduleData.module_names.length;j++)
				if(moduleData.moduleIDs[j] == minID[i])
				{
					sp1.miningID[i] = minID[i];
					moduleData.miningModuleSelection[j] = true;
				}
			
			for(int j=0;j<moduleData.visu_module_names.length;j++)
				if(moduleData.visuModuleIDs[j] == visID[i])
				{
					sp1.visualizationID[i] = visID[i];
					moduleData.visualizationModuleSelection[j] = true;
					
					
				}
		}
		moduleData.initializeModuleSubset();
        
            //StoryControl.PanelSelectCheck();
            //StoryControl.PanelSelectCheck();
        
        

	}	
	
	public void panelSet(int moduleIDs[], int displayIDs[], int textIDs[], int sizeX[])
	{
        getBalancedPanelSize(panelNumber);
        
		sp1.createBackupID();	//BACKUP		
		
        closePanelWindow();
        
		createProcessingPop();
		
		panelNumber = moduleIDs.length;
		
		for(int i=0;i<panelNumber;i++)
			balancedPanelSizeX[i] = sizeX[i];
        
		setModulesToPanels(moduleIDs,displayIDs);
		panelsReConstruction(textIDs);
        
        if(characterTutorial == 0)// after setting module
            setCharacterTutorialButton();
        
            StoryControl.PanelSelectCheck();
            StoryControl.PanelSelectCheck();
        
        if(characterTutorial > 0)
            setCharacterTutorialButton();
	}
	
	// HISTORY REPLAY
	public void panelSetForHistoryReplay(int moduleIDs[], int displayIDs[])
	{
		int textIDs[] = new int[moduleIDs.length];
		int sizeX[] = new int[moduleIDs.length];
		
		for(int i=0;i<moduleIDs.length;i++)
		{
			textIDs[i] = 0;
			sizeX[i] = 1;
		}
		
		panelSet(moduleIDs, displayIDs, textIDs, sizeX);
		
		setWindowLocation(50,250,1000,400,pop);		//MENU WINDOW
		setWindowLocation(50,50,1000,400,popUpForSelectionAssist);	//COMBINATION SELECTION
		setWindowLocation(50,10,1000,1000,mainf);	//COMBINATION SELECTION
		
	}
	// HISTORY REPLAY	
	public void setWindowLocation(int x, int y, int width, int height, JFrame window)
	{
		if(window == null)
			return;
		
		window.setBounds(x,y,width,height);
	}
	
	
	public void panelSet()
	{
        closePanelWindow();
        
		createProcessingPop();
		
		panelNumber = miningIDs.length;
			
		calculateBalancedPanelSizeInitial(panelNumber);
		
		setModulesToPanels(miningIDs,visualizationIDs);
		panelsReConstruction(0);
        
        
        StoryControl.PanelSelectCheck();
        StoryControl.PanelSelectCheck();
	}
	
	
	public void panelSetByMiningModule(int moduleID)
	{
		int rID = moduleData.findModule(moduleID);
		
		panelSet(moduleData.miningPanelSet[rID].MiningIDs, moduleData.miningPanelSet[rID].VisualizationIDs, moduleData.miningPanelSet[rID].TextIDs, moduleData.miningPanelSet[rID].sizeX);
	}	

	public void backPanelSetByMiningModule(int moduleID)
	{
		int rID = moduleData.findModule(moduleID);
		
        //resetPartial();
        
		panelSet(moduleData.miningPanelSet[rID].backMiningIDs, moduleData.miningPanelSet[rID].backVisualizationIDs, moduleData.miningPanelSet[rID].backTextIDs, moduleData.miningPanelSet[rID].backSizeX);
	}
	
	
	public static BufferedImage rescale(BufferedImage srcImage, int nw) {
		BufferedImage dstImage = null;
		
		double sx = (double) nw / srcImage.getWidth();
		double sy = sx;
		int nh = (int)(sy * srcImage.getHeight());
		
		if( srcImage.getColorModel() instanceof IndexColorModel ) {
			dstImage = new BufferedImage(nw, nh, srcImage.getType(), (IndexColorModel)srcImage.getColorModel());
		} else {
			if( srcImage.getType() == 0 ) {
				dstImage = new BufferedImage(nw, nh, BufferedImage.TYPE_4BYTE_ABGR_PRE);
			} else {
				dstImage = new BufferedImage(nw, nh, srcImage.getType());
			}
		}
		

		AffineTransform trans = AffineTransform.getScaleInstance(sx, sy);
		
		if( dstImage.getColorModel().hasAlpha() && dstImage.getColorModel() instanceof IndexColorModel) {
			int transparentPixel = ((IndexColorModel) dstImage.getColorModel()).getTransparentPixel();
			for(int i=0;i<dstImage.getWidth();++i) {
				for(int j=0;j<dstImage.getHeight();++j) {
					dstImage.setRGB(i, j, transparentPixel);
				}
			}
		}
		
		Graphics2D g2 = (Graphics2D)dstImage.createGraphics();
		g2.drawImage(srcImage, trans, null);
		g2.dispose();
		
		return dstImage;
	}	
	
	
	//Image Capture // same as in Visualization.java
	public void imageCapture()
	{
		JFileChooser chooser = new JFileChooser(text.absolutePath);		
		BufferedImage image = null;
		
		try{
            mainf.toFront();
            
			Robot robo = new Robot();
			image = robo.createScreenCapture(new Rectangle(getLocationOnScreen(),getSize()));
		} 
		catch(Exception e){}
		
		int result = chooser.showSaveDialog(this);
		File selectedFile = chooser.getSelectedFile();
		
		if(result == JFileChooser.APPROVE_OPTION)
			try{
				String filename = selectedFile.getName();
				if(filename.endsWith(".png") == false)
					filename += ".png";
				
				ImageIO.write(image,"png", new File(selectedFile.getParent(), filename));
			} 
		catch(Exception e){}	
	}
    
    public void imageCaptureFromInterpretation(String filename)
    {
        BufferedImage image = null;
        
        try{
            mainf.toFront();
            
            Robot robo = new Robot();
            image = robo.createScreenCapture(new Rectangle(getLocationOnScreen(),getSize()));
        }
        catch(Exception e){}

        try{
                ImageIO.write(image,"png", new File(filename));
        }
        catch(Exception e){}
    }
	
	//AUTO CAPTURE
//	int captureNumber = 0;
	public void imageCapture(String filename)
	{
		BufferedImage image = null, smallImage = null;
		
		try{
            mainf.toFront();
            
			Robot robo = new Robot();
			image = robo.createScreenCapture(new Rectangle(getLocationOnScreen(),getSize()));
			smallImage = rescale(image, 600);	 //WIDTH=600
		} 
		catch(Exception e){}
		
		try{
			ImageIO.write(smallImage,"png", new File(text.absolutePath+"capture"+File.separator, filename+selectionAssistData.selectionNumber+".png"));
//			captureNumber++;
		} 
		catch(Exception e){}	
	}
	
	//MAN CAPTURE
	public void manImageCapture(String filename)
	{
		BufferedImage image = null, smallImage = null;
		
		try{
            mainf.toFront();
            
			Robot robo = new Robot();
			image = robo.createScreenCapture(new Rectangle(getLocationOnScreen(),getSize()));
			smallImage = rescale(image, 600);	 //WIDTH=600
		} 
		catch(Exception e){}
		
		try{
			ImageIO.write(smallImage,"png", new File(text.absolutePath+"capture"+File.separator, filename+selectionAssistData.manSelectionNumber+".png"));
		} 
		catch(Exception e){}	
	}	
	
	
	public String createPanelInformation()
	{
		String saveSettingTexts = "";
		
		try
		{
			StringWriter sw1 = new StringWriter();
			BufferedWriter bw1 = new BufferedWriter(sw1);
			
			bw1.write("panelNumber="+panelNumber);
			bw1.newLine();
			
			getPanelInformation();
			for(int i=0;i<panelNumber;i++)
			{
				bw1.write(miningIDs[i]+" "+visualizationIDs[i]+" "+textIDs[i]);
				bw1.newLine();
			}
			
			getBalancedPanelSize(panelNumber);
			bw1.write("#Panel Balance");
			bw1.newLine();			
			for(int i=0;i<panelNumber;i++)
				bw1.write(balancedPanelSizeX[i]+" ");
			bw1.newLine();
			
			bw1.flush();
			sw1.flush();
			saveSettingTexts = sw1.toString();
			bw1.close();
			sw1.close();
		}
		catch(Exception e){
			System.out.println("Text Writing ERROR in createPanelInformation");
		}
		
		return saveSettingTexts;		
	}
	

	//auto saved
	public void savePanelInformation()
	{
		String saveSettingTexts = createPanelInformation();

		if(selectionAssistData.selectionNumber == 10) //MAX NUMBER 
		{
			selectionAssistData.dataDelete(0);	//ROTATION
		}
		
		if(selectionAssistData.selectionNumber == 0)
			FILEIO.TextFileWriteCode(new File(text.absolutePath+"capture"+File.separator+"panelInformation"), saveSettingTexts, "SJIS");	// NEW FILE		
		else
			FILEIO.TextFileWriteCode2(new File(text.absolutePath+"capture"+File.separator+"panelInformation"), saveSettingTexts, "SJIS");	// ADD MODE

		
		imageCapture("Capture");
		
		selectionAssistData.selectionNumber++;
		selectionAssistData.countNumber();
		selectionAssistData.dataRead();		
		selectionAssistData.readIcon();
		
		if(popUpForSelectionAssist != null)
			popUpForSelectionAssist.reConstruction();						
	}
	
//	int manSaveCount = 0;
	//manually saved
	public void manSavePanelInformation()
	{
		String saveSettingTexts = createPanelInformation();
		
		FILEIO.TextFileWriteCode2(new File(text.absolutePath+"capture"+File.separator+"manPanelInformation"), saveSettingTexts, "SJIS");	// ADD MODE
		
		manImageCapture("manCapture");
		
		selectionAssistData.manSelectionNumber++;
		selectionAssistData.countNumber();
		selectionAssistData.manDataRead();
		selectionAssistData.readManIcon();
		
		if(popUpForSelectionAssist != null)
			popUpForSelectionAssist.reConstruction();			
	}		
	
	
	
	PopUpForSetting popForSetting;
	PopUpForModeSetting popForModeSetting;
	PopUpForSetModule popForSetModule;
	PopUpForSetModule popForSetModuleImage;
    
    PopUpForNavigation popUpForNavigation;
    
    PopUpForWordToolSelect popUpForWordToolSelect;
	
    public void resetPartial()
    {
        resetSelectpanelData(text);
        
        for(int i=0;i<panelNumber;i++)
        {
            panel[i].mining[panel[i].selected_module].partialDocumentA = -1;
            panel[i].mining[panel[i].selected_module].partialDocumentB = -1;
        }
    }
	
	PopUpForKnowledgeCreation popForKnowledgeCreation;
	PopUpForInterpretationList popForInterpretationList;
    
	//FOR MISSION
    
	public void interpretationMission()	// called from PopUpForInterpretation
	{
		if(popForSupport == null)
			return;
		
		//USE interpretation[interpretationNumber-1] as newly created interpretation
		
        popForSupport.support.checkAnswer(interpretation[interpretationNumber-1].result, interpretation[interpretationNumber-1].meaning,interpretation[interpretationNumber-1].importance);
        
        /*
		popForSupport.support.checkAnswer(interpretation[interpretationNumber-1].sourceFilename,
			moduleData.module_names[moduleData.findModule(interpretation[interpretationNumber-1].allMiningIDs[interpretation[interpretationNumber-1].noticedPanelNumber])],
			moduleData.visu_module_names[moduleData.findVisualizationModule(interpretation[interpretationNumber-1].allVisualizationIDs[interpretation[interpretationNumber-1].noticedPanelNumber])],
			interpretation[interpretationNumber-1].result, interpretation[interpretationNumber-1].meaning, 
			interpretation[interpretationNumber-1].importance);
         */
	}
	
	
	public void openCombinationWindow()
	{
		String windowTitle = "Application Selection";
		if(sp1.inJapanese)
			windowTitle = windowNameInJapanese[6];		
		
		popUpForSelectionAssist = new PopUpForSelectionAssist(sp1.windowSizeX, sp1.windowSizeY, this, windowTitle);

		popUpForSelectionAssist.panelCreated = true;
	}
	
	public void closeCombinationWindow()
	{
        if(popUpForSelectionAssist != null)
        {
			popUpForSelectionAssist.autoSet = true;
            popUpForSelectionAssist.dispose();
            popUpForSelectionAssist = null;

        }
	}
    
    public void closePopForSetModule()
    {
        if(popForSetModule != null)
        {
            popForSetModule.closeInformationWindow();
            
            popForSetModule.dispose();
            popForSetModule = null;

        }
    }
    
    public void closePopForSetModuleImage()
    {
        if(popForSetModuleImage != null)
        {
            popForSetModuleImage.dispose();
            popForSetModuleImage = null;

        }
    }
    
    public void closePopForSupport()
    {
        if(popForSupport != null)
        {
            popForSupport.closeAllWindows();
            
            popForSupport.dispose();
            popForSupport.support.data.sendtimeData(popForSupport.support.classstage_num," Window close");
            popForSupport = null;

        }
    }

    public void closePopForSupportDeveloper()
    {
        if(popForSupportDeveloper != null)
        {
            popForSupportDeveloper.closeAllWindows();
            
            popForSupportDeveloper.dispose();
            popForSupportDeveloper.support.data.sendtimeData(popForSupportDeveloper.support.classstage_num," Window close");			
            popForSupportDeveloper = null;

        }
    }
    
    public void closePopForInterpretationList()
    {
        if(popForInterpretationList != null)
        {
            popForInterpretationList.dispose();
            popForInterpretationList = null;
        }
    }

    public void closePopForKnowledgeCreation()
    {
        if(popForKnowledgeCreation != null)
        {
            popForKnowledgeCreation.dispose();
            popForKnowledgeCreation = null;
        }
    }
    
    public void closePopForSetting()
    {
        if(popForSetting != null)
        {
            popForSetting.dispose();
            popForSetting = null;
        }
    }
    
    public void closePopForModeSetting()
    {
        if(popForModeSetting != null)
        {
            popForModeSetting.dispose();
            popForModeSetting = null;
        }
    }
    
    public void closePopForNavigation()
    {
        if(popUpForNavigation != null)
        {
            popUpForNavigation.dispose();
            popUpForNavigation = null;
        }
    }
    
    public void closePopForWordToolSelect()
    {
        if(popUpForWordToolSelect != null)
        {
            popUpForWordToolSelect.dispose();
            popUpForWordToolSelect = null;
        }
    }

    public void openPopForStory()
    {
        popForStory = new PopUpForStory(200, 100, 400, 400, this, 1);
    }
    
    public void closePopForStory()
    {
        StoryControl.CloseAllWindows();
        
        if(popForStory != null)
        {
            popForStory.dispose();
            popForStory = null;
            
            autoSet = true;
            btTutorial.setSelected(false);
            autoSet = false;
        }
    }
    
    public void closePopForInterpretation()
    {
        if(popForInterpretation != null)
        {
            popForInterpretation.subWindowClose();  //DELETE STARS
            popForInterpretation.dispose();
            popForInterpretation = null;
        }
    }
    
	
	///////////////// EXP ///////////////
	public void buttonExp(ActionEvent e)
	{
		int number = -1;
		
		if(e.getSource() == bt55)
			number = 0;
		if(e.getSource() == bt52)
			number = 1;
		if(e.getSource() == bt10)
			number = 2;
		if(e.getSource() == bt40)
			number = 3;
		if(e.getSource() == bt50)
			number = 4;
		if(e.getSource() == bt71)
			number = 5;
		if(e.getSource() == bt90)
			number = 6;
		if(e.getSource() == btx)
			number = 7;
		if(e.getSource() == btxImage)
			number = 8;
		if(e.getSource() == bt72)
			number = 9;
		if(e.getSource() == bt70)
			number = 10;
		if(e.getSource() == bt20)
			number = 11;
		if(e.getSource() == bt30)
			number = 12;
		if(e.getSource() == btxx)
			number = 13;
		if(e.getSource() == btxxx)
			number = 14;
		if(e.getSource() == bt77)
			number = 15;
		if(e.getSource() == bt78)
			number = 16;
		if(e.getSource() == bt0)
			number = 17;
		if(e.getSource() == bt00)
			number = 18;
		if(e.getSource() == bt99)
			number = 19;
		if(e.getSource() == bt60)
			number = 20;
		if(e.getSource() == btTutorial)
			number = 21;
        if(e.getSource() == bt79)
            number = 22;
        if(e.getSource() == bt81)
            number = 23;
        if(e.getSource() == btd1)
            number = 24;
        if(e.getSource() == btd2)
            number = 25;
        if(e.getSource() == btd3)
            number = 26;
        if(e.getSource() == btxTree) //NEW
            number = 27;
				
		if(number >= 0)
			addExpByControlButton(number);			
		
	}
		
	public void addExpByControlButton(int number)
	{
		ex1.addExpByControlButton(number);
		if(expPanel != null)
			expPanel.repaint();		
	}
	
	public String getButtonName(ActionEvent e)
	{
		String log = e.getSource().toString();
		
		if(log.equals(""))
			return "NONAME";
		
		//            String regex = "text=(.*),";
		String regex = "text=(.*)]";
		Pattern p = Pattern.compile(regex);
		
		Matcher m = p.matcher(log);
		
		if(m.find())
		{
			return m.group(1).replaceAll(",defaultCapable=true","");
		}
		else
			return log;
	}
	
    //Mainly for Character Assist
	//inputText file must be given with absolutePath
	//absolutePath+File.separator+"text"+File.separator+"urashima.txt"
	public void autoTextLoading(String inputText)
	{
		original_file = inputText;	
		
		createProcessingPop();
		
		textDataLoading(original_file);
		resetSelectpanelData(text);		
	}
	
    TextData getSetText()
    {
        int usePanel=0;
        for(int i=0;i<panelNumber;i++)
        {
            if(panel[i] == null)
                return text;
            
            if(panel[i].mining[panel[i].selected_module].cancelPartialDocument == false)
            {
                usePanel = i;
                break;
            }
        }
        
        if(panelNumber == 0)
            return text;
        else
            return panel[usePanel].mining[panel[usePanel].selected_module].text;
    }
    
    
    
	//Action listener
	public void actionPerformed(ActionEvent e)
	{
        
//        System.out.println("--------");
        
		if(autoSet == true)
			return;
		
		
	///////////////// EXP ///////////////
		buttonExp(e);

		String buttonName = getButtonName(e);
        
//        System.out.println(buttonName);
		
//		writeActionLog(buttonName);
//		writeActionLog("MENU-WINDOW", buttonName);
		ACTIONLOG.writeButtonLog("MENU", buttonName, (Component)e.getSource());
		/*
		Point S = ((Component)e.getSource()).getLocationOnScreen();
		System.out.println("Location = "+S.x+","+S.y);
		
		Dimension QD = ((Component)e.getSource()).getSize();
		System.out.println("Size = "+QD.width+","+QD.height);		
		
		
		 
		 Point S = panel[0].interpretation.getLocationOnScreen();
		 System.out.println("Location = "+S.x+","+S.y);
		 
		 Dimension QD = panel[0].interpretation.getSize();
		 System.out.println("Size = "+QD.width+","+QD.height);		 
		 
		 
        String log = e.getSource().toString();
//        String regex = "text=(.*),";
        String regex = "text=(.*)]";
        Pattern p = Pattern.compile(regex);
        
        Matcher m = p.matcher(log);
        
        if(m.find())
		{
            writeActionLog(m.group(1));
			writeActionLog("CONTROL", m.group(1));
		}
        else
		{
            writeActionLog(log);
			writeActionLog("CONTROL", log);			
		}
        */
		
		if(e.getSource() == bt55)//Load A File
		{
//			autoTextLoading(absolutePath+File.separator+"text"+File.separator+"sanshodayu.txt");
			
			if(!fileChoose())
				return;
			

            
            btd2.doClick();
            
			createProcessingPop();

			textDataLoading(original_file);
			resetSelectpanelData(text);
            



            
            StoryControl.nextSerif(1001);
		}		
		
		if(e.getSource() == bt52)//Load Folder
		{
			if(!fileChooseFromDirectory())
				return;
            
            btd2.doClick();
			
			createProcessingPop();
			
			textDataLoading(original_file);
			resetSelectpanelData(text);
            
            StoryControl.nextSerif(1002);
		}
		

		if(e.getSource() == bt10)//Reload and ReExecute
		{
			createProcessingPop();
			
			textDataLoadingAgain();/////
			resetSelectpanelData(text);
            
            StoryControl.nextSerif(1003);
		}
		
		if(e.getSource() == bt40)//Add Panel
		{		
			addNewPanel(text);
            
            StoryControl.nextSerif(1004);
		}		
		
		if(e.getSource() == bt50)//Delete Panel
		{
			delete(panelNumber-1);
            
            StoryControl.nextSerif(1005);
		}
		
		if(e.getSource() == bt71)// Set balanced Panel Size
		{
			if(panelNumber == 1)
				balancedPanelSizeX[0] = getWidth();
			else
				for(int i=0;i<panelNumber;i++)
					balancedPanelSizeX[i] = (getWidth() - (11*(panelNumber-1)))/panelNumber;
			
			for(int i=0;i<panelNumber-1;i++)
				setBalancedSplitDivider(i);
            
            StoryControl.nextSerif(1006);
			
			if(popForSupport != null)
                popForSupport.support.setAnsweredFlagTrue(1,2);//1.0
		}
		
		if(e.getSource() == bt90)// Image Capture
        {
			imageCapture();
            StoryControl.nextSerif(1007);
        }
				
		if(e.getSource() == btx)//SetModulePanel
		{
            if(btx.isSelected())
			{
                closePopForSetModuleImage();//
                closePopForWordToolSelect();///////
                btxImage.setSelected(false);
                btxTree.setSelected(false);
                
			    int x,y,width;
			    x = width = getWidth();
			    y = getHeight();
			    if(x > 950)
                    x = 950;
			    if(y > 900)
                    y = 900;
				
				String windowTitle = "Tool Selection by Name";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[7];					
				
				Point position = getLocationOnScreen();
				getPanelInformation(); //Update miningIDs, visualizationIDs 
				popForSetModule = new PopUpForSetModule(sp1, (int)((width-x)/2), (int)position.getY()-20, x, y, this,0, windowTitle);

                
                StoryControl.nextSerif(1008);
			}
			else
			{
                closePopForSetModule();
			}
		}
		
        if(e.getSource() == btxTree)//SetModulePanelToolTree
        {
            if(btxTree.isSelected())
            {
                closePopForSetModule();
                btx.setSelected(false);
                
                int x,y,width;
                x = width = getWidth();
                y = getHeight();
                if(x > 950)
                    x = 950;
                if(y > 900)
                    y = 900;
                
                Point position = getLocationOnScreen();
                setWordToolSelectWindow(true, (int)((width-x)/2), (int)position.getY()-20);
                
                StoryControl.nextSerif(1028);
            }
            else
            {
                closePopForWordToolSelect();
            }
        }
        
        /*
        if(e.getSource() == bt20)//SetModulePanelToolTree forTEST
        {
                int x,y,width;
                x = width = getWidth();
                y = getHeight();
                if(x > 950)
                    x = 950;
                if(y > 900)
                    y = 900;
                
                Point position = getLocationOnScreen();
                setWordToolSelectWindow(true, (int)((width-x)/2), (int)position.getY()-20);
        }*/
        
		if(e.getSource() == btxImage)//SetModulePanelImage
		{
            if(btxImage.isSelected())
			{
                closePopForSetModule();
                btx.setSelected(false);
                
			    int x,y,width;
			    x = width = getWidth();
			    y = getHeight();
			    if(x > 950)
                    x = 950;
			    if(y > 900)
                    y = 900;
				
				String windowTitle = "Tool Selection by Image";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[8];	
				
				Point position = getLocationOnScreen();
				getPanelInformation(); //Update miningIDs, visualizationIDs 
				popForSetModuleImage = new PopUpForSetModule(sp1, (int)((width-x)/2), (int)position.getY()-20, x, y, this,1, windowTitle);

                
                StoryControl.nextSerif(1009);
			}
			else
			{
                closePopForSetModuleImage();

			}
            
		}		
		
		if(e.getSource() == bt72)//combination Panel
		{
			if(popUpForSelectionAssist == null)
			{
				openCombinationWindow();
				autoSet = true;
				bt72.setSelected(true);
				autoSet = false;
				
				if(mainf.logStart == true && popUpForSelectionAssist.logStart == false)
					popUpForSelectionAssist.logStart = true;
                
                StoryControl.nextSerif(1010);
			}
			else
			{
				closeCombinationWindow();
				autoSet = true;
				bt72.setSelected(false);
				autoSet = false;				
			}
		}		
		
		
		if(e.getSource() == bt70)// Save Combination
		{
			int option;
			if(sp1.inJapanese)
				option = JOptionPane.showConfirmDialog(this, buttonNamesInJapanese[47],  buttonNamesInJapanese[48], JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
			else
				option = JOptionPane.showConfirmDialog(this, "SAVE MODE and CURRENT PANELS OK?", "OK", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
			
			if(option != JOptionPane.YES_OPTION)
				return;
			
			manSavePanelInformation();
			
			sp1.saveActivationFile();
			
			/*
			int miningIndex=0;
			
			getBalancedPanelSize(panelNumber);
			
			sp1.panels = panelNumber;
			for(int i=0;i<panelNumber;i++)
			{
				sp1.miningID[i] = moduleData.msub.selectedMiningIDs[panel[i].selected_module];
				for(int j=0;j<moduleData.moduleIDs.length;j++)
					if(moduleData.moduleIDs[j] == sp1.miningID[i])
					{
						moduleData.miningModuleSelection[j] = true;
						miningIndex = j;
					}
				sp1.visualizationID[i] = moduleData.msub.selectedVisualizationIDs[panel[i].pair_visu[panel[i].selected_module]];
				for(int j=0;j<moduleData.visuModuleIDs.length;j++)
					if(moduleData.visuModuleIDs[j] == sp1.visualizationID[i])				
						moduleData.visualizationModuleSelection[j] = true;
				
				sp1.modifyModuleSettings(miningIndex, sp1.visualizationID[i]);
				
				//				System.out.println(moduleData.msub.selectedMiningIDs[panel[i].selected_module] +":"
				//								   +moduleData.msub.selectedVisualizationIDs[panel[i].pair_visu[panel[i].selected_module]]);			
			}
			sp1.saveSettingFile();
			 */
			
            StoryControl.nextSerif(1011);
            
			if(popForSupport != null)
                popForSupport.support.setAnsweredFlagTrue(0,10);			
		}
		

		
		if(e.getSource() == bt20)//Font-
		{
			if(sp1.toolFontSize > 1)
				sp1.toolFontSize--;
			resetFontSize();
            
            StoryControl.nextSerif(1012);
            
            /*********
            if(th != null)
                th.stopThread();
            
            th = new XYThread();
            th.start();
             *********/


		}
		
		if(e.getSource() == bt30)//Font+
		{
			if(sp1.toolFontSize < 100)
				sp1.toolFontSize++;
			resetFontSize();
            
            StoryControl.nextSerif(1013);
            
            /////////          th.stopThread();/////////
		}	
		
		if(e.getSource() == btTutorial)//Character Assist
		{
            if(btTutorial.isSelected())
            {
                popForStory = new PopUpForStory(200, 100, 400, 400, this, 1);
                StoryControl.nextSerif(1014);
                
                btd2.doClick();
                if(text.control.btd3.isSelected() == true)
                    text.control.btd3.doClick();
                
                characterTutorial = 1;
                setCharacterTutorialButton();
            }
            else
            {
                closePopForStory();
                characterTutorial = 0;
                setCharacterTutorialButton();
            }
		}
        
        if(e.getSource() == bt81)//GameMode
        {
            if(bt81.isSelected())
            {
                setGameMode(true);
                StoryControl.nextSerif(1023);
            }
            else
                setGameMode(false);
            
            if(shrinkInformationWindow != null)
            {
                if(bt81.isSelected())
                    shrinkInformationWindow.moveY(sp1.popSizeY);
                else
                    shrinkInformationWindow.moveY(-sp1.popSizeY);
            }
        }

		if(e.getSource() == btxx)//SUPPORT
		{
			if(btxx.isSelected())
			{
				int x,y,width;
				x = width = getWidth();
				y = getHeight();
				if(x > 950)
					x = 950;
		    	if(y > 900)
					y = 900;
				
				String windowTitle = "Tutorials For User";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[4];				
				
				Point position = getLocationOnScreen();
				getPanelInformation(); //Update miningIDs, visualizationIDs 			
				//				popForSupport = new PopUpForSupport((int)((width-x)/2), (int)position.getY()-20, x, y, this,flagbox);
				popForSupport = new PopUpForSupport((int)(2*width/3), (int)position.getY()-20, x, y, this, "ForUser", "operate", windowTitle);
				//			writeActionLog("OPEN-MODULE-SUPPORT-WINDOW");
                
                StoryControl.nextSerif(1015);
			}
			else
			{
                closePopForSupport();
			}
		}
        
		if(e.getSource() == btxxx)//SUPPORT
		{
			if(btxxx.isSelected())
			{
				int x,y,width;
				x = width = getWidth();
				y = getHeight();
				if(x > 950)
					x = 950;
		    	if(y > 900)
					y = 900;
				
				String windowTitle = "Tutorials For Developer";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[5];				
				
				Point position = getLocationOnScreen();
				getPanelInformation(); //Update miningIDs, visualizationIDs
				//				popForSupport = new PopUpForSupport((int)((width-x)/2), (int)position.getY()-20, x, y, this,flagbox);
				popForSupportDeveloper = new PopUpForSupport((int)(2*width/3), (int)position.getY()-20, x, y, this, "ForDeveloper", "developer", windowTitle);
				//			writeActionLog("OPEN-MODULE-SUPPORT-WINDOW");
                
                StoryControl.nextSerif(1016);
			}
			else
			{
                closePopForSupportDeveloper();
			}
		}
        
        
        if(e.getSource() == btd1)   //shrink
        {
//            System.out.println("ID="+panel[0].text.textID);
            
            TextData setText = getSetText();
            
            System.out.println("Shrink base textID= "+setText.textID);
            
            if(setText.textID == 0)
            {
//                panel[i].mining[panel[i].selected_module]

                setPartialDocument(2, true);
            }
            else
            {
                boolean focusSegments[] = new boolean[text.segmentNumber]; //ALL
                boolean partialFocusSegments[] = setText.focus.getFocusSegments();  //PARTIAL
                for(int i=0;i<text.segmentNumber;i++) //ALL
                    focusSegments[i] = false; //ALL
                
                for(int i=0;i<setText.segmentNumber;i++) //PARTIAL
                    focusSegments[setText.originalSegmentNumbers[i]] = partialFocusSegments[i]; //PARTIAL -> ALL
                
                text.focus.setFocusSegments(0,0,focusSegments,"","",false); //ALL  ////
            }
            
            focus.addCondition();       ////


            
            resetBySegmentPartialData(0);

            
            
            btd1.setEnabled(false);
            if(shrinkInformationWindow != null)
                shrinkInformationWindow.invertion.setEnabled(false);
            btd2.setEnabled(true);
            
            for(int i=0;i<panelNumber;i++)
                sp1.textID[i] = panel[i].text.textID;
            sp1.createBackupTextID(1); //BACKUP for TEXTID ONLY
            
            StoryControl.nextSerif(1025);
            
            /*
            for(int i=0;i<text.sentenceNumber;i++)
            {
                System.out.println("sentenceID = "+text.sentence[i].sentenceID);
                System.out.println("segmentID = "+text.sentence[i].segmentID);
                System.out.println("positionOfSegment = "+text.sentence[i].positionOfSegment);
                System.out.println("positionOfSentenceInSegment = "+text.sentence[i].positionOfSentenceInSegment);
                System.out.println("positionOfSentenceInText = "+text.sentence[i].positionOfSentenceInText);
                System.out.println("--------------------");
            }
            
            setText = panel[0].mining[panel[0].selected_module].text;
            for(int i=0;i<setText.sentenceNumber;i++)
            {
                System.out.println("sentenceID = "+setText.sentence[i].sentenceID);
                System.out.println("segmentID = "+setText.sentence[i].segmentID);
                System.out.println("positionOfSegment = "+setText.sentence[i].positionOfSegment);
                System.out.println("positionOfSentenceInSegment = "+setText.sentence[i].positionOfSentenceInSegment);
                System.out.println("positionOfSentenceInText = "+setText.sentence[i].positionOfSentenceInText);
                System.out.println("--------------------");
            }
            */
        }

        if(e.getSource() == btd2)   //shrink reset
        {
            if(focus.shrinkCount > 0)
                setPartialDocument(0, false);
            
            text.focus.clearAllFocus();
            focus.resetCondition();
            
            for(int i=0;i<panelNumber;i++)
                sp1.textID[i] = panel[i].text.textID;
            sp1.createBackupTextID(0); //BACKUP for TEXTID ONLY
            
            for(int i=0;i<panelNumber;i++)
                if(panel[i].reExecution != null)
                    panel[i].reExecution.doClick();
            
            StoryControl.nextSerif(1026);
        }
        
        if(e.getSource() == btd2x)   //shrink reset without reExecution //DUMMY BUTTON
        {
            if(focus.shrinkCount > 0)
                setPartialDocument(0, false);
            
            text.focus.clearAllFocus();
            focus.resetCondition();
            
            for(int i=0;i<panelNumber;i++)
                sp1.textID[i] = panel[i].text.textID;
            sp1.createBackupTextID(0); //BACKUP for TEXTID ONLY
        }
        
        if(e.getSource() == btd3)   //shrink information window
        {
            if(shrinkInformationWindow != null)
            {
                shrinkInformationWindow.setVisible(btd3.isSelected());
                StoryControl.nextSerif(1027);
//                System.out.println("NOT CREATED");
            }
            else
            {
                if(sp1.inJapanese)
                    shrinkInformationWindow = new PopUpForShrinkInformation(sp1.windowSizeX-800, sp1.popSizeY, 800, baseHeight, sp1.fontSize, sp1.fontName, inJapanese[15], absolutePath, this);
                else
                    shrinkInformationWindow = new PopUpForShrinkInformation(sp1.windowSizeX-800, sp1.popSizeY, 800, baseHeight, sp1.fontSize, sp1.fontName, "Data (Segment: Paragraph, Document) Shrink Condition >Hit Number", absolutePath, this);
                
//                System.out.println("NEWLY CREATED");
            }
                
        }
		
        if(e.getSource() == bt79)    //RESULT AND INTERPRETATION
        {
            if(bt79.isSelected())
            {
                closePopForInterpretationList();
                closePopForKnowledgeCreation();
                
                String windowTitle = "Result and Interpretation "+(interpretationNumber+1)+" /"+maxInterpretationNumber;
                if(sp1.inJapanese)
                    windowTitle = windowNameInJapanese[9]+" "+(interpretationNumber+1)+" /"+maxInterpretationNumber;
                
                String imagePath = absolutePath+"source"+File.separator+"image"+File.separator+"star.png";
//                popForInterpretation = new PopUpForInterpretation(imagePath, panel[0].mining[panel[0].selected_module],this,panel[0], 0, windowTitle);
                popForInterpretation = new PopUpForInterpretation(imagePath, this, windowTitle);
                
                StoryControl.nextSerif(2003);
            }
            else
            {
                closePopForInterpretation();
            }
        }
        
		if(e.getSource() == bt77)	//KNOWLEDGE CREATION LIST
		{
			if(bt77.isSelected())
			{
                closePopForInterpretation();
				closePopForKnowledgeCreation();
				
			    int x,y,width;
			    x = width = getWidth();
			    y = getHeight();
			    if(x > 950)
                    x = 950;
			    if(y > 900)
                    y = 900;
				
				String windowTitle = "Interpretation List";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[2];
				
				Point position = getLocationOnScreen();				
				popForInterpretationList = new PopUpForInterpretationList((int)((width-x)/2), (int)position.getY()-20, x, y, this, windowTitle);
                
                StoryControl.nextSerif(1017);
			}
			else
			{
                closePopForInterpretationList();
			}
		}
		
		if(e.getSource() == bt78)	//KNOWLEDGE CREATION
		{
			if(bt78.isSelected())
			{
                closePopForInterpretation();
                closePopForInterpretationList();
				
				String creationTitle;
				
				if(sp1.inJapanese)
					creationTitle = JOptionPane.showInputDialog(this, buttonNamesInJapanese[49],windowNameInJapanese[16], JOptionPane.PLAIN_MESSAGE);
				else
					creationTitle = JOptionPane.showInputDialog(this, "Please input the purpose of analysis","INPUT PURPOSE",JOptionPane.PLAIN_MESSAGE);
				
				if(creationTitle == null)
					creationTitle = "";
				
			    int x,y,width;
			    x = width = getWidth();
			    y = getHeight();
			    if(x > 950)
                    x = 950;
			    if(y > 900)
                    y = 900;
				
				String windowTitle = "Knowledge Creation";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[3];
				
				Point position = getLocationOnScreen();				
				popForKnowledgeCreation = new PopUpForKnowledgeCreation((int)((width-x)/2), (int)position.getY()-20, x, y, this, windowTitle, creationTitle);
                
                StoryControl.nextSerif(1018);
			}
			else
			{
                closePopForKnowledgeCreation();
			}
			
		}		
		
		
		if(e.getSource() == bt0)//SettingPanel
		{
			if(bt0.isSelected())
			{
                int x,y,width;
			    x = width = getWidth();
			    y = getHeight()+20;
			    if(x > 600)
                    x = 600;
			    if(y > 920)
                    y = 920;
				
				String windowTitle = "Keyword Setting";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[0];
				
				Point position = getLocationOnScreen();
				popForSetting = new PopUpForSetting(sp1, (int)((width-x)/2), (int)position.getY()-20, x, y, this, windowTitle);
                
                if(popForSupport != null)
                    popForSupport.support.setAnsweredFlagTrue(0,2);//1.0
                
                StoryControl.nextSerif(1019);
			}
			else
			{
                closePopForSetting();
			}
			
            
		}	
		
		if(e.getSource() == bt00)//SettingPanel Mode
		{
			if(bt00.isSelected())
			{
				/*
				int mining[]={1,1,1};
				int visual[]={1,1,1};
				int text[]={0,0,0};
				int size[]={1,1,1};
				
				panelSet(mining,visual,text,size);
				*/
			    int x,y,width;
			    x = width = getWidth();
			    y = getHeight()+20;
			    if(x > 600)
                    x = 600;
			    if(y > 400)
                    y = 400;
				
				String windowTitle = "Mode Setting";
				if(sp1.inJapanese)
					windowTitle = windowNameInJapanese[1];				
				
				Point position = getLocationOnScreen();
				popForModeSetting = new PopUpForModeSetting(sp1, (int)((width-x)/2), (int)position.getY()-20, x, y, this, windowTitle);
                

                
                StoryControl.nextSerif(1020);
			}
			else
			{
                closePopForModeSetting();
			}
			
            
		}		
		

		if(e.getSource() == bt99)//Quit application
		{		
			savePanelInformation();
			

/*			
			Point T = bt99.getLocationOnScreen();
			System.out.println("Location = "+T.x+","+T.y);
			
			Dimension TD = bt99.getSize();
			System.out.println("Size = "+TD.width+","+TD.height);			
			

			Point S = panel[0].interpretation.getLocationOnScreen();
			System.out.println("Location = "+S.x+","+S.y);
			
			Dimension QD = panel[0].interpretation.getSize();
			System.out.println("Size = "+QD.width+","+QD.height);
		
			
			System.out.println("set 40,3 = "+isSetModule(40,3));
			System.out.println("set 1,1 = "+isSetModule(1,1));
			System.out.println("set 5,5 = "+isSetModule(5,5));	
			System.out.println("set 0 = "+isSetMiningModule(0));			
			System.out.println("set 1 = "+isSetMiningModule(1));	
			System.out.println("set 0 = "+isSetVisualizationModule(0));			
			System.out.println("set 1 = "+isSetVisualizationModule(1));			
				*/
			
            StoryControl.nextSerif(1021);
            
            ACTIONLOG.checkLogFile();
            
			mainf.dispose(); //destroy frame
			System.exit(0);
			 			
		}		

        
        if(e.getSource() == bt60)//back
        {
            panelSet(sp1.lastMiningID, sp1.lastVisualizationID, sp1.lastTextID, sp1.lastBalancedPanelSizeX);

            StoryControl.nextSerif(1022);
        }

	}
	
	//ComponentListener
	public void componentHidden(ComponentEvent e){}
	public void componentMoved(ComponentEvent e){}
	public void componentShown(ComponentEvent e){}
	public void componentResized(ComponentEvent e)
	{		
		calculateBalancedPanelSize(panelNumber);
		for(int i=0;i<panelNumber-1;i++)
			setBalancedSplitDivider(i);
	}	
	
	void panelsReConstruction(int option) //0:normal, 1:mode changed
	{
		for(int i=0;i<panelNumber;i++)
			if(panel[i] != null)
			{
				panel[i].closeAllWindows();
				
				if(panel[i].popModuleSelect != null)
					panel[i].popModuleSelect.setMenu();
			}
		
		upperPanel.remove(selectPanel);
		selectPanel = new JPanel(new GridLayout());
		upperPanel.add(selectPanel, "select");
		initializeSelectPanel(option);
		upperPanel.revalidate();
		
		if(btx.isSelected())
			popForSetModule.setMenu();
		if(btxImage.isSelected())
			popForSetModuleImage.setMenu(); //////////
        
        if(shrinkInformationWindow != null)
        {
            shrinkInformationWindow.dispose();
            btd3.setSelected(false);
            shrinkInformationWindow = null;
            btd2.doClick();
            btd3.doClick();
        }
	}
	
	void panelsReConstruction(int tIDs[])
	{
		for(int i=0;i<panelNumber;i++)
			if(panel[i] != null)
			{
				panel[i].closeAllWindows();
				
				if(panel[i].popModuleSelect != null)
					panel[i].popModuleSelect.setMenu();	
			}
		
		upperPanel.remove(selectPanel);
		selectPanel = new JPanel(new GridLayout());
		upperPanel.add(selectPanel, "select");	
		
        for(int i=0;i<tIDs.length;i++)
            sp1.textID[i] = tIDs[i];
        
//        initializeSelectPanel(tIDs);
        initializeSelectPanel();
		upperPanel.revalidate();
		
		if(btx.isSelected())
			popForSetModule.setMenu();
		if(btxImage.isSelected())   //////////
			popForSetModuleImage.setMenu();
	}
    
    public void panelsReConstructionfromSetSegment(int panelID, int textID)
    {
        for(int i=0;i<panelNumber;i++)
            if(i != panelID)
                if(panel[i] != null)
                {
                    panel[i].closeAllWindows();
                    
                    if(panel[i].popModuleSelect != null)
                        panel[i].popModuleSelect.setMenu();
                }
        
        upperPanel.remove(selectPanel);
        selectPanel = new JPanel(new GridLayout());
        upperPanel.add(selectPanel, "select");
        
        initializeSelectPanelwithoutSegSegment(panelID, textID);
        upperPanel.revalidate();
        
        if(btx.isSelected())
            popForSetModule.setMenu();
        if(btxImage.isSelected())   //////////
            popForSetModuleImage.setMenu();
    }
	
/*
	void panelsReConstruction(int panelID, int miningID, int visualizationID)
	{
		upperPanel.remove(selectPanel);
		selectPanel = new JPanel(new GridLayout());
		upperPanel.add(selectPanel, "select");
		initializeSelectPanel();
		upperPanel.revalidate();	
	}
*/	
	int miningIDs[];
	int visualizationIDs[];
	int textIDs[];	
    
    int lastMiningIDs[];
    int lastVisualizationIDs[];
	int lastTextIDs[];	
    
	public void getPanelInformation()
	{
		miningIDs = new int[panelNumber];
		visualizationIDs = new int[panelNumber];
		textIDs = new int[panelNumber];		
		
		for(int i=0;i<panelNumber;i++)
		{
			miningIDs[i] = panel[i].miningIDs[panel[i].selected_module];
			visualizationIDs[i] = panel[i].visualizationIDs[panel[i].pair_visu[panel[i].selected_module]];
			textIDs[i] = panel[i].text.textID;			
		}
	}
   
    public void createBackupIDs()
    {
        getPanelInformation();
        
        lastMiningIDs = new int[miningIDs.length];
        lastVisualizationIDs = new int[visualizationIDs.length];
		lastTextIDs = new int[textIDs.length];		
        
        for(int i=0;i<miningIDs.length;i++)
            lastMiningIDs[i] = miningIDs[i];
        
        for(int i=0;i<visualizationIDs.length;i++)
            lastVisualizationIDs[i] = visualizationIDs[i];
		
        for(int i=0;i<textIDs.length;i++)
            lastTextIDs[i] = textIDs[i];		
    }
    
    public void traceBackupIDs()
    {
        miningIDs = new int[lastMiningIDs.length];
        visualizationIDs = new int[lastVisualizationIDs.length];
		textIDs = new int[lastTextIDs.length];		
        
        for(int i=0;i<lastMiningIDs.length;i++)
            miningIDs[i] = lastMiningIDs[i];
        
        for(int i=0;i<lastVisualizationIDs.length;i++)
            visualizationIDs[i] = lastVisualizationIDs[i];
		
        for(int i=0;i<lastTextIDs.length;i++)
            textIDs[i] = lastTextIDs[i];		
    }

    //buttonPanel
	void initializeButtonPanel()
	{
		buttonPanel = new JPanel(new GridLayout());
		buttonPanel.setBackground(Color.YELLOW);
        
		//button initialization
		
		bt10 = new JButton();
		bt20 = new JButton();
		bt30 = new JButton();
		bt40 = new JButton();
		bt50 = new JButton();

		bt99 = new JButton();
		bt52 = new JButton();	
		bt55 = new JButton();	

		bt70 = new JButton();
		bt72 = new JToggleButton();	//combination Panel
		bt60 = new JButton(buttonNamesInJapanese[50], new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"back.png"));
		
		bt71 = new JButton();
		bt90 = new JButton();
		bt0 = new JToggleButton();
		bt00 = new JToggleButton();		
		btx = new JToggleButton();
		btxImage = new JToggleButton();
        btxTree = new JToggleButton();
		btTutorial = new JToggleButton();//SUPPORT		
		btxx = new JToggleButton();//SUPPORT
		btxxx = new JToggleButton();//SUPPORT	
		
		bt77 = new JToggleButton();	//KNOWLEDGE CREATION
		bt78 = new JToggleButton();	//KNOWLEDGE CREATION
        
        bt79 = new JToggleButton();    //RESULT AND INTERPRETATION
        bt81 = new JToggleButton();    //GAME MODE
        
        btd1 = new JButton();   //Data shrink
        btd2 = new JButton();   //Data Shrink Reset
        btd2x = new JButton();   //Data Shrink Reset
        btd3 = new JToggleButton();     //Data shrink information window
		
        //PANEL SETTINGS
        int subPanelNumber = 11;
        
        //subLabelPanel = buttonLabel + subButtonPanel
		subLabelPanel = new JPanel[subPanelNumber];
        buttonLabel = new JLabel[subPanelNumber];
		subButtonPanel = new JPanel[subPanelNumber];
        
		for(int i=0;i<subPanelNumber;i++)
		{
			subLabelPanel[i] = new JPanel(new BorderLayout());
            buttonLabel[i] = new JLabel();
            buttonLabel[i].setFont(new Font(sp1.fontName, Font.BOLD, 10));
			subButtonPanel[i] = new JPanel(new GridLayout());
            
            if(i < subPanelNumber-1)
            {
                subLabelPanel[i].add(buttonLabel[i]);
                subLabelPanel[i].add(subButtonPanel[i], BorderLayout.SOUTH);
            }
		}
        
        //sub[6],sub[8] text
		if(sp1.controlButtons[0] || sp1.controlButtons[2])
			buttonPanel.add(subLabelPanel[6]);
		if(sp1.controlButtons[1] || sp1.controlButtons[6])
			buttonPanel.add(subLabelPanel[8]);
        
        subLabelPanel[6].setBackground(Color.YELLOW);
		subButtonPanel[6].setBackground(Color.YELLOW);

        subLabelPanel[8].setBackground(Color.YELLOW);
		subButtonPanel[8].setBackground(Color.YELLOW);
        
		bt55.setBackground(Color.YELLOW);
		bt52.setBackground(Color.YELLOW);
		bt10.setBackground(Color.YELLOW);
        bt90.setBackground(Color.YELLOW);
		
		bt55.addActionListener(this);
		bt52.addActionListener(this);
		bt10.addActionListener(this);
        bt90.addActionListener(this);
		
		if(sp1.controlButtons[0])        
			subButtonPanel[6].add(bt55);
        if(sp1.controlButtons[2])
            subButtonPanel[6].add(bt10);
        
		if(sp1.controlButtons[1])		
			subButtonPanel[8].add(bt52);
        if(sp1.controlButtons[6])
            subButtonPanel[8].add(bt90);
        
        
        //sub[4] settings
        if(sp1.controlButtons[17] || sp1.controlButtons[18])
            buttonPanel.add(subLabelPanel[4]);
        
        subLabelPanel[4].setBackground(Color.CYAN);
        subButtonPanel[4].setBackground(Color.CYAN);

        bt0.setBackground(Color.CYAN);
        bt00.setBackground(Color.CYAN);
        
        bt0.addActionListener(this);
        bt00.addActionListener(this);

        if(sp1.controlButtons[17])
            subButtonPanel[4].add(bt0);
        if(sp1.controlButtons[18])
            subButtonPanel[4].add(bt00);
        
		
        //sub[5],sub[9] tool
        
        if(sp1.controlButtons[9] || sp1.controlButtons[7] )
            buttonPanel.add(subLabelPanel[5]);
        if(sp1.controlButtons[8] || sp1.controlButtons[20] || sp1.controlButtons[27])
            buttonPanel.add(subLabelPanel[9]);
        
        subLabelPanel[5].setBackground(Color.PINK);
        subButtonPanel[5].setBackground(Color.PINK);
        
        
        subLabelPanel[9].setBackground(Color.PINK);
        subButtonPanel[9].setBackground(Color.PINK);
        
        btx.setBackground(Color.PINK);
        btxImage.setBackground(Color.PINK);
        btxTree.setBackground(Color.PINK);
        
        bt72.setBackground(Color.PINK);
        bt60.setBackground(Color.PINK);       //UNDO
        
        btx.addActionListener(this);
        btxImage.addActionListener(this);
        btxTree.addActionListener(this);
        
        bt72.addActionListener(this);
        bt60.addActionListener(this);
        
        subLabelPanel[5].add(buttonLabel[5]);
        if(sp1.controlButtons[9])
            subButtonPanel[5].add(bt72);//TOOL
        if(sp1.controlButtons[7])
            subButtonPanel[5].add(btx);//TOOL
        
        if(!(sp1.controlButtons[9] || sp1.controlButtons[7]))
            subLabelPanel[9].add(buttonLabel[5]);
        
        //NORMAL MODE ONLY
        if(sp1.controlButtons[8])
            subButtonPanel[9].add(btxImage);
    
        if(sp1.controlButtons[27])
            subButtonPanel[9].add(btxTree);
        
        if(sp1.controlButtons[20])
            subButtonPanel[9].add(bt60);      //UNDO
        
        
		//sub[1] panel
		if(sp1.controlButtons[3] || sp1.controlButtons[5] || sp1.controlButtons[11] || sp1.controlButtons[12] )
			buttonPanel.add(subLabelPanel[1]);

		
   		subLabelPanel[1].setBackground(Color.CYAN);
   		subButtonPanel[1].setBackground(Color.CYAN);

		
		bt40.setBackground(Color.CYAN);
		bt71.setBackground(Color.CYAN);
		
//		bt50.setBackground(Color.PINK);

		bt20.setBackground(Color.CYAN);
		bt30.setBackground(Color.CYAN);
        
			
		bt40.addActionListener(this);
		bt71.addActionListener(this);

//		bt50.addActionListener(this);
		
		
		bt20.addActionListener(this);
		bt30.addActionListener(this);
        

		
		if(sp1.controlButtons[3])		
			subButtonPanel[1].add(bt40);
		if(sp1.controlButtons[5])		
			subButtonPanel[1].add(bt71);
        if(sp1.controlButtons[11])
            subButtonPanel[1].add(bt20);
        if(sp1.controlButtons[12])
            subButtonPanel[1].add(bt30);
        
//		if(sp1.controlButtons[4])		
//			subButtonPanel[1].add(bt50);
		

		
		/*
		//sub[0] fontSize

        
   		subLabelPanel[0].setBackground(Color.YELLOW);
        subButtonPanel[0].setBackground(Color.YELLOW);
        
		bt20.setBackground(Color.YELLOW);
		bt30.setBackground(Color.YELLOW);		
		
		bt20.addActionListener(this);
		bt30.addActionListener(this);
        
		if(sp1.controlButtons[11])		
			subButtonPanel[0].add(bt20);
		if(sp1.controlButtons[12])		
			subButtonPanel[0].add(bt30);		
		*/
		


		
        /*
		if(sp1.controlButtons[7] || sp1.controlButtons[8])
			buttonPanel.add(subLabelPanel[5]);		
		if(sp1.controlButtons[9] || sp1.controlButtons[10])		
			buttonPanel.add(subLabelPanel[9]);
        		
        subLabelPanel[5].setBackground(Color.CYAN);
		subButtonPanel[5].setBackground(Color.CYAN);		
   		subLabelPanel[9].setBackground(Color.CYAN);
   		subButtonPanel[9].setBackground(Color.CYAN);

		btx.addActionListener(this);
		btxImage.addActionListener(this);		
	
		bt70.addActionListener(this);
		bt72.addActionListener(this);		

		subLabelPanel[5].add(buttonLabel[5]);
		if(sp1.controlButtons[7])		
			subButtonPanel[5].add(btx);//TOOL
		if(sp1.controlButtons[8])		
			subButtonPanel[5].add(btxImage);//TOOL		
		
		if(sp1.controlButtons[9])
			subButtonPanel[9].add(bt72);
		if(sp1.controlButtons[10])		
			subButtonPanel[9].add(bt70);
		*/
		/*
		//sub[0] fontSize
		if(sp1.controlButtons[11] || sp1.controlButtons[12])		
			buttonPanel.add(subLabelPanel[0]);
        
   		subLabelPanel[0].setBackground(Color.YELLOW);
        subButtonPanel[0].setBackground(Color.YELLOW);
        
		bt20.setBackground(Color.YELLOW);
		bt30.setBackground(Color.YELLOW);		
		
		bt20.addActionListener(this);
		bt30.addActionListener(this);
        
		if(sp1.controlButtons[11])		
			subButtonPanel[0].add(bt20);
		if(sp1.controlButtons[12])		
			subButtonPanel[0].add(bt30);
        */
        
		//sub[3] tutorial
		if(sp1.controlButtons[21] || sp1.controlButtons[13] || sp1.controlButtons[14] || sp1.controlButtons[23])
			buttonPanel.add(subLabelPanel[3]);
        
        subLabelPanel[3].setBackground(new Color(0xad, 0xff, 0x2f));
		subButtonPanel[3].setBackground(new Color(0xad, 0xff, 0x2f));
		
		btTutorial.setBackground(new Color(0xad, 0xff, 0x2f));
		btxx.setBackground(new Color(0xad, 0xff, 0x2f));
		btxxx.setBackground(new Color(0xad, 0xff, 0x2f));
        bt81.setBackground(new Color(0xad, 0xff, 0x2f));
        
		btTutorial.addActionListener(this);//SUPPORT
		btxx.addActionListener(this);//SUPPORT
		btxxx.addActionListener(this);//SUPPORT
        bt81.addActionListener(this);//GAME MODE
		
		if(sp1.controlButtons[21])			
			subButtonPanel[3].add(btTutorial);//SUPPORT		
		if(sp1.controlButtons[13])
			subButtonPanel[3].add(btxx);//SUPPORT
		if(sp1.controlButtons[14])
			subButtonPanel[3].add(btxxx);//SUPPORT
        if(sp1.controlButtons[23])
            subButtonPanel[3].add(bt81);//GAME MODE
        
        /*
		bt1.addActionListener(this);
		bt1.setSelected(true);
		
		bt2.addActionListener(this);
		bt3.addActionListener(this);
        
		subButtonPanel[3].add(bt1);
		subButtonPanel[3].add(bt2);
		subButtonPanel[3].add(bt3);
		bg.add(bt1);
		bg.add(bt2);
		bg.add(bt3);
*/
        
        //sub[2] data shrink
        if(sp1.controlButtons[24] || sp1.controlButtons[25])
            buttonPanel.add(subLabelPanel[2]);
        
        subLabelPanel[2].setBackground(new Color(0xf4, 0xb9, 0x42));
        subButtonPanel[2].setBackground(new Color(0xf4, 0xb9, 0x42));
        
        
        btd1.setBackground(Color.CYAN);
        btd2.setBackground(Color.CYAN);
        btd3.setBackground(Color.CYAN);
        btd1.addActionListener(this);
        btd2.addActionListener(this);
        btd3.addActionListener(this);


        
        if(sp1.controlButtons[24])
            subButtonPanel[2].add(btd1);
        if(sp1.controlButtons[25])
            subButtonPanel[2].add(btd2);
        if(sp1.controlButtons[26])
            subButtonPanel[2].add(btd3);
        
        
		//sub[7] //knowledge CREATION
		if(sp1.controlButtons[15] || sp1.controlButtons[16]|| sp1.controlButtons[22])
			buttonPanel.add(subLabelPanel[7]);
		
        subLabelPanel[7].setBackground(new Color(0xff, 0x33, 0x66));
		subButtonPanel[7].setBackground(new Color(0xff, 0x33, 0x66));
		
        bt79.setBackground(new Color(0xff, 0x33, 0x66));
		bt77.setBackground(new Color(0xff, 0x33, 0x66));
		bt78.setBackground(new Color(0xff, 0x33, 0x66));	
		
        bt79.addActionListener(this);
		bt77.addActionListener(this);
		bt78.addActionListener(this);
		
        if(sp1.controlButtons[22])
            subButtonPanel[7].add(bt79);
		if(sp1.controlButtons[15])		
			subButtonPanel[7].add(bt77);
		if(sp1.controlButtons[16])		
			subButtonPanel[7].add(bt78);
		
		if(interpretationNumber == 0)
		{
//			bt77.setEnabled(false);
			bt78.setEnabled(false);			
		}
        
        if(interpretationNumber >= maxInterpretationNumber)
        {
            bt79.setEnabled(false);
        }
		
//        bt78.setEnabled(false);/////////////
		
		
        
        
        //QUIT sub[10]
		if(sp1.controlButtons[10] || sp1.controlButtons[19])
			buttonPanel.add(subLabelPanel[10]);
        
        subLabelPanel[10].add(buttonLabel[10]);
        subLabelPanel[10].add(subButtonPanel[10], BorderLayout.SOUTH);
        
        subLabelPanel[10].setBackground(Color.YELLOW);
		subButtonPanel[10].setBackground(Color.YELLOW);
        
        bt70.setBackground(Color.YELLOW);
        bt70.addActionListener(this);
        
        bt99.setBackground(Color.YELLOW);
        bt99.addActionListener(this);
        
        if(sp1.controlButtons[10])
            subButtonPanel[10].add(bt70);
		if(sp1.controlButtons[19])		
			subButtonPanel[10].add(bt99);
        
		
        
        

        
        
        
        //		add(buttonPanel, BorderLayout.NORTH);
		setButtonLabel();
	}
	
	public void readJapaneseLabels()
	{
		String filename = absolutePath+"source"+File.separator+"japaneseText"+File.separator+"controlJapanese.txt";
		File jpname = new File(filename);
		buttonNamesInJapanese = FILEIO.TextFileAllReadCodeArray(jpname);
		inJapanese[0] = buttonNamesInJapanese[11];
		inJapanese[1] = buttonNamesInJapanese[15];
		inJapanese[2] = buttonNamesInJapanese[16];
		inJapanese[3] = buttonNamesInJapanese[17];
		inJapanese[4] = buttonNamesInJapanese[30];
		inJapanese[5] = buttonNamesInJapanese[31];
		inJapanese[6] = buttonNamesInJapanese[32];
		inJapanese[7] = buttonNamesInJapanese[33];
		inJapanese[8] = buttonNamesInJapanese[34];
		inJapanese[9] = buttonNamesInJapanese[35];
        inJapanese[10] = buttonNamesInJapanese[36];
        inJapanese[11] = buttonNamesInJapanese[40];
        inJapanese[12] = buttonNamesInJapanese[43];
        inJapanese[13] = buttonNamesInJapanese[54];
        inJapanese[14] = buttonNamesInJapanese[57];
        inJapanese[15] = buttonNamesInJapanese[58];
        inJapanese[16] = buttonNamesInJapanese[59];
	}
	
	public void setButtonLabel()
	{
		if(sp1.inJapanese)
		{
            System.out.println("To Japanese");
            
            buttonLabel[6].setText(buttonNamesInJapanese[28]);
            bt55.setText(buttonNamesInJapanese[7]); //Load A File
            bt52.setText("");                       //Load Folder
			bt10.setText(buttonNamesInJapanese[0]); //Reload and ReExecute
            bt90.setText(buttonNamesInJapanese[22]);// Image Capture
            
            buttonLabel[5].setText(buttonNamesInJapanese[37]);
            bt72.setText(buttonNamesInJapanese[8]);//combination Panel
            btx.setText(buttonNamesInJapanese[41]);//23//SetModulePanel
            btxImage.setText(buttonNamesInJapanese[42]);//SetModulePanelImage
            btxTree.setText(buttonNamesInJapanese[65]);//SetModulePanelImage "MOKUTEKI"
            bt60.setText(buttonNamesInJapanese[50]);//back
            
            buttonLabel[1].setText(buttonNamesInJapanese[25]);
            bt40.setText(buttonNamesInJapanese[3]);//Add Panel
            bt71.setText(buttonNamesInJapanese[21]);// Set balanced Panel Size
            bt20.setText(buttonNamesInJapanese[1]);//Font-
            bt30.setText(buttonNamesInJapanese[2]);//Font+

            buttonLabel[3].setText(buttonNamesInJapanese[26]);
            btTutorial.setText(buttonNamesInJapanese[51]);            //SUPPORT    //Character Assist
            bt81.setText(buttonNamesInJapanese[53]);    //GAME MODE//GameMode

            buttonLabel[2].setText(buttonNamesInJapanese[54]);
            btd1.setText(buttonNamesInJapanese[55]);    //data shrink
            btd2.setText(buttonNamesInJapanese[56]);    //data shrink reset
            btd3.setText(buttonNamesInJapanese[60]);    //data shrink reset

            buttonLabel[7].setText(buttonNamesInJapanese[44]);
            bt79.setText(buttonNamesInJapanese[52]);    //RESULT AND INTEPRETATION
            bt77.setText(buttonNamesInJapanese[45]);    //KNOWLEDGE CREATION
            bt78.setText(buttonNamesInJapanese[46]);    //KNOWLEDGE CREATION
            
            buttonLabel[4].setText(buttonNamesInJapanese[27]);
            bt0.setText(buttonNamesInJapanese[10]);//SettingPanel
            bt00.setText(buttonNamesInJapanese[6]);        //SettingPanel Mode
            
            buttonLabel[10].setText(buttonNamesInJapanese[29]);
			bt70.setText(buttonNamesInJapanese[9]);// Save Combination
            bt99.setText(buttonNamesInJapanese[5]);//Quit application


            
            buttonLabel[0].setText(buttonNamesInJapanese[24]);
            //            bt1.setText(buttonNamesInJapanese[18]);
            //            bt2.setText(buttonNamesInJapanese[19]);
            //            bt3.setText(buttonNamesInJapanese[20]);
            bt50.setText(buttonNamesInJapanese[4]);//Delete Panel       ////////////////
            btxx.setText(buttonNamesInJapanese[38]);    //SUPPORT
            btxxx.setText(buttonNamesInJapanese[39]);    //SUPPORT
            
		}
		else
		{
            System.out.println("To English");
            
            buttonLabel[6].setText(buttonNamesInEnglish[21]);
            bt55.setText(buttonNamesInEnglish[7]);
            bt52.setText("");
			bt10.setText(buttonNamesInEnglish[0]);
            bt90.setText(buttonNamesInEnglish[15]);
            
            buttonLabel[5].setText(buttonNamesInEnglish[23]);
            bt72.setText(buttonNamesInEnglish[8]);
            btx.setText(buttonNamesInEnglish[26]);
            btxImage.setText(buttonNamesInEnglish[27]);
            btxTree.setText(buttonNamesInEnglish[39]);///Purpose
            bt60.setText("back");
            
            buttonLabel[1].setText(buttonNamesInEnglish[18]);
            bt40.setText(buttonNamesInEnglish[3]);
            bt71.setText(buttonNamesInEnglish[14]);
			bt20.setText(buttonNamesInEnglish[1]);
			bt30.setText(buttonNamesInEnglish[2]);
            
            buttonLabel[3].setText(buttonNamesInEnglish[19]);
            btTutorial.setText(buttonNamesInEnglish[32]);            //SUPPORT
            bt81.setText(buttonNamesInEnglish[34]);    //GAME MODE
            
            buttonLabel[2].setText(buttonNamesInEnglish[37]);
            btd1.setText(buttonNamesInEnglish[35]);    //data shrink
            btd2.setText(buttonNamesInEnglish[36]);    //data shrink reset
            btd3.setText(buttonNamesInEnglish[37]);    //data shrink reset

            buttonLabel[7].setText(buttonNamesInEnglish[28]);
            bt79.setText(buttonNamesInEnglish[33]);    //RESULT AND INTEPRETATION
            bt77.setText(buttonNamesInEnglish[29]);    //KNOWLEDGE CREATION
            bt78.setText(buttonNamesInEnglish[30]);    //KNOWLEDGE CREATION
            
            buttonLabel[4].setText(buttonNamesInEnglish[20]);
            bt0.setText(buttonNamesInEnglish[10]);
            bt00.setText(buttonNamesInEnglish[31]);
            
            buttonLabel[10].setText(buttonNamesInEnglish[22]);
            bt70.setText(buttonNamesInEnglish[9]);

			bt99.setText(buttonNamesInEnglish[5]);


            buttonLabel[0].setText(buttonNamesInEnglish[17]);
//			bt1.setText(buttonNamesInEnglish[11]);
//			bt2.setText(buttonNamesInEnglish[12]);
//			bt3.setText(buttonNamesInEnglish[13]);
            bt50.setText(buttonNamesInEnglish[4]);
			btxx.setText(buttonNamesInEnglish[24]);			//SUPPORT
			btxxx.setText(buttonNamesInEnglish[25]);			//SUPPORT

		}
        

        
		bt55.setForeground(Color.red);
		bt72.setForeground(Color.red);//COMBINATION
//		bt0.setForeground(Color.red);//keyword
		bt00.setForeground(Color.red);//mode
//		btx.setForeground(Color.red);
//		btxImage.setForeground(Color.red);
		btxx.setForeground(Color.red);//SUPPORT
//		btxxx.setForeground(Color.red);//SUPPORT
        btd1.setForeground(Color.red);//Shrink

		/*
        bt0.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"setting.jpg"));
        bt0.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
        //bt00.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"setting.jpg"));
        //bt00.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
        btx.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"tools.jpg"));
        btx.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
        btxImage.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"tools.jpg"));
        btxImage.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
		bt72.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"tools.jpg"));
		bt72.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
		
		btxx.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"tutorial.jpg"));//SUPPORT
		btxx.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));	//SUPPORT
		btxxx.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"tutorial.jpg"));//SUPPORT
		btxxx.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));	//SUPPORT
        */
         
        bt55.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"txt.png"));
        bt52.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"folder.png"));
        bt90.setIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
	}
    
    public void setCharacterTutorialButton()
    {
        System.out.println("SET CHARACTER TUTORIAL BUTTON ======================" + characterTutorial);
        
        switch(characterTutorial)
        {
            case 0:btTutorial.setEnabled(true);
                for(int i=0;i<panelNumber;i++)
                {
                    if(panel[i].mining[panel[i].selected_module].tutorialExist == true)
                        panel[i].mining[panel[i].selected_module].combinationPanel.characterTutorialButton.setEnabled(true);
                    else
                        panel[i].mining[panel[i].selected_module].combinationPanel.characterTutorialButton.setEnabled(false);
                }
                break;
            case 1: //from menu
                for(int i=0;i<panelNumber;i++)
                    panel[i].mining[panel[i].selected_module].combinationPanel.characterTutorialButton.setEnabled(false);
                break;
            case 2: //from module
                btTutorial.setEnabled(false);
                for(int i=0;i<panelNumber;i++)
                    panel[i].mining[panel[i].selected_module].combinationPanel.characterTutorialButton.setEnabled(false);
                break;
        }
    }
    
    public void setNavigation(boolean flag)
    {
        sp1.navigation = flag;
    }
    
    public void setNavigationWindow(boolean flag)
    {
        closePopForNavigation();
        
        if(flag == true)
            popUpForNavigation = new PopUpForNavigation(this, 150, 150, 500, 200, navigationControl.navigation);
    }
    
    public void setWordToolSelectWindow(boolean flag, int x, int y)
    {
        closePopForWordToolSelect();

        if(flag == true)
            popUpForWordToolSelect = new PopUpForWordToolSelect(this, x, y, 500, 800);
    }
    
    
	public void setGameMode(boolean flag)
	{
		if(flag == true)
		{
			if(sp1.gameMode == false) // OFF -> ON
			{
				pop.dispose();
				pop = null;
				sp1.gameMode = true;
                
				reSizeWindow();
                reSizeFont();
			}
		}
		else
		{
			if(sp1.gameMode == true) // ON -> OFF
			{
				pop.dispose();
				pop = null;				
				sp1.gameMode = false;
                
                expPanel.closeAllPanel();
                
				reSizeWindow();
			}
		}
	}
	
	int menuMargin = 25;
	//MENU WINDOW
    public class PopUpWindow extends JFrame
    {
        Container pane = getContentPane();
        public JPanel popPanel;
		
//		MainFrame myFrame;
		String windowName = "MENU";		
		
		//GAMEMODE OFF		
        public PopUpWindow(int X, int Y, int width, int height)
        {
			popPanel = new JPanel(new BorderLayout());
			
//            System.out.println("X,Y,width,height="+X+","+Y+","+width+","+height);
            
            
			if(sp1.isWindows == true)
				setBounds(X, Y, width, height-menuMargin);
			else
				setBounds(X, Y+menuMargin, width, height-menuMargin);

			//            setAlwaysOnTop(true);
            pane.setBackground(Color.white);
            setUndecorated(true);
            
            pane.add(popPanel);
		//	if(sp1.isWindows == true)
				popPanel.add(buttonPanel);			
		//	else
			//	popPanel.add(buttonPanel,BorderLayout.SOUTH);
            
            setVisible(true);
            
            WINDOWACTIONLOG windowActionLog = new WINDOWACTIONLOG(this, windowName);
            this.addComponentListener(windowActionLog.componentListener);                    //FOR LOG
            this.addWindowListener(windowActionLog.windowListener);
        }		
		
		//GAMEMODE ON
        public PopUpWindow(int X, int Y, int width, int height, Control control)
        {
			popPanel = new JPanel(new BorderLayout());
            
//            System.out.println("X,Y,width,height="+X+","+Y+","+width+","+height);
			
			if(sp1.isWindows == true)
				setBounds(X, Y, width, height-menuMargin);
			else
				setBounds(X, Y+menuMargin, width, height-menuMargin);
            
//            setAlwaysOnTop(true);
            pane.setBackground(Color.white);
            setUndecorated(true);
            
            pane.add(popPanel);
			expPanel = new ExpPanel(control);
            popPanel.add(expPanel);			
			popPanel.add(buttonPanel,BorderLayout.SOUTH);
            
            setVisible(true);
            
            WINDOWACTIONLOG windowActionLog = new WINDOWACTIONLOG(this, windowName);
            this.addComponentListener(windowActionLog.componentListener);                    //FOR LOG
            this.addWindowListener(windowActionLog.windowListener);
        }
		
		//NO MOVE AND RESIZE
    }
}

