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


package source;

import source.TextData.*;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import java.util.regex.*;


public abstract class MiningModule extends JPanel
{
	private int moduleID = -1;
	private int categoryID = -1;
	private int useMode = 3;
	private int panelID = -1;
	
	private int toolType = 4;//1:simple 2:primitive 3:semi-primitive 4:special
	
	public TextData text;
	String absolutePath;
    
    public boolean tutorialExist = false;// TUTORIAL FILE CHECK
	
    SetData setData = new SetData();
	
	public String myModulePath;
	public String myModuleName;
	public String visuModulePath;
	public String visuModuleName;
	
	boolean firstTime = true;
	boolean keep = false;
	
    public boolean focusExecute = false;
//	public boolean focusTouchExecute = false;
	//public boolean focusClickExecute = false;
//	public boolean focusTimingExecute = false;
	
	CardLayout layout;
	JPanel visualPanel = new JPanel(layout = new CardLayout());
	public JPanel operationPanel = new JPanel(new GridLayout());
	CombinationPanel combinationPanel;
	
//	public boolean panelSet = false;
	boolean panelSet = true;

	private int setPanelModuleID[];
	private int setPanelVisualizationID[];
	private int setPanelTextID[];	
	private int setBalancedPanelSizeX[];	
	private int lastSetPanelModuleID[];
	private int lastSetPanelVisualizationID[];
	private int lastSetPanelTextID[];	
	private int lastBalancedPanelSizeX[];
	public int defaultSetPanelModuleID[];
	public int defaultSetPanelVisualizationID[];
	public int defaultSetPanelTextID[];
    public int defaultBalancedPanelSizeX[];


	Class<?> visuModule[];
    	public VisualizationModule visualization;	
//	private VisualizationModule visualization;
	VisualizationModule visual[];
	int visuModuleNumber;
	
	public int pairingVisualizationID[];
	 int pairingVisualizationIndex[];
	public int pairingVisuID[];		//For SettingPanel
    
    public boolean displayOperationPanel[];     // for each visualization tool, true: display operationPanel, false: not display operationPanel
    public JButton button[];
    public JToggleButton toggleButton[];
    
    //Display operation panel forcibly, and overcome cancelOperationPanel
    public boolean forcedDisplayOperationPanel = false;
	
//  FOR FOCUS
    public boolean focusSegments[];
    public boolean focusSentences[];
    public boolean focusKeywords[];
    
//  FOR ATTENTION
    public boolean attentionSegments[];
    public boolean attentionSentences[];
    public boolean attentionKeywords[];
    
//	FOR PROCESSING
	
	PopUpForProcessing processingPanel;

//  FOR JAPANESE
    
    public String inJapanese[];
    String buttonNamesInJapanese[];

// FOR PARTAIL
    
    public boolean cancelPartialDocument = false;   //2017.7.28
    
    public int partialDocumentA = -1; //-1:---,0:---,1:ALL,2:SEG1,3:SEG2,4:SEN1,5:SEN2
    public int partialDocumentB = -1;
	
    PopUpForDiff popForDiff;
	int diffPatterns[][];
	int textID1, textID2;
	
  
    
	public MiningModule(){}
	
	public final void setModuleID(int moduleID)
	{
		this.moduleID = moduleID;
	}	
	public final int getModuleID()
	{
		return moduleID;
	}
	public final void setCategoryID(int categoryID)
	{
		this.categoryID = categoryID;
	}	
	public final int getCategoryID()
	{
		return categoryID;
	}
	public final void setUseMode(int useMode)
	{
		this.useMode = useMode;
	}	
	public final int getUseMode()
	{
		return useMode;
	}	
	public final void setPanelID(int panelID)
	{
		this.panelID = panelID;
	}	
	public final int getPanelID()
	{
		return panelID;
	}
	public final void setToolType(int type)
	{
		this.toolType = type;
	}
	public final int getToolType()
	{
		return toolType;
	}	
	
	public final void setVisualizationPanelID()
	{
		if(visual != null)
		for(int i=0;i<visual.length;i++)
//			if(visual[i] != null)
				visual[i].setPanelID(panelID);		
	}
    
    public final void setInJapanese()
    {
        inJapanese = fileReadArray();
    }
    


	public final void init_panel(TextData tex, Class<?> vis[], int selectedVisu, String absolute, int defaultPanelSizeX, int defaultPanelSizeY)
	{
		text = tex; // this is only used for calling text.settingData.inJapanese;
		
		setLayout(new BorderLayout());
		setBackground(Color.white);
        
		this.visuModule = vis;
		visuModuleNumber = visuModule.length;		
		
		initializeVisuModules();
		add(visualPanel);
		
		setVisualizationPanelID();
		
		for(int i=0;i<visuModuleNumber;i++)
		{
			visual[i].sizeX = defaultPanelSizeX;
			visual[i].sizeY = defaultPanelSizeY;			
		}
			
		absolutePath = absolute;		
		myModulePath = absolutePath + this.getClass().getPackage().getName().replaceAll("\\.","/") + File.separator;
		myModuleName = this.getClass().getPackage().getName().replaceAll("module\\.MiningModules\\.","");

        setInJapanese();        // JAPANESE
        
        
//		System.out.println("myModuleName= "+myModuleName);

		if(panelSet)	// SET PANEL COMBINATION
		{
			createCombinationPanel();
		}
		
		operationPanel.setBackground(Color.RED);		
		initializePanel();					// Step.1
        
        
        if(displayOperationPanel == null)// <- initialize displayOperationpanel
        {
            displayOperationPanel = new boolean[pairingVisualizationID.length];
            for(int i=0;i<pairingVisualizationID.length;i++)
                displayOperationPanel[i] = true;
        }
        
        // forcedDisplayOperationPanel > cancelOperationPanel
        if(visual[selectedVisu].cancelOperationPanel == false || forcedDisplayOperationPanel == true)  //NEW 2017.4.20, 2017.7.25, 7.29, 12.5
        {
            int k;
            for(k=0;k<displayOperationPanel.length;k++)
                if(visual[selectedVisu].getModuleID() == pairingVisualizationID[k])
                    if(displayOperationPanel[k] == false)
                        break;

            if(k == displayOperationPanel.length)
                add(operationPanel, BorderLayout.SOUTH);
//                add(operationPanel);
        }
		
		setVisu(selectedVisu);
		
		System.out.println("Mining: "+this.getClass().getName());
	}
	
	public void createCombinationPanel()
	{
		combinationPanel = new CombinationPanel(this);  // calling text.settingData.inJapanese;
		add(combinationPanel, BorderLayout.NORTH);		
	}

	public final void reExecute()
	{
		resetFirstTime();
		selected(text); 		
	}
	
	public final void reLoad()
	{
		resetFirstTime();
		text = text.control.text;
		selected(text); 		
	}
	
	//get setting information
	public final String getSegmentTag()
	{
		return text.control.sp1.segment_tag;
	}
	
	public final String getSentenceTag()
	{
		return text.control.sp1.kind_touns[0];
	}	
	
	public final void initializeVisuModules()
	{
		visual = new VisualizationModule[visuModuleNumber];
		try {
			for(int i=0;i<visuModuleNumber;i++)
				visual[i] = (VisualizationModule)visuModule[i].newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
		
		for(int i=0;i<visuModuleNumber;i++)
			visualPanel.add(visual[i],"VISUAL"+i);	
	}
	
	public final void setPartialDocument()
	{
        if(cancelPartialDocument == true)
        {
            System.out.println("Canceled selected partial document because of the module setting.");
            return;
        }
        
        if(partialDocumentB == -1)//NOT SELECTED
            switch(partialDocumentA)//-1:---,0:---,1:ALL,2:SEG1,3:SEG2,4:SEN1,5:SEN2
        {
            case -1:
            case 0:
            case 1:text = text.control.text;
                break;

            case 2:text = text.control.text.segmentPartialTextData[0];
                break;
                
            case 3:text = text.control.text.segmentPartialTextData[1];
                break;
                
            case 4:text = text.control.text.sentencePartialTextData[0];
                break;
                
            case 5:text = text.control.text.sentencePartialTextData[1];
                break;
        }
        
        if(panelID != -1 && panelID != 10000)
            text.control.panel[panelID].text = text;
	}

	public final void selected(TextData tex)
	{
		text = tex;
        
        System.out.println("MINING: panelID="+panelID+" moduleID="+moduleID+" : <<textID="+text.textID+">>");

		setPartialDocument();
		
		
		if(firstTime)
		{
			initializeData();				// Step.2	Set moduleID
			firstTime = false;
		}
								
		if(visualization.firstTime)
		{
//			visualization.setPanelID(panelID);////
			visualization.selected(text);		// (to Step.3,4)
			
			miningOperations(0);	// Step.5
			setFont();							// (to Step.6,7)

		}
        
        if(visualization.toolType == 2)
            combinationPanel.displayDiffButton.setEnabled(true);
        else
            combinationPanel.displayDiffButton.setEnabled(false);
	}

	//FOCUS   Because this method is callled from this class only, TextData tex may be NO need. 
	public final void focusSelected(TextData tex)
	{
		text = tex;
		initializeData();				// Step.2	Set moduleID
		visualization.focusSelected(text);		// (to Step.4)
		miningOperations(4500);	// Step.5 case 4500
        
        setFont();              // (to Step.6,7)
        
	}	
	
	public final void createInitialData(){}// for check only 
	public final void setInitialData(){}// for check only

	public final void initDiffPatterns()
	{		
		diffPatterns = new int[11][];
		for(int i=0;i<11;i++)
			if(visualization.dataNumbers[i] > 0)
			{
				diffPatterns[i] = new int[visualization.dataNumbers[i] + 1];
				for(int j=0;j<visualization.dataNumbers[i] + 1;j++)
					diffPatterns[i][j] = 0;
			}		
	}	
	
	public final void setVisu(int selectedVisu)
	{
		visualization = visual[selectedVisu];
		layout.show(visualPanel, "VISUAL"+selectedVisu);
		
		visuModulePath = absolutePath + visualization.getClass().getPackage().getName().replaceAll("\\.","/") + File.separator;		
		visuModuleName = visualization.getClass().getPackage().getName().replaceAll("module\\.VisualizationModules\\.","");
		
		initDiffPatterns();			
	}
	
	public void initializePanel(){};		// #Step.1
	public void initializeData(){};				// #Step.2

	public abstract void miningOperations(int n);			// #Step.5

	//display for visualization
	public final void setFont()
	{
		visualization.setFont();
		displayOperations(0);				// Step.6
        visualization.firstTime = false;
        miningOperations(-1);               // Step.7
	}
	
	public final void displayOperations(int optionNumber)
	{
		visualization.displayOperations(optionNumber);
	}	
	
	public final void resetFirstTime()
	{
			firstTime = true;
			visualization.firstTime = true;
	}
	
	public final void panelReset()
	{
//		combinationPanel.panelReset();  // reset partial text buttons
		resetFirstTime();
//		selected(text.control.panel[panelID].text);		
	}

	public String fileRead()
	{	
		return FILEIO.TextFileAllReadCode(new File(myModulePath+"Japanese.txt"));
	}	
	
	public String fileRead(String filename)
	{	
		return FILEIO.TextFileAllReadCode(new File(filename));
	}
	
	public String[] fileReadArray()
	{
        System.out.println("-------"+myModulePath+"-----");
        
		return FILEIO.TextFileAllReadCodeArray(new File(myModulePath+"Japanese.txt"));
	}
	
	public String[] fileReadArray(String filename)
	{	
		return FILEIO.TextFileAllReadCodeArray(new File(filename));
	}
    
    public String[] fileReadArray(String filename, String code)
    {
        return FILEIO.TextFileAllReadCodeArray(new File(filename), code);
    }
	
	public void fileWrite(String filename, String writeText)
	{	
		FILEIO.TextFileWrite2(new File(filename), writeText);
	}
	
	public void fileWriteArray(String filename, String writeText[], int lineNumber)
	{	
		FILEIO.TextFileWrite(new File(filename), writeText, lineNumber);
	}
    
    public void fileWriteArrayCode(String filename, String writeText[], int lineNumber, String code)
    {
        FILEIO.TextFileWriteCode3(new File(filename), writeText, lineNumber, code);
    }

    //COMPONET POSITION
    public void getComponentPosition(Component component)
    {
        Point position = component.getLocation();
        
        int FunnelX = (int)component.getX();
        int FunnelY = (int)component.getY();
        
        int sizeX = component.getWidth();
        int sizeY = component.getHeight();
        
        FunnelX =sizeX/2+FunnelX;
    }
    
	//CREATE DICTIONARY
	public void createDictionary()// windows,  commandPath, dictionaryPath
	{
		EXECUTE.createDictionaryByIgo(text.control.sp1.isWindows, text.control.sp1.chasenPath, text.control.sp1.absolutePath);		
	}
	
	//CAPTURE
	public final void imageCapture()
	{
		visualization.imageCapture();
	}
	
	public final void imageCapture(String filename)
	{
        visualization.imageCapture(filename);
	}
    
    
    //SET ATTENTION
    
    public void initializeAttentionSegments()
    {
        attentionSegments = new boolean[text.segmentNumber];
        for(int i=0;i<text.segmentNumber;i++)
            attentionSegments[i] = false;// LOCAL focus
    }
    
    public void initializeAttentionSentences()
    {
        attentionSentences = new boolean[text.sentenceNumber];
        for(int i=0;i<text.sentenceNumber;i++)
            attentionSentences[i] = false;// LOCAL focus
    }
    
    public void initializeAttentionKeywords()
    {
        attentionKeywords = new boolean[text.keywordNumber];
        for(int i=0;i<text.keywordNumber;i++)
            attentionKeywords[i] = false;// LOCAL focus
    }
    
    public void setAttentionKeywords()
    {
        text.attention.setAttentionKeywords(attentionKeywords);
    }
    
    public void setAttentionSegments()
    {
        text.attention.setAttentionSegments(attentionSegments);
    }
    
    public void setAttentionSentences()
    {
        text.attention.setAttentionSentences(attentionSentences);
    }
    
	
    //NEW FOCUS*
    public final void selectedByFocus()
    {
        if(panelID != 10000)
            if(focusExecute)
                focusSelected(text);
    }
    //NEW FOCUS*
    public final void setDisplayByFocus()
    {
        if(panelID != 10000)
            visualization.setDisplayByFocus();
    }
    /*
	//FOCUS*
	public final void selectedByTouchFocus()
	{
		if(focusTouchExecute)
			focusSelected(text, 4501);
	}
	//FOCUS*
	public final void selectedByClickFocus()
	{
		if(focusClickExecute)
			focusSelected(text, 4502);
	}
	//FOCUS*
	public final void selectedByTimingFocus()
	{
		if(focusTimingExecute)
			focusSelected(text, 4503);
	}
     */
     
     //NEW FOCUS
     protected final void repaintOthersByFocus()
     {
     if(panelID != 10000)
         text.control.setDisplayOthersByFocus(panelID);
     }
     //NEW FOCUS
     protected final void executeOthersByFocus()
     {
     if(panelID != 10000)
         text.control.resetSelectPanelDataByFocus(panelID);
     }
     //NEW FOCUS    ALL     // NOT TO USE
     protected final void executeAllByFocus()
     {
     if(panelID != 10000)
         text.control.resetSelectPanelDataByFocusAll(panelID);
     }
     
     /*
	//FOCUS*
	public final void setDisplayByTouchFocus()
	{
		visualization.setDisplayByTouchFocus();
	}
	//FOCUS*
	public final void setDisplayByClickFocus()
	{
		visualization.setDisplayByClickFocus();
	}
	//FOCUS*	
	public final void setDisplayByTimingFocus()
	{
		visualization.setDisplayByTimingFocus();
	}	
	*/
	/*
	//FOCUS PARTIAL SEGMENTS
	public void createSegmentPartialData()
	{
		text.control.resetBySegmentPartialData();
	}*/
	//FOCUS PARTIAL SENTENCES   
	/*
	public void createSentencePartialData()
	{
		text.control.resetBySentencePartialData();
	}	
*/
	//FOCUS PARTIAL SEGMENTS
	public void createSegmentPartialData(int number)
	{
        if(panelID != 10000)
            text.control.resetBySegmentPartialData(number);
	}
	//FOCUS PARTIAL SENTENCES        
	public void createSentencePartialData(int number)
	{
        if(panelID != 10000)
            text.control.resetBySentencePartialData(number);
	}
    
    //SET FOCUS
    
    public void initializeFocusSegments()
    {
        focusSegments = new boolean[text.segmentNumber];
        for(int i=0;i<text.segmentNumber;i++)
            focusSegments[i] = false;// LOCAL focus
    }
    
    public void initializeFocusSentences()
    {
        focusSentences = new boolean[text.sentenceNumber];
        for(int i=0;i<text.sentenceNumber;i++)
            focusSentences[i] = false;// LOCAL focus
    }
    
    public void initializeFocusKeywords()
    {
        focusKeywords = new boolean[text.keywordNumber];
        for(int i=0;i<text.keywordNumber;i++)
            focusKeywords[i] = false;// LOCAL focus
    }
    
    public void setFocusSegments(String japaneseCondition, String englishCondition)
    {
        setFocusSegments(focusSegments, japaneseCondition, englishCondition);// LOCAL focus
        
        setDataBooleanArray(4501, focusSegments);
        setDataBooleanArray(4502, getFocusSentences());
        setDataBooleanArray(4503, getFocusKeywords());
        
        if(panelID == 10000)
            text.focus.clearAllFocus();
    }
    
    public void setFocusSentences(String japaneseCondition, String englishCondition)
    {
        setFocusSentences(focusSentences, japaneseCondition, englishCondition);// LOCAL focus
        
        setDataBooleanArray(4502, focusSentences);
        setDataBooleanArray(4501, getFocusSegments());
        setDataBooleanArray(4503, getFocusKeywords());
        
        if(panelID == 10000)
            text.focus.clearAllFocus();
    }

    public void setFocusKeywords(String japaneseCondition, String englishCondition)
    {
        setFocusKeywords(focusKeywords, japaneseCondition, englishCondition);// LOCAL focus
        
        setDataBooleanArray(4503, focusKeywords);
        setDataBooleanArray(4501, getFocusSegments());
        setDataBooleanArray(4502, getFocusSentences());
        
        if(panelID == 10000)
            text.focus.clearAllFocus();
    }
    
    public void setFocusSegmentsLocal(TextData setTextData, boolean value[])
    {
        setTextData.focus.setFocusSegmentsLocal(value);
    }
    
    public void setFocusSentencesLocal(TextData setTextData, boolean value[])
    {
        setTextData.focus.setFocusSentencesLocal(value);
    }
    
    public void setFocusKeywordsLocal(TextData setTextData, boolean value[])
    {
        setTextData.focus.setFocusKeywordsLocal(value);
    }
    
    public void setFocusSegments(boolean value[], String japaneseCondition, String englishCondition)
    {
        if(panelID != 10000)
            text.focus.setFocusSegments(1, moduleID, value, japaneseCondition, englishCondition, true);
        else
            text.focus.setFocusSegments(1, moduleID, value, japaneseCondition, englishCondition, false);
    }
    public void setFocusSentences(boolean value[], String japaneseCondition, String englishCondition)
    {
        if(panelID != 10000)
            text.focus.setFocusSentences(1, moduleID, value, japaneseCondition, englishCondition, true);
        else
            text.focus.setFocusSentences(1, moduleID, value, japaneseCondition, englishCondition, false);
    }
    public void setFocusKeywords(boolean value[], String japaneseCondition, String englishCondition)
    {
        if(panelID != 10000)
            text.focus.setFocusKeywords(1, moduleID, value, japaneseCondition, englishCondition, true);
        else
            text.focus.setFocusKeywords(1, moduleID, value, japaneseCondition, englishCondition, false);
    }

     /*
    private void setOriginalFocusSegments(boolean value[])
    {
        if(panelID != 10000)
            text.control.text.focus.setFocusSegments(1, moduleID, value, "","", false);
    }
    private void setOriginalFocusSentences(boolean value[])
    {
        if(panelID != 10000)
            text.control.text.focus.setFocusSentences(1, moduleID, value, "","", false);
    }
    private void setOriginalFocusKeywords(boolean value[])
    {
        if(panelID != 10000)
            text.control.text.focus.setFocusKeywords(1, moduleID, value, "","", false);
    }
   */
    public boolean[] getOriginalFocusSegments()
    {
        return text.control.text.focus.getFocusSegments();
    }
    public boolean[] getOriginalFocusSentences()
    {
        return text.control.text.focus.getFocusSentences();
    }
    public boolean[] getOriginalFocusKeywords()
    {
        return text.control.text.focus.getFocusKeywords();
    }
    
    /*
    public void setMainFocusKeyword(int value)
    {
        if(panelID != 10000)
            text.focus.setMainFocusKeyword(value);
    }
    public void setSubFocusKeyword(int value)
    {
        if(panelID != 10000)
            text.focus.setSubFocusKeyword(value);
    }
    public void setMainFocusSegment(int value)
    {
        if(panelID != 10000)
            text.focus.setMainFocusSegment(value);
    }
    public void setSubFocusSegment(int value)
    {
        if(panelID != 10000)
            text.focus.setSubFocusSegment(value);
    }
    public void setMainFocusSentence(int value)
    {
        if(panelID != 10000)
            text.focus.setMainFocusSentence(value);
    }
    public void setSubFocusSentence(int value)
    {
        if(panelID != 10000)
            text.focus.setSubFocusSentence(value);
    }
    */
    
    public void resetAllFocus()
    {
        text.control.text.focus.clearAllFocus();
    }
    
    public void resetMainSub()
    {
        text.control.text.focus.clearMainSub();
    }
    
    public void setMainFocusKeyword(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setMainFocusKeyword(1, moduleID, value, "","", only, false);
            
            text.focus.setMainFocusKeyword(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    public void setSubFocusKeyword(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setSubFocusKeyword(1, moduleID, value, "","", only, false);
            
            text.focus.setSubFocusKeyword(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    public void setMainFocusSegment(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setMainFocusSegment(1, moduleID, text.originalSegmentNumbers[value], "","", only, false);
            
            text.focus.setMainFocusSegment(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    public void setSubFocusSegment(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setSubFocusSegment(1, moduleID, text.originalSegmentNumbers[value], "","", only, false);
            
            text.focus.setSubFocusSegment(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    public void setMainFocusSentence(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setMainFocusSentence(1, moduleID, text.originalSentenceNumbers[value], "","", only, false);
            
            text.focus.setMainFocusSentence(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    public void setSubFocusSentence(int value, String japaneseCondition, String englishCondition, boolean only)
    {
        if(panelID != 10000)
        {
            if(text.textID != 0)
                text.control.text.focus.setSubFocusSentence(1, moduleID, text.originalSentenceNumbers[value], "","", only, false);
            
            text.focus.setSubFocusSentence(1, moduleID, value, japaneseCondition, englishCondition, only, true);
        }
    }
    
    public boolean[] getFocusKeywords()
    {
        return text.focus.getFocusKeywords();
    }
    public boolean[] getFocusSegments()
    {
        return text.focus.getFocusSegments();
    }
    public boolean[] getFocusSentences()
    {
        return text.focus.getFocusSentences();
    }
    
    public int getMainFocusKeyword()
    {
        return text.focus.getMainFocusKeyword();
    }
    public int getSubFocusKeyword()
    {
        return text.focus.getSubFocusKeyword();
    }
    public int getMainFocusSegment()
    {
        return text.focus.getMainFocusSegment();
    }
    public int getSubFocusSegment()
    {
        return text.focus.getSubFocusSegment();
    }
    public int getMainFocusSentence()
    {
        return text.focus.getMainFocusSentence();
    }
    public int getSubFocusSentence()
    {
        return text.focus.getSubFocusSentence();
    }
    
    
    
    public int getFocusStatus(int dataNumber)
    {
        return text.focus.getFocusStatus(dataNumber);
    }
    
    //FOCUS SHRINK CONTROL
    
    public void shrinkReset()
    {
        text.control.btd2.doClick();
    }
    
    public void shrinkExecute()  //MUST BE USED WITH shrinkReset
    {
        text.control.btd1.doClick();
    }
    
    
    //FOCUS CONTROL
    public void setMainFocusBoolean(boolean value)
    {
        if(panelID != 10000)
            text.control.focus.mainFocusBoolean = value;
    }
    public void setSubFocusBoolean(boolean value)
    {
        if(panelID != 10000)
            text.control.focus.subFocusBoolean = value;
    }
    public void setMainFocusInteger(int value)
    {
        if(panelID != 10000)
            text.control.focus.mainFocusInteger = value;
    }
    public void setSubFocusInteger(int value)
    {
        if(panelID != 10000)
            text.control.focus.subFocusInteger = value;
    }
    public void setMainFocusDouble(double value)
    {
        if(panelID != 10000)
            text.control.focus.mainFocusDouble = value;
    }
    public void setSubFocusDouble(double value)
    {
        if(panelID != 10000)
            text.control.focus.subFocusDouble = value;
    }
    public void setMainFocusString(String value)
    {
        if(panelID != 10000)
            text.control.focus.mainFocusString = value;
    }
    public void setSubFocusString(String value)
    {
        if(panelID != 10000)
            text.control.focus.subFocusString = value;
    }
    
    public void setFocusBooleanArray(boolean values[])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusBooleanArray = new boolean[values.length];
        for(int i=0;i<values.length;i++)
            text.control.focus.focusBooleanArray[i] = values[i];
    }
    public void setFocusIntegerArray(int values[])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusIntegerArray = new int[values.length];
        for(int i=0;i<values.length;i++)
            text.control.focus.focusIntegerArray[i] = values[i];
    }
    public void setFocusDoubleArray(double values[])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusDoubleArray = new double[values.length];
        for(int i=0;i<values.length;i++)
            text.control.focus.focusDoubleArray[i] = values[i];
    }
    public void setFocusStringArray(String values[])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusStringArray = new String[values.length];
        for(int i=0;i<values.length;i++)
            text.control.focus.focusStringArray[i] = values[i];
    }
    
    public void setFocusBooleanArray2(boolean values[][])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusBooleanArray2 = new boolean[values.length][];
        for(int i=0;i<values.length;i++)
        {
            text.control.focus.focusBooleanArray2[i] = new boolean[values[i].length];
            for(int j=0;j<values[i].length;j++)
            {
                text.control.focus.focusBooleanArray2[i][j] = values[i][j];
                
                System.out.println("INPUT:"+i+","+j+":"+values[i][j]);
            }
        }
    }
    public void setFocusIntegerArray2(int values[][])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusIntegerArray2 = new int[values.length][];
        for(int i=0;i<values[i].length;i++)
        {
            text.control.focus.focusIntegerArray2[i] = new int[values[i].length];
            for(int j=0;j<values.length;j++)
                text.control.focus.focusIntegerArray2[i][j] = values[i][j];
        }
    }
    public void setFocusDoubleArray2(double values[][])
    {
        if(panelID == 10000)
            return;
        
        text.control.focus.focusDoubleArray2 = new double[values.length][];
        for(int i=0;i<values[i].length;i++)
        {
            text.control.focus.focusDoubleArray2[i] = new double[values[i].length];
            for(int j=0;j<values.length;j++)
                text.control.focus.focusDoubleArray2[i][j] = values[i][j];
        }
    }
    

    public boolean getMainFocusBoolean()
    {
        return text.control.focus.mainFocusBoolean;
    }
    public boolean getSubFocusBoolean()
    {
        return text.control.focus.subFocusBoolean;
    }
    public int getMainFocusInteger()
    {
        return text.control.focus.mainFocusInteger;
    }
    public int getSubFocusInteger()
    {
        return text.control.focus.subFocusInteger;
    }
    public double getMainFocusDouble()
    {
        return text.control.focus.mainFocusDouble;
    }
    public double getSubFocusDouble()
    {
        return text.control.focus.subFocusDouble;
    }
    public String getMainFocusString()
    {
        return text.control.focus.mainFocusString;
    }
    public String getSubFocusString()
    {
        return text.control.focus.subFocusString;
    }
    
    public boolean[] getFocusBooleanArray()
    {
        return text.control.focus.focusBooleanArray;
    }
    public int[] getFocusIntegerArray()
    {
        return text.control.focus.focusIntegerArray;
    }
    public double[] getFocusDoubleArray()
    {
        return text.control.focus.focusDoubleArray;
    }
    public String[] getFocusStringArray()
    {
        return text.control.focus.focusStringArray;
    }
    
    public boolean[][] getFocusBooleanArray2()
    {
        return text.control.focus.focusBooleanArray2;
    }
    public int[][] getFocusIntegerArray2()
    {
        return text.control.focus.focusIntegerArray2;
    }
    public double[][] getFocusDoubleArray2()
    {
        return text.control.focus.focusDoubleArray2;
    }
    
	
	//SET DATA
    public final void resetData()
    {
        visualization.resetData();
    }
    
	String dataType[] = {"boolean","int","double","String","boolean[]","int[]","double[]","String[]","boolean[][]","int[][]","double[][]"};
	
	public void printResult(int from, int to)
	{
		if(from == to)
		{
			System.out.println("Data type "+dataType[from]+" was set.");
			return;
		}
		if(to == 11)
		{
			System.out.println("Data type "+dataType[from]+" was NOT set.");
			return;
		}
		System.out.println("Data type "+dataType[from]+" was CONVERTED to "+dataType[to]+".");
	}
	
	public final boolean checkTextID()
	{
        if(partialDocumentA == -1 || partialDocumentB == -1)//-1:---,0:---,1:ALL,2:SEG1,3:SEG2,4:SEN1,5:SEN2
        {
			textID1 = textID2 = 0;	// NOT CREATE DIFFERENCE
			return false;
        }
        
        if(partialDocumentA == partialDocumentB) // SELECTED SAME DATA
        {
            textID1 = textID2 = 0;
            partialDocumentA = -1;
            partialDocumentB = -1;
            
			combinationPanel.autoSet = true;
            combinationPanel.partialDocument.setSelectedIndex(0);
			combinationPanel.autoSet = false;
            return false;
        }
        
        int indexToID[] = {0,0,1,3,2,4};
        
        textID1 = indexToID[partialDocumentA];
        textID2 = indexToID[partialDocumentB];
		
		return true;
	}

	public final int checkDiff(int typeNumber, int dataID)
	{
		int diff = -1;
		if(textID1 != textID2)
		{
			if(diffPatterns[typeNumber] != null)
			{
				if(dataID < diffPatterns[typeNumber].length-1)
					diff = diffPatterns[typeNumber][dataID+1];
				else			
					diff = diffPatterns[typeNumber][0];
			}
			else
				diff = 0;
		}
		return diff;
	}

	public final void setDataBoolean(int dataID, boolean data)
	{
		checkTextID();
        setData.setDataBoolean(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(0, dataID));
	}
	public final void setDataInteger(int dataID, int data)
	{
		checkTextID();		
        setData.setDataInteger(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(1, dataID));
	}
	public final void setDataDouble(int dataID, double data)
	{
		checkTextID();		
        setData.setDataDouble(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(2, dataID));
	}
	public final void setDataString(int dataID, String data)
	{
		checkTextID();		
        setData.setDataString(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(3, dataID));
	}
	public final void setDataBooleanArray(int dataID, boolean data[])
	{
		checkTextID();		
        setData.setDataBooleanArray(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(4, dataID));
	}
	public final void setDataIntegerArray(int dataID, int data[])
	{
		checkTextID();		
        setData.setDataIntegerArray(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(5, dataID));
	}
	public final void setDataDoubleArray(int dataID, double data[])
	{
		checkTextID();		
        setData.setDataDoubleArray(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(6, dataID));
	}
	public final void setDataStringArray(int dataID, String data[])
	{
		checkTextID();		
        setData.setDataStringArray(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(7, dataID));
	}
	public final void setDataBooleanArray2(int dataID, boolean data[][])
	{
		checkTextID();		
        setData.setDataBooleanArray2(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(8, dataID));
	}
	public final void setDataIntegerArray2(int dataID, int data[][])
	{
		checkTextID();		
        setData.setDataIntegerArray2(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(9, dataID));
	}
	public final void setDataDoubleArray2(int dataID, double data[][])
	{
		checkTextID();		
        setData.setDataDoubleArray2(dataID, data,moduleID,text,visualization, textID1, textID2, checkDiff(10, dataID));
	}	
	
	
	public final void setDataBoolean(boolean data)
	{
		checkTextID();
		int to = setData.setDataBoolean(data,moduleID,text,visualization, textID1, textID2, checkDiff(0, visualization.booleanNumber));
		printResult(0,to);
	}	
	public final void setDataInteger(int data)
	{
		checkTextID();		
        int to = setData.setDataInteger(data,moduleID,text,visualization, textID1, textID2, checkDiff(1, visualization.integerNumber));
		printResult(1,to);		
	}
	public final void setDataDouble(double data)
	{
		checkTextID();		
        int to = setData.setDataDouble(data,moduleID,text,visualization, textID1, textID2, checkDiff(2, visualization.doubleNumber));
		printResult(2,to);		
	}
	public final void setDataString(String data)
	{
		checkTextID();		
        int to = setData.setDataString(data,moduleID,text,visualization, textID1, textID2, checkDiff(3, visualization.StringNumber));
		printResult(3,to);		
	}
	public final void setDataBooleanArray(boolean data[])
	{
		checkTextID();		
        int to = setData.setDataBooleanArray(data,moduleID,text,visualization, textID1, textID2, checkDiff(4, visualization.booleanArrayNumber));
		printResult(4,to);		
	}	
	public final void setDataIntegerArray(int data[])
	{
		checkTextID();		
        int to = setData.setDataIntegerArray(data,moduleID,text,visualization, textID1, textID2, checkDiff(5, visualization.integerArrayNumber));
		printResult(5,to);		
	}
	public final void setDataDoubleArray(double data[])
	{
		checkTextID();		
        int to = setData.setDataDoubleArray(data,moduleID,text,visualization, textID1, textID2, checkDiff(6, visualization.doubleArrayNumber));
		printResult(6,to);		
	}
	public final void setDataStringArray(String data[])
	{
		checkTextID();		
        int to = setData.setDataStringArray(data,moduleID,text,visualization, textID1, textID2, checkDiff(7, visualization.StringArrayNumber));
		printResult(7,to);		
	}	
	public final void setDataBooleanArray2(boolean data[][])
	{
		checkTextID();		
        int to = setData.setDataBooleanArray2(data,moduleID,text,visualization, textID1, textID2, checkDiff(8, visualization.booleanArray2Number));
		printResult(8,to);		
	}	
	public final void setDataIntegerArray2(int data[][])
	{
		checkTextID();		
        int to = setData.setDataIntegerArray2(data,moduleID,text,visualization, textID1, textID2, checkDiff(9, visualization.integerArray2Number));
		printResult(9,to);		
	}
	public final void setDataDoubleArray2(double data[][])
	{
		checkTextID();		
        int to = setData.setDataDoubleArray2(data,moduleID,text,visualization, textID1, textID2, checkDiff(10, visualization.doubleArray2Number));
		printResult(10,to);		
	}
    


	
	//GET DATA
	public final boolean getDataBoolean(int getModuleID, int dataID)
	{
		return text.connection.getDataBoolean(text.textID, getModuleID, dataID);
	}	
	public final int getDataInteger(int getModuleID, int dataID)
	{
		return text.connection.getDataInteger(text.textID, getModuleID, dataID);
	}
	public final double getDataDouble(int getModuleID, int dataID)
	{
		return text.connection.getDataDouble(text.textID, getModuleID, dataID);
	}
	public final String getDataString(int getModuleID, int dataID)
	{
		return text.connection.getDataString(text.textID, getModuleID, dataID);
	}
	public final boolean[] getDataBooleanArray(int getModuleID, int dataID)
	{
		return text.connection.getDataBooleanArray(text.textID, getModuleID, dataID);
	}		
	public final int[] getDataIntegerArray(int getModuleID, int dataID)
	{
		return text.connection.getDataIntegerArray(text.textID, getModuleID, dataID);
	}
	public final double[] getDataDoubleArray(int getModuleID, int dataID)
	{
		return text.connection.getDataDoubleArray(text.textID, getModuleID, dataID);
	}
	public final String[] getDataStringArray(int getModuleID, int dataID)
	{
		return text.connection.getDataStringArray(text.textID, getModuleID, dataID);
	}	
	public final boolean[][] getDataBooleanArray2(int getModuleID, int dataID)
	{
		return text.connection.getDataBooleanArray2(text.textID, getModuleID, dataID);
	}		
	public final int[][] getDataIntegerArray2(int getModuleID, int dataID)
	{
		return text.connection.getDataIntegerArray2(text.textID, getModuleID, dataID);
	}
	public final double[][] getDataDoubleArray2(int getModuleID, int dataID)
	{
		return text.connection.getDataDoubleArray2(text.textID, getModuleID, dataID);
	}	

	public final boolean getDataBoolean(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataBoolean(text.textID, getModuleID, dataID, optionNumber);
	}
	public final int getDataInteger(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataInteger(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double getDataDouble(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataDouble(text.textID, getModuleID, dataID, optionNumber);
	}
	public final String getDataString(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataString(text.textID, getModuleID, dataID, optionNumber);
	}
	public final boolean[] getDataBooleanArray(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataBooleanArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final int[] getDataIntegerArray(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataIntegerArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double[] getDataDoubleArray(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataDoubleArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final String[] getDataStringArray(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataStringArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final boolean[][] getDataBooleanArray2(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataBooleanArray2(text.textID, getModuleID, dataID, optionNumber);
	}
	public final int[][] getDataIntegerArray2(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataIntegerArray2(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double[][] getDataDoubleArray2(int getModuleID, int dataID, int optionNumber)
	{
		return text.connection.getDataDoubleArray2(text.textID, getModuleID, dataID, optionNumber );
	}	
	
	
	//GET NEW DATA	// CAUTION: delete all data of the same dataID,
            //CAUTION: If the indicated module used another getData, that may use old data. This method should delete all relevant data.
	public final boolean getNewDataBoolean(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 0);
		return text.connection.getDataBoolean(text.textID, getModuleID, dataID);
	}	
	public final int getNewDataInteger(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 1);
		return text.connection.getDataInteger(text.textID, getModuleID, dataID);
	}
	public final double getNewDataDouble(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 2);
		return text.connection.getDataDouble(text.textID, getModuleID, dataID);
	}
	public final String getNewDataString(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 3);
		return text.connection.getDataString(text.textID, getModuleID, dataID);
	}
	public final boolean[] getNewDataBooleanArray(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 4);
		return text.connection.getDataBooleanArray(text.textID, getModuleID, dataID);
	}	
	public final int[] getNewDataIntegerArray(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 5);
		return text.connection.getDataIntegerArray(text.textID, getModuleID, dataID);
	}
	public final double[] getNewDataDoubleArray(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 6);
		return text.connection.getDataDoubleArray(text.textID, getModuleID, dataID);
	}
	public final String[] getNewDataStringArray(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 7);
		return text.connection.getDataStringArray(text.textID, getModuleID, dataID);
	}	
	public final boolean[][] getNewDataBooleanArray2(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 8);
		return text.connection.getDataBooleanArray2(text.textID, getModuleID, dataID);
	}	
	public final int[][] getNewDataIntegerArray2(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 9);
		return text.connection.getDataIntegerArray2(text.textID, getModuleID, dataID);
	}
	public final double[][] getNewDataDoubleArray2(int getModuleID, int dataID)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 10);
		return text.connection.getDataDoubleArray2(text.textID, getModuleID, dataID);
	}	
	
	public final boolean getNewDataBoolean(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 0);
		return text.connection.getDataBoolean(text.textID, getModuleID, dataID, optionNumber);
	}	
	public final int getNewDataInteger(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 1);
		return text.connection.getDataInteger(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double getNewDataDouble(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 2);
		return text.connection.getDataDouble(text.textID, getModuleID, dataID, optionNumber);
	}
	public final String getNewDataString(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 3);
		return text.connection.getDataString(text.textID, getModuleID, dataID, optionNumber);
	}
	public final boolean[] getNewDataBooleanArray(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 4);
		return text.connection.getDataBooleanArray(text.textID, getModuleID, dataID, optionNumber);
	}	
	public final int[] getNewDataIntegerArray(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 5);
		return text.connection.getDataIntegerArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double[] getNewDataDoubleArray(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 6);
		return text.connection.getDataDoubleArray(text.textID, getModuleID, dataID, optionNumber);
	}
	public final String[] getNewDataStringArray(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 7);
		return text.connection.getDataStringArray(text.textID, getModuleID, dataID, optionNumber);
	}	
	public final boolean[][] getNewDataBooleanArray2(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 8);
		return text.connection.getDataBooleanArray2(text.textID, getModuleID, dataID, optionNumber);
	}	
	public final int[][] getNewDataIntegerArray2(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 9);
		return text.connection.getDataIntegerArray2(text.textID, getModuleID, dataID, optionNumber);
	}
	public final double[][] getNewDataDoubleArray2(int getModuleID, int dataID, int optionNumber)
	{
		text.connection.deleteData(text.textID, getModuleID, dataID, 10);
		return text.connection.getDataDoubleArray2(text.textID, getModuleID, dataID, optionNumber);
	}		
	
	
	//EXECUTION
	public final void executeOtherModuleFirst(int executeModuleID, int optionNumber)
	{
		text.connection.executeModuleWithOptionFirst(panelID, executeModuleID, optionNumber);
	}	
	public final void executeOtherModule(int executeModuleID, int optionNumber)
	{
		text.connection.executeModuleWithOption(panelID, executeModuleID, optionNumber);
	}
	public final void executeModuleFirst(int executeModuleID, int optionNumber)
	{
		text.connection.executeModuleWithOptionFirstFromXXX(executeModuleID, optionNumber);
	}	
	public final void executeModule(int executeModuleID, int optionNumber)
	{
		text.connection.executeModuleWithOptionFromXXX(executeModuleID, optionNumber);
	}	

	//DISPLAY
	public final void displayOtherModuleFirst(int displayModuleID, int optionNumber)
	{
		text.connection.displayModuleWithOptionFirst(panelID, displayModuleID, optionNumber);
	}	
	public final void displayOtherModule(int displayModuleID, int optionNumber)
	{
		text.connection.displayModuleWithOption(panelID, displayModuleID, optionNumber);
	}
	public final void displayModuleFirst(int displayModuleID, int optionNumber)
	{
		text.connection.displayModuleWithOptionFirstFromXXX(displayModuleID, optionNumber);
	}	
	public final void displayModule(int displayModuleID, int optionNumber)
	{
		text.connection.displayModuleWithOptionFromXXX(displayModuleID, optionNumber);
	}	

	
	//PANEL SET
	public final void panelSetFromModule(int moduleIDs[], int displayIDs[])
	{
		combinationPanel.panelSetFromModule(moduleIDs, displayIDs);
	}
	
	public final void panelSetFromModule(int moduleIDs[], int displayIDs[], int sizeX[])
	{
		combinationPanel.panelSetFromModule(moduleIDs, displayIDs, sizeX);
	}	
	
	//JAPANESE
	public boolean isMenuInJapanese()
	{		
		return text.control.text.settingData.inJapanese;
	}	

    //FONTSIZE
    public int getFontSize()
    {
        return text.control.sp1.toolFontSize;
    }
    
	//DISPLAY PROCESS
	public void createProcessingPop()
	{
		String windowTitle = "Mining Processing";
		if(text.control.sp1.inJapanese)
			windowTitle = text.control.windowNameInJapanese[13];		
		
		if(processingPanel == null)		
			processingPanel = new PopUpForProcessing(text.control.sp1.windowSizeX/2 - 250, 500,500,300, myModuleName+" in PANEL "+(panelID+1)+"(panelID="+panelID+")", Color.green, text.control.absolutePath, text.getFontName(), windowTitle);
	}
	
	public void setProcessingPercent(int percent)
	{
        if(processingPanel != null)		
			processingPanel.setPercent(percent);
	}		
	
	public void disposeProcessingPop()
	{
        if(processingPanel != null)
        {
            processingPanel.dispose();
            processingPanel = null;
        }
	}
    
    public void closeAllWindows()
    {
        disposeProcessingPop();
        if(visualization != null)
            visualization.disposeProcessingPop();
        if(combinationPanel != null)
        {
            combinationPanel.closePopForDiff();
            combinationPanel.closePopForMining();
            combinationPanel.closePopForVisualization();
        }
    }
	
	//SAVE ACTION LOG
	
	
	public void writeButtonLog(String buttonName, Component component)
	{
        ACTIONLOG.writeButtonLogFromModule("PANEL-"+panelID+"-MINING", buttonName, moduleID, visualization.getModuleID(),component);
	}
    
    public void writeButtonLogWithExp(String buttonName, Component component)
    {
        ACTIONLOG.writeButtonLogFromModule("PANEL-"+panelID+"-MINING", buttonName, moduleID, visualization.getModuleID(),component);

        text.control.ex1.addExpByOperatedMiningModule(moduleID);
        if(text.control.expPanel != null)
            text.control.expPanel.repaint();
    }

    public void writeMouseLog(String operation)
    {
        ACTIONLOG.writeMouseLogFromModule("PANEL-"+panelID+"-MINING", operation, moduleID, visualization.getModuleID());
    }
    
    public void writeMouseWheelLog(double rotation)
    {
        ACTIONLOG.writeMouseWheelLogFromModule("PANEL-"+panelID+"-MINING", rotation, moduleID, visualization.getModuleID());
    }
    /*
    public void writeMouseLogWithExp(String operation)
    {
        ACTIONLOG.writeMouseLogFromModule("PANEL-"+panelID+"-MINING", operation, moduleID, visualization.getModuleID());

        text.control.ex1.addExpByOperatedMiningModule(moduleID);
        if(text.control.expPanel != null)
            text.control.expPanel.repaint();
    }
    */
    public void writeTextLog(String text)
    {
        ACTIONLOG.writeTextInputLogFromModule("PANEL-"+panelID+"-MINING", text, moduleID, visualization.getModuleID());
    }
	
	//mouse motion listener
	public void writeMoveLog()
	{
		writeMouseLog("MOVE");
	}
	
	public void writeDragLog()
	{
        //        writeLogWithExp("DRAG");
        writeMouseLog("DRAG");
	}

    public void writeBarDragLog()
    {
        writeMouseLog("DRAG(BAR-ADJUSTED)");
    }
	
	//mouse listener
	public void writeClickLog()
	{
		writeMouseLog("CLICK");
	}
	
	public void writePressLog()
	{
		writeMouseLog("PRESS");
	}
	
	public void writeReleaseLog()
	{
		writeMouseLog("RELEASE");
	}
	
	public void writeEnterLog()
	{
		writeMouseLog("ENTER");
	}
	
	public void writeExitLog()
	{
		writeMouseLog("EXIT");
	}	
	
    //mouse wheel "WHEEL"
    public void writeWheelLog(double rotation)
    {
        writeMouseWheelLog(rotation);
    }
	
	//button		
	public void writeButtonLog(ActionEvent e)
	{
		writeButtonLogWithExp(getButtonName(e),(Component)e.getSource());
	}
    
    public void writeSelectionButtonLog(ActionEvent e)
    {
        writeButtonLogWithExp(getButtonName(e),(Component)e.getSource());
    }
	
	public String getButtonName(ActionEvent e)
	{
		return text.control.getButtonName(e);
	}	
	
	//SAVE ACTION LOG
    public void writeActionLog(String data)
    {
//        String dataText = String.format("%.2f",text.control.getDiffTime())+" Mining PanelID="+panelID+" "+"ModuleID="+moduleID+" "+"TextID="+text.textID+" "+data+System.getProperty("line.separator");
        ACTIONLOG.writeActionLog("PANEL-"+panelID+"-MINING*"+data);
    }
	
    ///// AUTO SAVE INTERPRETATION
    // importanceRate should be 1-5
    public void autoInterpretation(String result, String meaning, int importanceRate)
    {
        if(result.equals("") && meaning.equals(""))
        {
            System.out.println("Both result and meaning are not given");
        }
        if(result.equals(""))
            result = "NO RESULT";
        if(meaning.equals(""))
            meaning = "NO MEANING";
        
        
        
        text.control.getPanelInformation();
        int miningIDs[] = new int[text.control.panelNumber];
        int visualizationIDs[] = new int[text.control.panelNumber];
        int textIDs[] = new int[text.control.panelNumber];
        int sizeX[] = new int[text.control.panelNumber];
        
        for(int i=0;i<text.control.panelNumber;i++)
        {
            miningIDs[i] = text.control.miningIDs[i];
            visualizationIDs[i] = text.control.visualizationIDs[i];
            textIDs[i] = text.control.textIDs[i];
            sizeX[i] = text.control.balancedPanelSizeX[i];
        }
        
        if(text.control.interpretationNumber < text.control.maxInterpretationNumber)
        {
            System.out.println("AUTO Create situation"+(text.control.interpretationNumber+1)+".png");
            imageCapture(text.control.absolutePath + "interpretation" + File.separator + "situation"+(text.control.interpretationNumber+1)+".png");//must before add Interpretation
            
            text.control.addInterpretation(new File(text.sourceFilename).getName(), result, meaning, importanceRate, miningIDs, visualizationIDs, textIDs, sizeX, panelID);
            text.control.writeInterpretation(text.control.interpretationNumber);
            
            System.out.println("AUTO RESULT = "+result);
            System.out.println("AUTO INTERPRETATION = "+meaning);
            System.out.println("AUTO IMPORTANCE = "+importanceRate);
            
            /////////SCENE DATA REVISION
            PopUpForKnowledgeCreation sceneDataRevision = new PopUpForKnowledgeCreation(text.control);
            sceneDataRevision = null;
        }
    }
    
    
	//PANEL SET
	public void additionalPanelSet(){}

	//PANEL SET
	public class CombinationPanel extends JPanel implements ActionListener
	{
		public JButton panelDeleteButton;
		public JButton panelBackButton;
		public JButton panelSetButton;		
		public JToggleButton panelKeepButton;
		public JButton panelCaptureButton;
		
		public JToggleButton displayReadmeButton;
		PopUpWindow popForMining, popForVisualization;
        
		public JToggleButton characterTutorialButton;
        String tutorialFilename;

		public JButton panelLoadButton;
		public JButton panelRecordButton;
		
		public JToggleButton displayDiffButton;		

		
//		public JComboBox partialSegments1;
//		public JComboBox partialSegments2;
//		public JComboBox partialSentences1;
//		public JComboBox partialSentences2;

		public JComboBox partialDocument;
        
        JPanel subLabelPanel[];
        JLabel buttonLabel[];
        JPanel partial;
		
		MiningModule mining;
		
		boolean autoSet = false;
        boolean autoSetPartial = false;
		
		CombinationPanel(MiningModule mining)
		{
			this.mining = mining;
			
			setLayout(new GridLayout());
			initializePanel();
		}
		
		void initializePanel()
		{
			if(defaultSetPanelModuleID == null)		// NOT GIVEN IN THE CONSTRUCTOR
				defaultSetPanel();		//SET DEFAULT PANEL COMBINATION
			
			if(defaultSetPanelTextID == null)		// NOT GIVEN IN THE CONSTRUCTOR
				defaultSetPanelTextID();
            
            if(defaultBalancedPanelSizeX == null)		// NOT GIVEN IN THE CONSTRUCTOR
                defaultBalancedPanelSizeX();
			
			String filename = absolutePath+"source"+File.separator+"japaneseText"+File.separator+"JapaneseMining.txt";					
			File jpname = new File(filename);

			buttonNamesInJapanese = FILEIO.TextFileAllReadCodeArray(jpname);
			
            int labelNumber = 8;
			subLabelPanel = new JPanel[labelNumber];
            buttonLabel = new JLabel[labelNumber];
            for(int i=0;i<labelNumber;i++)
            {
                subLabelPanel[i] = new JPanel(new BorderLayout());
                if(i<3)
                    subLabelPanel[i].setBackground(Color.PINK);
//                        subLabelPanel[i].setBackground(new Color(0xff,0xda,0xb9));
                else if(i==3)
                    subLabelPanel[i].setBackground(new Color(0xad, 0xff, 0x2f));
                else if(i<6)
//                    subLabelPanel[i].setBackground(new Color(0xff,0xda,0xb9));
                subLabelPanel[i].setBackground(new Color(0xec,0xb2,0xdd));
//                                    subLabelPanel[i].setBackground(new Color(0xe0,0xf2,0xf7));
               //     subLabelPanel[i].setBackground(Color.PINK);
                else
                    subLabelPanel[i].setBackground(Color.GREEN);
  //                  subLabelPanel[i].setBackground(new Color(0x58,0xfa,0x82));
                buttonLabel[i] = new JLabel();
                buttonLabel[i].setFont(new Font(text.getFontName(), Font.BOLD, 10));

            }
            
            
            String partialDocumentNames[] = {"-","ALL","SEG-SET-1","SEG-SET-2","SEN-SET-1","SEN-SET-2"};

			
			if(isMenuInJapanese())
			{
                buttonLabel[0].setText(buttonNamesInJapanese[11]);
                buttonLabel[1].setText(" ");
                buttonLabel[2].setText(" ");
                buttonLabel[3].setText("");
//                buttonLabel[4].setText(buttonNamesInJapanese[12]);
                buttonLabel[4].setText("");
                buttonLabel[5].setText("");
                buttonLabel[6].setText(buttonNamesInJapanese[13]);
                buttonLabel[7].setText("");				
                
				panelDeleteButton = new JButton(buttonNamesInJapanese[0],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"delete.png"));
				panelBackButton = new JButton(buttonNamesInJapanese[1],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"back.png"));
				panelSetButton = new JButton(buttonNamesInJapanese[2],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"set.png"));				
				panelKeepButton = new JToggleButton(buttonNamesInJapanese[3],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"keep.png"));
				panelCaptureButton = new JButton(buttonNamesInJapanese[4],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
				
                panelSetButton.setFont(new Font(text.control.sp1.fontName, Font.PLAIN, text.control.sp1.fontSize-2));
                panelKeepButton.setFont(new Font(text.control.sp1.fontName, Font.PLAIN, text.control.sp1.fontSize-2));
                
				panelLoadButton = new JButton(buttonNamesInJapanese[5],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
				panelRecordButton = new JButton(buttonNamesInJapanese[6],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
                
                partialDocumentNames[1] = buttonNamesInJapanese[15];
                for(int i=2;i<6;i++)
                    partialDocumentNames[i] = buttonNamesInJapanese[16]+"-"+(i-1);
                partialDocument = new JComboBox(partialDocumentNames);

				displayReadmeButton = new JToggleButton(buttonNamesInJapanese[9],new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"readme.png"));
                displayDiffButton = new JToggleButton(buttonNamesInJapanese[14]);
                
                characterTutorialButton = new JToggleButton(buttonNamesInJapanese[28]);
			}
			else
			{
                buttonLabel[0].setText("Panel");
                buttonLabel[1].setText(" ");
                buttonLabel[2].setText(" ");
                buttonLabel[3].setText("");
                buttonLabel[4].setText("Tool");
                buttonLabel[5].setText(" ");
                buttonLabel[6].setText("Text");
                buttonLabel[7].setText("");				
				
			
                
				panelDeleteButton = new JButton("DELETE",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"delete.png"));
				panelBackButton = new JButton("BACK",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"back.png"));
				panelSetButton = new JButton("SET",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"set.png"));				
				panelKeepButton = new JToggleButton("KEEP",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"keep.png"));
				panelCaptureButton = new JButton("IMAGE",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));

				panelLoadButton = new JButton("MYSET",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
				panelRecordButton = new JButton("REC",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"camera.png"));
                
                partialDocument = new JComboBox(partialDocumentNames);
				
				displayReadmeButton = new JToggleButton("README",new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"readme.png"));
				displayDiffButton = new JToggleButton("DIFF");
                
                characterTutorialButton = new JToggleButton("CHAR");

			}
            displayReadmeButton.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"image"+File.separator+"close.png"));
            displayReadmeButton.setForeground(Color.blue);

            
			
			
			panelDeleteButton.setBackground(Color.PINK);
			panelKeepButton.setBackground(Color.PINK);
			panelSetButton.setBackground(Color.PINK);
			panelBackButton.setBackground(Color.PINK);
			
			panelDeleteButton.addActionListener(this);
			panelKeepButton.addActionListener(this);
			panelSetButton.addActionListener(this);
			panelBackButton.addActionListener(this);

			panelCaptureButton.setBackground(new Color(0xec,0xb2,0xdd));
			displayReadmeButton.setBackground(new Color(0xec,0xb2,0xdd));
            characterTutorialButton.setBackground(new Color(0xec,0xb2,0xdd));
			
			panelCaptureButton.addActionListener(this);
			displayReadmeButton.addActionListener(this);
            characterTutorialButton.addActionListener(this);
			

			partialDocument.setBackground(Color.GREEN);
			displayDiffButton.setBackground(Color.GREEN);
			
			partialDocument.addActionListener(this);
            displayDiffButton.addActionListener(this);			
			
			autoSet = true;
            partialDocument.setSelectedIndex(0);
			autoSet = false;
			
			
			//panelLoadButton.addActionListener(this);
			//panelRecordButton.addActionListener(this);
			

            
			
			
			
			

            for(int i=0;i<labelNumber;i++)    //except partial
				if(text.control.sp1.miningButtons[i])
					add(subLabelPanel[i]);
            
			subLabelPanel[0].add(panelDeleteButton);
			subLabelPanel[1].add(panelKeepButton);
			subLabelPanel[2].add(panelSetButton);
            subLabelPanel[3].add(characterTutorialButton);
            //			subLabelPanel[3].add(panelBackButton);
			subLabelPanel[4].add(panelCaptureButton);
			subLabelPanel[5].add(displayReadmeButton);
            

            
            partial = new JPanel();
//            partial.setLayout(new GridLayout(1,2));
            partial.setLayout(new GridLayout(1,1));
            partial.setBackground(Color.green);
            subLabelPanel[6].add(partial);
			
            
            partial.add(partialDocument);

            for(int i=0;i<labelNumber;i++)
                subLabelPanel[i].add(buttonLabel[i],BorderLayout.NORTH);

//            subLabelPanel[7].add(displayDiffButton);
			
			//add(setFocusSegmentsButton);
			//add(setFocusSentencesButton);			
			
			//			add(panelLoadButton);			
			//			add(panelRecordButton);			
			
//            setBackground(new Color(0x58,0xfa,0x82));
			setBackground(Color.white);
						
			if(!text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].panelRecorded)
				panelLoadButton.setEnabled(false);
			if(!text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].panelBack)
				panelBackButton.setEnabled(false);
            
            tutorialFilename = text.control.absolutePath+File.separator+"module"+File.separator+"MiningModules"+File.separator+myModuleName+File.separator+myModuleName+"Tutorial.txt";
            File file = new File(tutorialFilename);
            if(!file.exists())
            {
                tutorialExist = false;
                System.out.println("Tutorial Not Found");
                characterTutorialButton.setEnabled(false);
            }
            else
                tutorialExist = true;
		}
		
        public void closePopForDiff()
        {
            if(popForDiff != null)
            {
                popForDiff.dispose();
                popForDiff = null;
            }
        }

		
		///////////////// EXP ///////////////
		public void buttonExp(ActionEvent e)
		{
			int number = -1;
			
			if(e.getSource() == panelDeleteButton)
				number = 0;
			if(e.getSource() == panelKeepButton)
				number = 1;
			if(e.getSource() == panelSetButton)
				number = 2;
			if(e.getSource() == panelBackButton)
				number = 3;		
			if(e.getSource() == panelCaptureButton)
				number = 4;
			if(e.getSource() == displayReadmeButton)
				number = 5;
			if(e.getSource() == partialDocument)
				number = 6;
			if(e.getSource() == displayDiffButton)
				number = 7;					
			
			
			if(number >= 0)
				addExpByMiningButton(number);			
			
		}
		
		public void addExpByMiningButton(int number)
		{
			text.control.ex1.addExpByMiningButton(number);
			if(text.control.expPanel != null)			
				text.control.expPanel.repaint();		
		}		
		

		/*
		public String getButtonName(ActionEvent e)
		{
            String log = e.getSource().toString();
			//            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;
		}
		 */
		
		//Action listener
		public void actionPerformed(ActionEvent e)
		{
			if(autoSet)
				return;
            
			///////////////// EXP ///////////////
			buttonExp(e);			
			
			/*
            String log = e.getSource().toString();
//            String regex = "text=(.*),";
            String regex = "text=(.*)]";
            Pattern p = Pattern.compile(regex);
        
            Matcher m = p.matcher(log);
            */
			
			String buttonName = getButtonName(e);
			
			
//			writeActionLog("MINING:"+myModuleName,buttonName);
            
            if(autoSetPartial == false)
                writeButtonLog(buttonName, (Component)e.getSource());

			
			/*
            if(m.find())
			{
                writeActionLog(m.group(1));
				writeActionLog("MINING:"+myModuleName,m.group(1));
			}
            else
			{				
                writeActionLog(log);
				writeActionLog("MINING:"+myModuleName,log);
			}
            */
			
			//			insideOfActionPerformed(e);	
			if(e.getSource() == panelDeleteButton)
            {
				panelDelete();
                StoryControl.nextSerif(3001);
            }
			
			if(e.getSource() == panelKeepButton)
            {
				panelKeep();
                StoryControl.nextSerif(3002);
            }
			
			if(e.getSource() == panelSetButton)
            {
                closePopForDiff();
				panelSet();
                StoryControl.nextSerif(3003);
            }			
			
            /*
			if(e.getSource() == panelBackButton)
            {
                closePopForDiff();
		writeSelectionLogWithExp("BUTTON:"+getButtonName(e), (Component)e.getSource());	                
				panelBack();
            }
			*/

			


			if(e.getSource() == panelCaptureButton)
			{
				visualization.imageCapture();
                StoryControl.nextSerif(3004);
			}
			
			if(e.getSource() == displayReadmeButton)
            {
				displayReadme();
                StoryControl.nextSerif(3005);
                if(text.control.popForSupport != null)
                    text.control.popForSupport.support.setAnsweredFlagTrue(0,15);//1.0
            }
            
            if(e.getSource() == characterTutorialButton)
            {
                String mode[] = {"SL2","L2","N2","A2"};
                int number=-1;                ///////NUMBER ASSIGN
                int buttonCheck=-1;                ///////NUMBER ASSIGN
                
                StoryControl storyControl = new StoryControl(text.control);
                StoryControl.countSubMissionNumber();
                
                text.control.btd2.doClick();
                if(text.control.btd3.isSelected() == true)
                    text.control.btd3.doClick();
                
                for(int i=0;i<4;i++)
                {
                    int j;
                    for(j=0;j<StoryControl.moduleTutorialCount[i];j++)
                    {
                        String name[];
                        if(text.control.sp1.isWindows)
                            name = StoryControl.moduleTutorialFilename[i][j].split("\\\\");
                        else
                            name = StoryControl.moduleTutorialFilename[i][j].split(File.separator);
                        
                        if(name[name.length-1].equals(myModuleName+"Tutorial.txt"))
                        {
                            number = i;
                            buttonCheck = j;
                            break;
                        }
                    }
                    if(j < StoryControl.moduleTutorialCount[i])
                        break;
                }
                
                if(number == -1 || buttonCheck == -1)
                    return;
                
                number = number*3+2;                
                
                storyControl = new StoryControl(text.control, mode[(int)(number/3)], number, buttonCheck+1);
                
                text.control.last_original_file = text.sourceFilename.substring(0, text.sourceFilename.length()-1);
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>BACKUP CURRENT TEXT = "+text.control.last_original_file);
                
                text.control.autoTextLoading(text.control.absolutePath+File.separator+"text"+File.separator+"urashima.txt");
                text.control.panelSet(defaultSetPanelModuleID, defaultSetPanelVisualizationID, defaultSetPanelTextID, defaultBalancedPanelSizeX);
                
                StoryControl.fromModule = true;
                storyControl.SerifControl(0, true);
                
                text.control.characterTutorial = 2;
                text.control.setCharacterTutorialButton();
                
                StoryControl.nextSerif(3008);
            }
            
			
//			if(e.getSource() == panelLoadButton)
//				panelLoad();

//			if(e.getSource() == panelRecordButton)
//				panelRecord();
			
            /*
			if(e.getSource() == partialSegments1)
				setPartialSegments(0);
			
			if(e.getSource() == partialSegments2)
				setPartialSegments(1);
			
			if(e.getSource() == partialSentences1)
				setPartialSentences(0);
			
			if(e.getSource() == partialSentences2)
				setPartialSentences(1);
             */
            
            if(e.getSource() == partialDocument)
            {
                setPartialDocument();
                StoryControl.nextSerif(3006);
            }
			
            if(e.getSource() == displayDiffButton)
            {
                if(!displayDiffButton.isSelected())
				{
                    closePopForDiff();
				}
                else
                {
                    panelSetForDiff(1,3);//seg1, seg2
                    StoryControl.nextSerif(3007);
                }
            }
			

		}
		
        final void displayDiff()
		{
			
			if(displayDiffButton.isSelected())
			{
				String windowTitle = "Data Comparison";
				if(text.control.sp1.inJapanese)
					windowTitle = text.control.windowNameInJapanese[10];				
				
				Point position = getLocationOnScreen();
				popForDiff = new PopUpForDiff((int)position.getX(), (int)position.getY()+35, 600, 400, visualization.dataNumbers, diffPatterns, mining, panelID, windowTitle);
				popForDiff.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			}
			else
			{
                closePopForDiff();
			}
        }		
		
		//PANEL SET
		final void defaultSetPanel()
		{
			defaultSetPanelModuleID= new int[pairingVisualizationID.length];
			defaultSetPanelVisualizationID = new int[pairingVisualizationID.length];
			defaultSetPanelTextID = new int[pairingVisualizationID.length];
            defaultBalancedPanelSizeX = new int[pairingVisualizationID.length];

			for(int i=0;i<pairingVisualizationID.length;i++)
			{
				defaultSetPanelModuleID[i] = moduleID;
				defaultSetPanelVisualizationID[i] = pairingVisualizationID[i];
				defaultSetPanelTextID[i] = 0;
                defaultBalancedPanelSizeX[i] = 1;
			}
		}
		
		final void defaultSetPanelTextID()
		{
			defaultSetPanelTextID = new int[defaultSetPanelModuleID.length];
			
			for(int i=0;i<defaultSetPanelModuleID.length;i++)
				defaultSetPanelTextID[i] = 0;
		}
        
        final void defaultBalancedPanelSizeX()
        {
            defaultBalancedPanelSizeX = new int[defaultSetPanelModuleID.length];
            
            for(int i=0;i<defaultBalancedPanelSizeX.length;i++)
                defaultBalancedPanelSizeX[i] = 1;
        }
		
		final void recPanelConstitution(int MID[], int VID[], int TID[], int sizeX[])
		{
			//MID = new int[text.control.panelNumber];
			//	VID = new int[text.control.panelNumber];
			for(int i=0;i<text.control.panelNumber;i++)
			{
				MID[i] = text.control.moduleData.msub.selectedMiningIDs[text.control.panel[i].selected_module];
				VID[i] = text.control.moduleData.msub.selectedVisualizationIDs[text.control.panel[i].pair_visu[text.control.panel[i].selected_module]];
				TID[i] = text.control.panel[i].mining[text.control.panel[i].selected_module].text.textID;
				sizeX[i] = text.control.balancedPanelSizeX[i];
			}
		}
		
        public final void panelSetDefault()
        {
            lastSetPanelModuleID = new int[text.control.panelNumber];
            lastSetPanelVisualizationID = new int[text.control.panelNumber];
            lastSetPanelTextID = new int[text.control.panelNumber];
            lastBalancedPanelSizeX = new int[text.control.panelNumber];
            
            recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
            
            text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
            
            text.control.panelSet(defaultSetPanelModuleID, defaultSetPanelVisualizationID, defaultSetPanelTextID, defaultBalancedPanelSizeX);
        }
        
		final void panelSet()
		{
			panelSetBasic();
//			additionalPanelSet();
		}
		
		final void panelSetBasic()
		{
            /*
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastSetPanelTextID = new int[text.control.panelNumber];			
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
			*/
			int setPanelTextID[] = new int[defaultSetPanelModuleID.length];
			for(int i=0;i<defaultSetPanelModuleID.length;i++)
				setPanelTextID[i] = text.textID;
			
			text.control.panelSetWithKeep(panelID, defaultSetPanelModuleID, defaultSetPanelVisualizationID, setPanelTextID, defaultBalancedPanelSizeX);
		}
		
		final void panelSetFromModule(int moduleIDs[], int displayIDs[])
		{
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastSetPanelTextID = new int[text.control.panelNumber];			
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
			
			text.control.panelSetFromModule(panelID, moduleIDs, displayIDs);
		}		
		
		final void panelSetFromModule(int moduleIDs[], int displayIDs[], int sizeX[])
		{
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastSetPanelTextID = new int[text.control.panelNumber];			
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
			
			text.control.panelSetFromModule(panelID, moduleIDs, displayIDs, sizeX);
		}		
		
		final void panelSetForDiff(int text1ID, int text2ID)
		{
            closePopForDiff();
            
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastSetPanelTextID = new int[text.control.panelNumber];
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
            
            int mIDs[] = new int[3];
            int vIDs[] = new int[3];
            int tIDs[] = new int[3];
            int sizeX[] = {1,1,1};
            for(int i=0;i<3;i++)
            {
                mIDs[i] = moduleID;
                vIDs[i] = visualization.getModuleID();
            }
            

            
            int IDtoIndex[] = {1,2,4,3,5};
            
            // 1:ALL, 2:SEG1, 3:SEG2, 4:SEN1, 5:SEN2        //-1:---,0:---,1:ALL,2:SEG1,3:SEG2,4:SEN1,5:SEN2
            tIDs[0] = text1ID;//1
            tIDs[1] = text2ID;//3
            tIDs[2] = -1 * (IDtoIndex[text1ID]*10 + IDtoIndex[text2ID]);
            
            System.out.println("SET TEXTID "+text1ID+"-"+text2ID+":"+tIDs[2]);
			
			text.control.panelSetWithKeep(panelID, mIDs, vIDs, tIDs, sizeX);
		}
		
		final void panelDelete()
		{
			text.control.delete(panelID);
		}
		
		final void panelKeep()
		{
			keep = panelKeepButton.isSelected();
		}
		
        public void closePopForMining()//README
        {
            if(popForMining != null)
            {
                popForMining.dispose();
                popForMining = null;
            }
        }
        
        public void closePopForVisualization()//README
        {
            if(popForVisualization != null)
            {
                popForVisualization.dispose();
                popForVisualization = null;
            }
        }
        
		final void displayReadme()
		{
			if(displayReadmeButton.isSelected())
			{
				Point position = getLocationOnScreen();

				String readmeTextForMining = text.control.moduleData.miningReadmeText[text.control.moduleData.findModule(moduleID)];				
				String japaneseMiningName = text.control.moduleData.miningModuleNamesInJapanese[text.control.moduleData.findModule(moduleID)];

				String readmeTextForVisualization = text.control.moduleData.visualizationReadmeText[text.control.moduleData.findVisualizationModule(visualization.getModuleID())];			
				String japaneseVisualizationName = text.control.moduleData.visualizationModuleNamesInJapanese[text.control.moduleData.findVisualizationModule(visualization.getModuleID())];			

				String windowTitle = "Explanation of Mining Tool";
				if(text.control.sp1.inJapanese)
					windowTitle = text.control.windowNameInJapanese[11];				
				
				popForMining = new PopUpWindow(japaneseMiningName+"("+myModuleName+"(ID="+moduleID+"))"+buttonNamesInJapanese[10],
											   readmeTextForMining, (int)position.getX(), (int)position.getY()+35, 600, 400, getFontSize(), new Color(0xff,0xf0,0xf5), text.getFontName(), text.control, panelID, 1, windowTitle);
				popForMining.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				
				windowTitle = "Explanation of Visualization Tool";
				if(text.control.sp1.inJapanese)
					windowTitle = text.control.windowNameInJapanese[12];
				
				popForVisualization = new PopUpWindow(japaneseVisualizationName+"("+visuModuleName+"(ID="+visualization.getModuleID()+"))"+buttonNamesInJapanese[10], 
													  readmeTextForVisualization, (int)position.getX(), (int)position.getY()+435, 600, 400, getFontSize(), new Color(0xe0,0xff,0xff), text.getFontName(), text.control, panelID, 2, windowTitle);
				popForVisualization.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			}
			else
			{
                closePopForMining();
                closePopForVisualization();
			}
		}
		
		final void panelLoad()
		{
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastSetPanelTextID = new int[text.control.panelNumber];			
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastSetPanelTextID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
			
			//		if(text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].panelRecorded)
			text.control.panelSetByMiningModule(moduleID);
			//		else
			//	text.control.panelSet(defaultSetPanelModuleID, defaultSetPanelVisualizationID);

		}		
		
		final void panelBack()
		{
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].panelBack = false;
			panelBackButton.setEnabled(false);
			
			text.control.backPanelSetByMiningModule(moduleID);
		}
        
        public void resetModuleForPartialData()
        {
			TextData originalTextData = text.control.text;            
            
            text.control.stealthPanel.resetFirstTime_for_stealth();
            
            for(int i=0;i<visuModuleNumber;i++)
                visual[i].firstTime = true;
            
            resetFirstTime();
            selected(originalTextData);
            text.control.panel[panelID].setTitle2();            
        }
        

        
        
		//////NEW FOR PARTIAL
        
		final void panelSetFocusSegments(int number)
		{
			TextData originalTextData = text.control.text;
			
			originalTextData.setSegmentPartialTextData(number);
			text.control.panel[panelID].setTitle2();
		}
		
		final void panelSetFocusSentences(int number)
		{
			TextData originalTextData = text.control.text;
			
			originalTextData.setSentencePartialTextData(number);
			text.control.panel[panelID].setTitle2();
		}
		
		final void setPartialDocument()
		{
            if(cancelPartialDocument == true)
            {
                System.out.println("Canceled selected partial document because of the module setting.");
                autoSet = true;
                partialDocument.setSelectedIndex(0);
                autoSet = false;
                return;
            }
            
			TextData originalTextData = text.control.text;
			
			partialDocumentA = partialDocument.getSelectedIndex();//-1:---,0:---,1:ALL,2:SEG1,3:SEG2,4:SEN1,5:SEN2
            if(partialDocumentA == 0)
                partialDocumentA = -1;
			
			System.out.println("Selected partial = "+partialDocumentA);
			
            text.control.panel[panelID].setTitle2();
            
			if(!autoSet)
                resetModuleForPartialData();
		}

		boolean compare(int a[], int b[])
		{
		    if(a.length != b.length)
				return false;
		    for(int i=0;i<a.length;i++)
				if(a[i] != b[i])
					return false;
		    return true;
		}		
		
		final void panelRecord()
		{
			setPanelModuleID = new int[text.control.panelNumber];
			setPanelVisualizationID = new int[text.control.panelNumber];
			setPanelTextID = new int[text.control.panelNumber];			
			setBalancedPanelSizeX = new int[text.control.panelNumber];

			recPanelConstitution(setPanelModuleID, setPanelVisualizationID, setPanelTextID, setBalancedPanelSizeX);
			
			if(compare(setPanelModuleID, defaultSetPanelModuleID) && compare(setPanelVisualizationID, defaultSetPanelVisualizationID))
			{
				text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].panelRecorded = false;
				panelLoadButton.setEnabled(false);
				return;
			}
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setPanelData(setPanelModuleID, setPanelVisualizationID, setPanelTextID, setBalancedPanelSizeX);
			panelLoadButton.setEnabled(true);
		}		
	}
	
}
