//
// Core Program for TETDM 
// MiningModule.java Version 0.44
// Copyright(C) 2011-2013 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.*;

public abstract class MiningModule extends JPanel
{
	private int moduleID = -1;
	private int panelID;
	
	private int toolType = 4;//1:simple 2:primitive 3:semi-primitive 4:special
	
	public TextData text;
	String absolutePath;
	
    SetData setData = new SetData();
	
	public String myModulePath;
	public String myModuleName;
	public String visuModulePath;
	public String visuModuleName;
	
	boolean firstTime = true;
	boolean keep = 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 setBalancedPanelSizeX[];	
	private int lastSetPanelModuleID[];
	private int lastSetPanelVisualizationID[];
	private int lastBalancedPanelSizeX[];
	public int defaultSetPanelModuleID[];
	public int defaultSetPanelVisualizationID[];


	Class<?> visuModule[];
//    	public VisualizationModule visualization;	
	private VisualizationModule visualization;
	VisualizationModule visual[];
	int visuModuleNumber;
	
	public int pairingVisualizationID[];
	 int pairingVisualizationIndex[];
	public int pairingVisuID[];		//For SettingPanel
	


	
	String buttonNamesInJapanese[];    
    
	public MiningModule(){}
	
	public final void setModuleID(int moduleID)
	{
		this.moduleID = moduleID;
	}	
	public final int getModuleID()
	{
		return moduleID;
	}		
	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 init_panel(TextData tex, Class<?> vis[], int selectedVisu, String absolute, int defaultPanelSizeX, int defaultPanelSizeY)
	{
		text = tex;
		
		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\\.","");

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

		if(panelSet)	// SET PANEL COMBINATION
		{
			combinationPanel = new CombinationPanel();
			add(combinationPanel, BorderLayout.NORTH);			
		}
		
		initializePanel();					// Step.1
		operationPanel.setBackground(Color.RED);		
		add(operationPanel, BorderLayout.SOUTH);
		
		setVisu(selectedVisu);
		
		System.out.println("Mining: "+this.getClass().getName());	
	}
	
	
	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 selected(TextData tex)
	{
		text = tex;
		
		if(combinationPanel.setFocusSegmentsButton.isSelected())	
			text = text.segmentPartialTextData;
		
		if(combinationPanel.setFocusSentencesButton.isSelected())	
			text = text.sentencePartialTextData;		
		
		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)
			visualization.firstTime = false;
		}	
	}
	
	public final void setFocusSegmentButton()
	{
		combinationPanel.setFocusSegmentsButton.setSelected(true);
	}
	public final void setFocusSentenceButton()
	{
		combinationPanel.setFocusSentencesButton.setSelected(true);
	}	
	
	//FOCUS
	public final void focusSelected(TextData tex, int operationID)
	{
		text = tex;
		initializeData();				// Step.2	Set moduleID
		visualization.focusSelected(text);		// (to Step.4)
		miningOperations(operationID);	// Step.5 case 4501, 4502
		visualization.setFont();
		displayOperations(0);				// Step.6
	}	
	
	public final void createInitialData(){}// for check only 
	public final void setInitialData(){}// for check only

	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\\.","");
	}
	
	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
	}
	
	public final void displayOperations(int optionNumber)
	{
		visualization.displayOperations(optionNumber);
	}	
	
	public final void resetFirstTime()
	{
			firstTime = true;
			visualization.firstTime = true;
	}
	
	public final void panelReset()
	{
		combinationPanel.panelReset();
		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()
	{	
		return FILEIO.TextFileAllReadCodeArray(new File(myModulePath+"Japanese.txt"));
	}
	
	public String[] fileReadArray(String filename)
	{	
		return FILEIO.TextFileAllReadCodeArray(new File(filename));
	}
	
	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);
	}

	//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);
	}	
	
	//FOCUS*
	public final void setDisplayByTouchFocus()
	{
		visualization.setDisplayByTouchFocus();
	}
	//FOCUS*
	public final void setDisplayByClickFocus()
	{
		visualization.setDisplayByClickFocus();
	}
	//FOCUS*	
	public final void setDisplayByTimingFocus()
	{
		visualization.setDisplayByTimingFocus();
	}	
	

	//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 void setDataBoolean(boolean data)
	{
		int to = setData.setDataBoolean(data,moduleID,text,visualization);
		printResult(0,to);
	}	
	public final void setDataInteger(int data)
	{
        int to = setData.setDataInteger(data,moduleID,text,visualization);
		printResult(1,to);		
	}
	public final void setDataDouble(double data)
	{
        int to = setData.setDataDouble(data,moduleID,text,visualization);
		printResult(2,to);		
	}
	public final void setDataString(String data)
	{
        int to = setData.setDataString(data,moduleID,text,visualization);
		printResult(3,to);		
	}
	public final void setDataBooleanArray(boolean data[])
	{
        int to = setData.setDataBooleanArray(data,moduleID,text,visualization);
		printResult(4,to);		
	}	
	public final void setDataIntegerArray(int data[])
	{
        int to = setData.setDataIntegerArray(data,moduleID,text,visualization);
		printResult(5,to);		
	}
	public final void setDataDoubleArray(double data[])
	{
        int to = setData.setDataDoubleArray(data,moduleID,text,visualization);
		printResult(6,to);		
	}
	public final void setDataStringArray(String data[])
	{
        int to = setData.setDataStringArray(data,moduleID,text,visualization);
		printResult(7,to);		
	}	
	public final void setDataBooleanArray2(boolean data[][])
	{
        int to = setData.setDataBooleanArray2(data,moduleID,text,visualization);
		printResult(8,to);		
	}	
	public final void setDataIntegerArray2(int data[][])
	{
        int to = setData.setDataIntegerArray2(data,moduleID,text,visualization);
		printResult(9,to);		
	}
	public final void setDataDoubleArray2(double data[][])
	{
        int to = setData.setDataDoubleArray2(data,moduleID,text,visualization);
		printResult(10,to);		
	}
    
	public final void setDataBoolean(int dataID, boolean data)
	{
        setData.setDataBoolean(dataID, data,moduleID,text,visualization);
	}
	public final void setDataInteger(int dataID, int data)
	{
        setData.setDataInteger(dataID, data,moduleID,text,visualization);
	}
	public final void setDataDouble(int dataID, double data)
	{
        setData.setDataDouble(dataID, data,moduleID,text,visualization);
	}
	public final void setDataString(int dataID, String data)
	{
        setData.setDataString(dataID, data,moduleID,text,visualization);
	}
	public final void setDataBooleanArray(int dataID, boolean data[])
	{
        setData.setDataBooleanArray(dataID, data,moduleID,text,visualization);
	}
	public final void setDataIntegerArray(int dataID, int data[])
	{
        setData.setDataIntegerArray(dataID, data,moduleID,text,visualization);
	}
	public final void setDataDoubleArray(int dataID, double data[])
	{
        setData.setDataDoubleArray(dataID, data,moduleID,text,visualization);
	}
	public final void setDataStringArray(int dataID, String data[])
	{
        setData.setDataStringArray(dataID, data,moduleID,text,visualization);
	}
	public final void setDataBooleanArray2(int dataID, boolean data[][])
	{
        setData.setDataBooleanArray2(dataID, data,moduleID,text,visualization);
	}
	public final void setDataIntegerArray2(int dataID, int data[][])
	{
        setData.setDataIntegerArray2(dataID, data,moduleID,text,visualization);
	}
	public final void setDataDoubleArray2(int dataID, double data[][])
	{
        setData.setDataDoubleArray2(dataID, data,moduleID,text,visualization);
	}

	
	//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);
	}	

	//JAPANESE
	public boolean isMenuInJapanese()
	{
		return text.settingData.inJapanese;
	}	
	
	//SAVE ACTION LOG 
    String logFilename;    
    public void writeActionLog(String data)
    {
        logFilename = absolutePath+"ACTIONLOG";
        try
        {
            BufferedWriter bw1 = new BufferedWriter(new FileWriter(logFilename, true));
			
            bw1.write(text.control.getDiffTime()+" Mining PanelID="+panelID+" "+"ModuleID="+moduleID+" "+data+System.getProperty("line.separator"));
            bw1.close();
        }
        catch(Exception e){
            System.out.println("File Writing ERROR ACTIONLOG");
        }		
    }	
	
	//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 JButton panelLoadButton;
		public JButton panelRecordButton;
		
		public JToggleButton setFocusSegmentsButton;
		public JToggleButton setFocusSentencesButton;
        
        JPanel subLabelPanel[];
        JLabel buttonLabel[];
        JPanel partial;
		
		boolean autoSet = false;
		
		CombinationPanel()
		{
			setLayout(new GridLayout());
			initializePanel();
		}
		
		void initializePanel()
		{
			if(defaultSetPanelModuleID == null)		// NOT GIVEN IN THE CONSTRUCTOR
				defaultSetPanel();		//SET DEFAULT PANEL COMBINATION
			
			String filename = absolutePath+"source"+File.separator+"JapaneseMining.txt";					
			File jpname = new File(filename);

			buttonNamesInJapanese = FILEIO.TextFileAllReadCodeArray(jpname);
			
            
            
            int labelNumber = 7;
			subLabelPanel = new JPanel[labelNumber];
            buttonLabel = new JLabel[labelNumber];
            for(int i=0;i<labelNumber;i++)
            {
                subLabelPanel[i] = new JPanel(new BorderLayout());
                if(i<4)
                    subLabelPanel[i].setBackground(Color.PINK);
//                        subLabelPanel[i].setBackground(new Color(0xff,0xda,0xb9));
                else if(i<6)
//                    subLabelPanel[i].setBackground(new Color(0xff,0xda,0xb9));
                subLabelPanel[i].setBackground(new Color(0xfb,0xef,0xf8));
//                                    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("Dialog", Font.BOLD, 10));

            }
            
            
			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]);
                
				panelDeleteButton = new JButton(buttonNamesInJapanese[0],new ImageIcon(absolutePath+"source"+File.separator+"delete.png"));
				panelBackButton = new JButton(buttonNamesInJapanese[1],new ImageIcon(absolutePath+"source"+File.separator+"back.png"));
				panelSetButton = new JButton(buttonNamesInJapanese[2],new ImageIcon(absolutePath+"source"+File.separator+"set.png"));				
				panelKeepButton = new JToggleButton(buttonNamesInJapanese[3],new ImageIcon(absolutePath+"source"+File.separator+"keep.png"));
				panelCaptureButton = new JButton(buttonNamesInJapanese[4],new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				
				panelLoadButton = new JButton(buttonNamesInJapanese[5],new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				panelRecordButton = new JButton(buttonNamesInJapanese[6],new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				
//				setFocusSegmentsButton = new JToggleButton(buttonNamesInJapanese[7],new ImageIcon(absolutePath+"source"+File.separator+"segment.png"));
//				setFocusSentencesButton = new JToggleButton(buttonNamesInJapanese[8],new ImageIcon(absolutePath+"source"+File.separator+"sentence.png"));
                
				setFocusSegmentsButton = new JToggleButton(buttonNamesInJapanese[7]);
				setFocusSentencesButton = new JToggleButton(buttonNamesInJapanese[8]);
				
				displayReadmeButton = new JToggleButton(buttonNamesInJapanese[9],new ImageIcon(absolutePath+"source"+File.separator+"readme.png"));
			}
			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");
                
				panelDeleteButton = new JButton("DELETE",new ImageIcon(absolutePath+"source"+File.separator+"delete.png"));
				panelBackButton = new JButton("BACK",new ImageIcon(absolutePath+"source"+File.separator+"back.png"));
				panelSetButton = new JButton("SET",new ImageIcon(absolutePath+"source"+File.separator+"set.png"));				
				panelKeepButton = new JToggleButton("KEEP",new ImageIcon(absolutePath+"source"+File.separator+"keep.png"));
				panelCaptureButton = new JButton("CAMERA",new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				

				panelLoadButton = new JButton("MYSET",new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				panelRecordButton = new JButton("REC",new ImageIcon(absolutePath+"source"+File.separator+"camera.png"));
				
                setFocusSegmentsButton = new JToggleButton("FocusSegments");
                setFocusSentencesButton = new JToggleButton("FocusSentences");
                
//				setFocusSegmentsButton = new JToggleButton("FocusSegments",new ImageIcon(absolutePath+"source"+File.separator+"segment.png"));
//				setFocusSentencesButton = new JToggleButton("FocusSentences",new ImageIcon(absolutePath+"source"+File.separator+"sentence.png"));
				
				displayReadmeButton = new JToggleButton("README",new ImageIcon(absolutePath+"source"+File.separator+"readme.png"));

			}
            displayReadmeButton.setSelectedIcon(new ImageIcon(absolutePath+"source"+File.separator+"close.png"));
            displayReadmeButton.setForeground(Color.blue);
            
			panelKeepButton.addActionListener(this);
			panelSetButton.addActionListener(this);
			panelBackButton.addActionListener(this);

			panelCaptureButton.addActionListener(this);
			displayReadmeButton.addActionListener(this);
			panelDeleteButton.addActionListener(this);
			
			panelLoadButton.addActionListener(this);
			panelRecordButton.addActionListener(this);
			
			setFocusSegmentsButton.addActionListener(this);
			setFocusSentencesButton.addActionListener(this);				
			
            for(int i=0;i<labelNumber;i++)
                add(subLabelPanel[i]);
            
			subLabelPanel[0].add(panelDeleteButton);
			subLabelPanel[1].add(panelKeepButton);
			subLabelPanel[2].add(panelSetButton);
			subLabelPanel[3].add(panelBackButton);
			subLabelPanel[4].add(panelCaptureButton);
			subLabelPanel[5].add(displayReadmeButton);
            
            partial = new JPanel();
            partial.setLayout(new GridLayout(1,2));
            partial.setBackground(Color.green);
            subLabelPanel[6].add(partial);

			partial.add(setFocusSegmentsButton);
			partial.add(setFocusSentencesButton);


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


			
			//add(setFocusSegmentsButton);
			//add(setFocusSentencesButton);			
			
			//			add(panelLoadButton);			
			//			add(panelRecordButton);			
			
//            setBackground(new Color(0x58,0xfa,0x82));
			setBackground(Color.green);
						
			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);			
		}
		
		//Action listener
		public void actionPerformed(ActionEvent e)
		{
			//			insideOfActionPerformed(e);	
			if(e.getSource() == panelDeleteButton)
				panelDelete();		
			
			if(e.getSource() == panelBackButton)
				panelBack();
			
			if(e.getSource() == panelSetButton)
				panelSet();			
			
			if(e.getSource() == panelKeepButton)
				panelKeep();

			if(e.getSource() == panelCaptureButton)
				visualization.imageCapture();
			
			if(e.getSource() == displayReadmeButton)
				displayReadme();
			
			if(e.getSource() == panelLoadButton)
				panelLoad();

			if(e.getSource() == panelRecordButton)
				panelRecord();
			
			if(e.getSource() == setFocusSegmentsButton)
				panelSetFocusSegments();
			
			if(e.getSource() == setFocusSentencesButton)
				panelSetFocusSentences();			
		}
		
		//PANEL SET
		final void defaultSetPanel()
		{
			defaultSetPanelModuleID= new int[pairingVisualizationID.length];
			defaultSetPanelVisualizationID = new int[pairingVisualizationID.length];			
			for(int i=0;i<pairingVisualizationID.length;i++)
			{
				defaultSetPanelModuleID[i] = moduleID;
				defaultSetPanelVisualizationID[i] = pairingVisualizationID[i];
			}
		}
		
		final void recPanelConstitution(int MID[], int VID[], 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]];
				sizeX[i] = text.control.balancedPanelSizeX[i];
			}
		}
		
		final void panelSet()
		{
			panelSetBasic();
			additionalPanelSet();
		}
		
		final void panelSetBasic()
		{
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, lastBalancedPanelSizeX);
			panelBackButton.setEnabled(true);
			
			text.control.panelSetWithKeep(panelID, defaultSetPanelModuleID, defaultSetPanelVisualizationID);
		}		
		
		final void panelDelete()
		{
			text.control.delete(panelID);
		}
		
		final void panelKeep()
		{
			keep = panelKeepButton.isSelected();
		}
		
		final void displayReadme()
		{
			if(displayReadmeButton.isSelected())
			{
				Point position = getLocationOnScreen();
//				String readmeTextForMining = fileRead(myModulePath+"README.txt");//visuModuleName visuModulePath
				String readmeTextForMining = text.control.moduleData.miningReadmeText[text.control.moduleData.findModule(moduleID)];				
//				String japaneseMiningName = fileRead(myModulePath+myModuleName+".txt");
				String japaneseMiningName = text.control.moduleData.miningModuleNamesInJapanese[text.control.moduleData.findModule(moduleID)];
//				String readmeTextForVisualization = fileRead(visuModulePath+"README.txt");//visuModuleName visuModulePath
				String readmeTextForVisualization = text.control.moduleData.visualizationReadmeText[text.control.moduleData.findVisualizationModule(visualization.getModuleID())];			
//				String japaneseVisualizationName = fileRead(visuModulePath+visuModuleName+".txt");
				String japaneseVisualizationName = text.control.moduleData.visualizationModuleNamesInJapanese[text.control.moduleData.findVisualizationModule(visualization.getModuleID())];			
				popForMining = new PopUpWindow(japaneseMiningName+"("+myModuleName+"(ID="+moduleID+"))"+buttonNamesInJapanese[10],
                    readmeTextForMining, (int)position.getX(), (int)position.getY()+35, 600, 400, text.fontSize, new Color(0xff,0xf0,0xf5));
				popForMining.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				popForVisualization = new PopUpWindow(japaneseVisualizationName+"("+visuModuleName+"(ID="+visualization.getModuleID()+"))"+buttonNamesInJapanese[10], readmeTextForVisualization, (int)position.getX(), (int)position.getY()+435, 600, 400, text.fontSize, new Color(0xe0,0xff,0xff));
				popForVisualization.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			}
			else
			{
				popForMining.dispose();
				popForVisualization.dispose();
			}			
		}
		
		final void panelLoad()
		{
			lastSetPanelModuleID = new int[text.control.panelNumber];
			lastSetPanelVisualizationID = new int[text.control.panelNumber];
			lastBalancedPanelSizeX = new int[text.control.panelNumber];
			
			recPanelConstitution(lastSetPanelModuleID, lastSetPanelVisualizationID, lastBalancedPanelSizeX);
			
			text.control.moduleData.miningPanelSet[text.control.moduleData.findModule(moduleID)].setBackPanelData(lastSetPanelModuleID, lastSetPanelVisualizationID, 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);
		}

        //FOCUS PARTIAL SEGMENTS
        public void createSegmentPartialData()
        {
            text.control.resetBySegmentPartialData();
        }
        //FOCUS PARTIAL SENTENCES        
        public void createSentencePartialData()
        {
            text.control.resetBySentencePartialData();
        }
        
        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();            
        }
        
		final void panelSetFocusSegments()
		{
			TextData originalTextData = text.control.text;            
            
			if(setFocusSegmentsButton.isSelected())
			{
				autoSet = true;
				setFocusSentencesButton.setSelected(false);
				autoSet = false;

                originalTextData.setSegmentPartialTextData();
                text.control.panel[panelID].setTitle2();
			}
			
			if(!autoSet)
                resetModuleForPartialData();
		}
		
		final void panelSetFocusSentences()
		{
			TextData originalTextData = text.control.text;            
            
			if(setFocusSentencesButton.isSelected())
			{
				autoSet = true;
				setFocusSegmentsButton.setSelected(false);
				autoSet = false;				
								
				originalTextData.setSentencePartialTextData();
                text.control.panel[panelID].setTitle2();                
			}
			
			if(!autoSet)
                resetModuleForPartialData();
		}
		
		public final void panelReset()
		{
			autoSet = true;
			setFocusSegmentsButton.setSelected(false);
			setFocusSentencesButton.setSelected(false);			
			autoSet = false;			
		}
		
		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];
			setBalancedPanelSizeX = new int[text.control.panelNumber];

			recPanelConstitution(setPanelModuleID, setPanelVisualizationID, 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, setBalancedPanelSizeX);
			panelLoadButton.setEnabled(true);
		}		
	}
	
}
