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

package source;

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

import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.GroupLayout.Alignment;


public class SettingPanel extends JPanel implements ActionListener, ItemListener
{
	JPanel allTopPanel;
	JPanel topPanel1;
	JPanel topPanel2;	
	JPanel leftTopPanel;
	JPanel rightTopPanel;
	
	JPanel upperPanel;	
	JPanel leftPanel;
	JPanel rightPanel;	

	JPanel buttonPanel;
	JPanel buttonPanel1;
	JPanel buttonPanel2;	
	
	
	//Top
	JLabel message;
	JLabel keywordSettingLabel = new JLabel();	
	JLabel moduleSelectLabel = new JLabel();
	
	//Text pane	for left	
	JTextPane textBox[];
	JScrollPane scroll[];
	String displayText[];	//display text
	
	JPanel setPanel;
	JLabel setFieldLabel;
	JTextField setField;
	JCheckBox setBox[];
	ButtonGroup checkGroup;
	
	//Module Selection	
	JPanel instructionPanel;
	JLabel instruction1;
	JLabel instruction2;
	JLabel instruction3;	
	
	JPanel boxPanel;	
	JPanel miningSelect, visualizationSelect;

	GroupLayout layout1, layout2;
	GroupLayout.SequentialGroup vGroup1, vGroup2;
	GroupLayout.SequentialGroup hGroup1, hGroup2;
	
	GroupLayout.ParallelGroup checkBoxGroup1, checkBoxGroup2, checkBoxGroup3;
	GroupLayout.ParallelGroup radioButtonGroup;

	GroupLayout.ParallelGroup resetButtonGroup;	
	JButton resetButton[];

	JScrollPane miningScroll, visualizationScroll;
	JCheckBox miningBox[], visualizationBox[];
	JRadioButton miningBox2[];
	ButtonGroup group = new ButtonGroup();
	JCheckBox visualizationBox2[];
	int selectedModuleNumber = 0;
	
	//Buttom
	JButton bt0 = new JButton();	
	JButton bt10 = new JButton();
	
	JToggleButton bt20 = new JToggleButton();
	JToggleButton bt30 = new JToggleButton();
	
	
	int fontsize = 16;
	
	String menuInJapanese[];
	
	SettingData settingData;
	ModuleData moduleData;
	
	boolean autoSet;
	
	boolean isChanged;
	boolean textReset;

	SettingPanel(SettingData settingD)
	{
		setLayout(new BorderLayout());
		
		settingData = settingD;
		moduleData = settingD.moduleData;
		
		menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(settingData.absolutePath + "source" + File.separator + "Japanese.txt"));		
		
		//ALL
		allTopPanel = new JPanel(new GridLayout(2,1));
		topPanel1 = new JPanel();
		topPanel2 = new JPanel(new GridLayout(1,2));		
		leftTopPanel = new JPanel();
		rightTopPanel = new JPanel();
		
		
		//TOP		
		topPanel1.setBackground(Color.green);
		leftTopPanel.setBackground(Color.orange);
		rightTopPanel.setBackground(Color.orange);
		
		add(allTopPanel, BorderLayout.NORTH);
		allTopPanel.add(topPanel1);
		allTopPanel.add(topPanel2);
		topPanel2.add(leftTopPanel);
		topPanel2.add(rightTopPanel);

		message = new JLabel();
		message.setFont(new Font("Dialog", Font.BOLD, fontsize+4));
		message.setForeground(Color.blue);

		keywordSettingLabel = new JLabel();
		keywordSettingLabel.setFont(new Font("Dialog", Font.BOLD, fontsize));
		moduleSelectLabel = new JLabel();
		moduleSelectLabel.setFont(new Font("Dialog", Font.BOLD, fontsize));		
		
		setTitleNames();



		topPanel1.add(message);
		leftTopPanel.add(keywordSettingLabel);
		rightTopPanel.add(moduleSelectLabel);
		

		//MIDDLE
		upperPanel = new JPanel(new GridLayout(1,2));
		leftPanel = new JPanel();		
		leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));	
		rightPanel = new JPanel(new BorderLayout());

		add(upperPanel);
		upperPanel.add(leftPanel);
		upperPanel.add(rightPanel);
		
		
		
		//MIDDLE Left
		textBox = new JTextPane[5];
		scroll = new JScrollPane[6];
		
		for(int i=0;i<5;i++)
		{
			textBox[i] = new JTextPane();
			scroll[i] = new JScrollPane(textBox[i]);
			leftPanel.add(scroll[i]);
		}
		displayText = new String[5];
		
		for(int i=0;i<5;i++)
			displayText[i] = "Nothing";

		setPanel = new JPanel();
		setPanel.setBackground(Color.white);
		setPanel.setLayout(new BoxLayout(setPanel, BoxLayout.Y_AXIS));		
		createSetPanel();
		scroll[5] = new JScrollPane(setPanel);
		leftPanel.add(scroll[5]);

		
		//MIDDLE Right
		instruction1 = new JLabel();
		instruction2 = new JLabel();
		instruction3 = new JLabel();
		instruction1.setFont(new Font("Dialog", Font.BOLD, fontsize-4));
		instruction2.setFont(new Font("Dialog", Font.BOLD, fontsize-4));
		instruction3.setFont(new Font("Dialog", Font.BOLD, fontsize-4));
		
		setInstructions();
		
		instructionPanel = new JPanel(new GridLayout(3,1));
		instructionPanel.setBackground(new Color(0xE0,0xFF,0xFF));
		rightPanel.add(instructionPanel, BorderLayout.NORTH);
		instructionPanel.add(instruction1);
		instructionPanel.add(instruction2);
		instructionPanel.add(instruction3);

		createModuleSelectPanel();
		
		initializeCheckBox();
		initializeCheckBox2();	
		
		initializeSetBox();
		

		//BOTTOM
		buttonPanel = new JPanel(new GridLayout(2,1));
		add(buttonPanel, BorderLayout.SOUTH);
		
		buttonPanel1 = new JPanel(new GridLayout());
		buttonPanel2 = new JPanel(new GridLayout());
				
		buttonPanel.add(buttonPanel2);		
		buttonPanel.add(buttonPanel1);

		buttonPanel2.setBackground(Color.orange);		
		buttonPanel1.setBackground(Color.green);

		
		bt0.addActionListener(this);
		bt0.setBackground(Color.GREEN);		
		buttonPanel1.add(bt0);		
		
		bt10.addActionListener(this);
		bt10.setBackground(Color.GREEN);		
		buttonPanel1.add(bt10);		
		
		bt30.addItemListener(this);
		bt30.setBackground(Color.ORANGE);		
		buttonPanel2.add(bt30);

		bt20.addItemListener(this);
		bt20.setBackground(Color.ORANGE);		
		buttonPanel2.add(bt20);		
	}
	
	public void createSetPanel()
	{
		setBox = new JCheckBox[9];
		checkGroup = new ButtonGroup();
		
		setFieldLabel = new JLabel();
		setFieldLabel.setFont(new Font("Dialog", Font.BOLD, fontsize));
		setPanel.add(setFieldLabel);
		setField = new JTextField(settingData.chasenPath, 1);
		setField.setFont(new Font("Dialog", Font.BOLD, fontsize));
//		setField.setPreferredSize(new Dimension(500, 20));
		setField.addActionListener(this);
		setPanel.add(setField);
		setField.setEnabled(!settingData.isWindows);
		
		for(int i=0;i<9;i++)
		{
			setBox[i] = new JCheckBox();
			setBox[i].addItemListener(this);
			setBox[i].setBackground(Color.white);
			setPanel.add(setBox[i]);
		}
		checkGroup.add(setBox[3]);
		checkGroup.add(setBox[4]);
		
		setNames();
	}
	
	public void setTitleNames()
	{
		if(settingData.inJapanese)
		{
			message.setText(menuInJapanese[0]);
			moduleSelectLabel.setText(menuInJapanese[13]);			
			keywordSettingLabel.setText(menuInJapanese[18]);			
		}
		else
		{
			message.setText("SETTINGS (Please push the SETTINGS button after you customized)");
			moduleSelectLabel.setText("Mining Tools -- Visualization Tools");			
			keywordSettingLabel.setText("TextData Creation Settings");
		}		
	}
	
	public void setInstructions()
	{
		if(settingData.inJapanese)
		{
			instruction1.setText(menuInJapanese[19]);
			instruction2.setText(menuInJapanese[20]);
			instruction3.setText(menuInJapanese[21]);
		}
		else
		{	
			instruction1.setText("  Mining Tool: Please check square boxes which you use");
			instruction2.setText("  Visualization Tool: Please check square boxes which you use");
			instruction3.setText("    after you checked a round button placed at right side of mining tools");		
		}		
	}
	
	public void setNames()
	{
		String setWords[] = {"Windows","English","ChaSen Execution","SJIS (Code of ChaSen and InputText)","EUC (Code of ChaSen and InputText)", 
			"Exclude HIRAGANA words", "Exclude KATAKANA words", "Exclude One character words","Menu in Japanese"};
		
		if(settingData.inJapanese)
		{
			setFieldLabel.setText(menuInJapanese[3]);
			for(int i=0;i<9;i++)
				setBox[i].setText(menuInJapanese[4+i]);

			bt0.setText(menuInJapanese[14]);	
			bt10.setText(menuInJapanese[15]);
			bt20.setText(menuInJapanese[16]);
			bt30.setText(menuInJapanese[17]);
		}
		else
		{
			setFieldLabel.setText("ChaSen PATH (Except for Windows) Please PUSH Return key after modification");
			for(int i=0;i<9;i++)
				setBox[i].setText(setWords[i]);

			bt0.setText("Load Original Settings");	
			bt10.setText("Save Settings");
			bt20.setText("Reconstruct Panels");
			bt30.setText("Reset TextData");
		}
	}
	
	public void initializeSetBox()
	{
		setField.setText(settingData.chasenPath);
		
		for(int i=0;i<9;i++)
			setBox[i].setFont(new Font("Dialog", Font.BOLD, fontsize));
		
		setBox[0].setSelected(settingData.isWindows);
		setBox[0].setEnabled(false);
		setBox[1].setSelected(settingData.isEnglish);
		setBox[1].setEnabled(false);		
		setBox[2].setSelected(settingData.chasenexe);
		setBox[2].setEnabled(false);			
		setBox[3].setSelected(settingData.defaultCode.equals("SJIS"));
		setBox[3].setEnabled(false);		
		setBox[4].setSelected(settingData.defaultCode.equals("EUC-JP"));
		setBox[4].setEnabled(false);		
		setBox[5].setSelected(settingData.excludeHiragana);
		setBox[6].setSelected(settingData.excludeKatakana);
		setBox[7].setSelected(settingData.excludeOne);
		setBox[8].setSelected(settingData.inJapanese);
	}
	
	public void createModuleSelectPanel()
	{


		
		boxPanel = new JPanel();
		boxPanel.setLayout(new GridLayout(1,2));
		//		boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.X_AXIS));
		
//		rightPanel.add(headerPanel, BorderLayout.NORTH);
		rightPanel.add(boxPanel);

		miningSelect = new JPanel();
		miningSelect.setBackground(Color.pink);
		layout1 = new GroupLayout(miningSelect);
		miningSelect.setLayout(layout1);
		vGroup1 = layout1.createSequentialGroup();
		hGroup1 = layout1.createSequentialGroup();
        checkBoxGroup1 = layout1.createParallelGroup();
        radioButtonGroup = layout1.createParallelGroup();
		resetButtonGroup = layout1.createParallelGroup();

		visualizationSelect = new JPanel();
		visualizationSelect.setBackground(Color.cyan);
		layout2 = new GroupLayout(visualizationSelect);
		visualizationSelect.setLayout(layout2);
		vGroup2 = layout2.createSequentialGroup();
		hGroup2 = layout2.createSequentialGroup();
        checkBoxGroup2 = layout2.createParallelGroup();
        checkBoxGroup3 = layout2.createParallelGroup();

		miningScroll = new JScrollPane(miningSelect);		
		visualizationScroll = new JScrollPane(visualizationSelect);
		boxPanel.add(miningScroll);
		boxPanel.add(visualizationScroll);

		miningBox = new JCheckBox[moduleData.module_names.length];
		miningBox2 = new JRadioButton[moduleData.module_names.length];

		resetButton = new JButton[moduleData.module_names.length];		
		
		visualizationBox2 = new JCheckBox[moduleData.visu_module_names.length];
		visualizationBox = new JCheckBox[moduleData.visu_module_names.length];

		createCheckBox1();
		
		layout1.setVerticalGroup(vGroup1);
		layout1.setHorizontalGroup(hGroup1);
		layout2.setVerticalGroup(vGroup2);
		layout2.setHorizontalGroup(hGroup2);		
		
		createCheckBox2();

		for(int i=0;i<moduleData.module_names.length;i++)
			group.add(miningBox2[i]);
		
		for(int i=0;i<moduleData.visu_module_names.length;i++)
			visualizationBox[i].setEnabled(false);		
	}
	
	public void setCheckBoxNames1()
	{
		for(int i=0; i<moduleData.module_names.length;i++)
			if(settingData.inJapanese)
			{
				miningBox[i].setText(moduleData.miningModuleNamesInJapanese[i]+"("+moduleData.moduleIDs[i]+")");
				resetButton[i].setText(menuInJapanese[22]);				
			}
			else
			{
				miningBox[i].setText(moduleData.module_names[i]+"("+moduleData.moduleIDs[i]+")");
				resetButton[i].setText("Reset");
			}
	}
	
	public void createCheckBox1()
	{	
		for(int i=0; i<moduleData.module_names.length;i++)
		{
			miningBox[i] = new JCheckBox();			
			miningBox[i].setFont(new Font("Dialog", Font.BOLD, fontsize));
			miningBox[i].setBackground(Color.pink);
			miningBox[i].addItemListener(this);
			
			miningBox2[i] = new JRadioButton();
			miningBox2[i].setFont(new Font("Dialog", Font.BOLD, fontsize));
			miningBox2[i].setBackground(Color.pink);
			miningBox2[i].addItemListener(this);
			
			resetButton[i] = new JButton();
			resetButton[i].setBackground(Color.pink);
			resetButton[i].addActionListener(this);

			GroupLayout.ParallelGroup group = layout1.createParallelGroup(Alignment.BASELINE);			
			group.addComponent(miningBox[i]);
			group.addComponent(miningBox2[i]);
			group.addComponent(resetButton[i]);			
			vGroup1.addGroup(group);			
			
			checkBoxGroup1.addComponent(miningBox[i]);
			radioButtonGroup.addComponent(miningBox2[i]);
			resetButtonGroup.addComponent(resetButton[i]);
		}		

		
		hGroup1.addGroup(checkBoxGroup1);
		hGroup1.addGroup(radioButtonGroup);
		hGroup1.addGroup(resetButtonGroup);

		setCheckBoxNames1();
	}	
	
	public void setCheckBoxNames2()
	{
		for(int i=0; i<moduleData.visu_module_names.length;i++)
			if(settingData.inJapanese)
				visualizationBox2[i].setText(moduleData.visualizationModuleNamesInJapanese[i]+"("+moduleData.visuModuleIDs[i]+")");
			else
				visualizationBox2[i].setText(moduleData.visu_module_names[i]+"("+moduleData.visuModuleIDs[i]+")");				
	}	
	
	public void createCheckBox2()
	{
		for(int i=0; i<moduleData.visu_module_names.length;i++)
		{
			//			visualizationBox2[i] = new JCheckBox(moduleData.visu_module_names[i]);
			visualizationBox2[i] = new JCheckBox();
			visualizationBox2[i].setFont(new Font("Dialog", Font.BOLD, fontsize));
			visualizationBox2[i].setBackground(Color.cyan);
			visualizationBox2[i].addItemListener(this);
			
			visualizationBox[i] = new JCheckBox();
			visualizationBox[i].setBackground(Color.cyan);
			visualizationBox[i].setFont(new Font("Dialog", Font.BOLD, fontsize));
			
			GroupLayout.ParallelGroup group = layout2.createParallelGroup(Alignment.BASELINE);			
			group.addComponent(visualizationBox2[i]);
			group.addComponent(visualizationBox[i]);
			vGroup2.addGroup(group);
			
			checkBoxGroup2.addComponent(visualizationBox2[i]);
			checkBoxGroup3.addComponent(visualizationBox[i]);		
		}
		
		hGroup2.addGroup(checkBoxGroup2);
		hGroup2.addGroup(checkBoxGroup3);
		
		setCheckBoxNames2();		
	}

	public void initializeCheckBox()
	{		
		for(int i=0;i<moduleData.module_names.length;i++)
			miningBox[i].setSelected(moduleData.miningModuleSelection[i]);
	}	
	
	public void setCheckBox2AndResetButton(int n)
	{
		miningBox2[n].setSelected(true);
		resetButton[n].setEnabled(true);
		
		for(int i=0;i<moduleData.module_names.length;i++)
			if(i != n)
			{
				miningBox2[i].setSelected(false);
				resetButton[i].setEnabled(false);
			}
	}
	
	public void initializeCheckBox2()
	{
		for(int i=0;i<moduleData.module_names.length;i++)
			if(miningBox[i].isSelected())
			{
				setCheckBox2AndResetButton(i);
				break;
			}
		
		setVisualizationCheckBox();	//for 2
	}	
	
	//for 2
	public void setVisualizationCheckBox()
	{
		autoSet = true;
		for(int j=0;j<moduleData.visu_module_names.length;j++)
			visualizationBox2[j].setSelected(false);			

		for(int j=0;j<moduleData.visu_module_names.length;j++)
			for(int k=0;k<moduleData.mining[selectedModuleNumber].pairingVisualizationID.length;k++)
				if(moduleData.visuModuleIDs[j] == moduleData.mining[selectedModuleNumber].pairingVisualizationID[k])
					visualizationBox2[j].setSelected(true);
		autoSet = false;
	}
	
	void resetPairingVisualization()
	{
		moduleData.mining[selectedModuleNumber].pairingVisualizationID = new int[moduleData.mining[selectedModuleNumber].pairingVisuID.length];
		for(int i=0;i<moduleData.mining[selectedModuleNumber].pairingVisuID.length;i++)
			moduleData.mining[selectedModuleNumber].pairingVisualizationID[i] = moduleData.mining[selectedModuleNumber].pairingVisuID[i];
	}	
	
	void resetAllPairingVisualization()
	{
		for(int k=0;k<moduleData.module_names.length;k++)
		{
			moduleData.mining[k].pairingVisualizationID = new int[moduleData.mining[k].pairingVisuID.length];
			for(int i=0;i<moduleData.mining[k].pairingVisuID.length;i++)
				moduleData.mining[k].pairingVisualizationID[i] = moduleData.mining[k].pairingVisuID[i];
		}
	}	

	public void setData()
	{
		displayText[0] = settingData.guideComments[0]+"\n";
		for(int i=0;i<settingData.nouns;i++)
			displayText[0] += (settingData.kind_nouns[i]+" ");
		displayText[0] += "\n";
		
		displayText[1] = settingData.guideComments[1]+"\n";
		for(int i=0;i<settingData.verbs;i++)
			displayText[1] += (settingData.kind_verbs[i]+" ");
		displayText[1] += "\n";		
		
		displayText[2] = settingData.guideComments[2]+"\n";
		for(int i=0;i<settingData.touns;i++)
			displayText[2] += (settingData.kind_touns[i]+" ");
		displayText[2] += "\n";		
		
		displayText[3] = settingData.guideComments[3]+"\n";
		for(int i=0;i<settingData.noises;i++)
			displayText[3] += (settingData.kind_noises[i]+" ");		
		displayText[3] += "\n";		
		
		displayText[4] = settingData.guideComments[5]+"\n";
		displayText[4] += settingData.segment_tag;
		displayText[4] += "\n";
	}
	
	
	public void setDisplay()
	{
		autoSet = true;
		for(int i=0;i<5;i++)
		{
			textBox[i].setFont(new Font("Dialog", Font.BOLD, fontsize));		
			textBox[i].setText(displayText[i]);
			textBox[i].setCaretPosition(0);
		}
		autoSet = false;		
	}
	
	public void resetVisualizationSelection()
	{
		moduleData.initializeVisualiationModuleSelection();
		
		for(int j=0;j<moduleData.visu_module_names.length;j++)
			visualizationBox[j].setSelected(moduleData.visualizationModuleSelection[j]);		
	}

	//Action listener
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == setField)
		{
			settingData.chasenPath = setField.getText();
			setTextReset(true);
			return;
		}		
		
		setChanged(true);
		
		for(int i=0;i<moduleData.module_names.length;i++)
			if(e.getSource() == resetButton[i])
			{
				resetPairingVisualization();
				setVisualizationCheckBox();
				resetVisualizationSelection();
				
			}
		
		if(e.getSource() == bt0)//Load Original Settings
		{
			resetAllPairingVisualization();	
		
			settingData.readOriginalSettingFile();
			initializeCheckBox();
			initializeCheckBox2();
			resetVisualizationSelection();
			
			initializeSetBox();			
			setData();
			setDisplay();
			
				
			
			if(settingData.inJapanese)
				message.setText(menuInJapanese[1]);
			else
				message.setText("SETTINGS ARE LOADED (Please push the Settings button after you customized)");

		}
		
		if(e.getSource() == bt10)//Save Settings
		{
			settingData.saveSettingFile();
			if(settingData.inJapanese)
				message.setText(menuInJapanese[2]);
			else
				message.setText("SETTINGS ARE SAVED (Please push the Settings button after you customized)");
		}
	}
	
	public void updateTextSetting()
	{
		String text0[] = textBox[0].getText().split("\n");
		if(text0.length > 1)
		{
			settingData.kind_nouns = text0[1].split(" ");
			settingData.nouns = settingData.kind_nouns.length;
		}

		String text1[] = textBox[1].getText().split("\n");
		if(text1.length > 1)
		{
			settingData.kind_verbs = text1[1].split(" ");
			settingData.verbs = settingData.kind_verbs.length;
		}		

		String text2[] = textBox[2].getText().split("\n");
		if(text2.length > 1)
		{
			settingData.kind_touns = text2[1].split(" ");
			settingData.touns = settingData.kind_touns.length;
		}
		
		String text3[] = textBox[3].getText().split("\n");
		if(text3.length > 1)
		{
			settingData.kind_noises = text3[1].split(" ");
			settingData.noises = settingData.kind_noises.length;
		}
		
		String text4[] = textBox[4].getText().split("\n");
		if(text4.length > 1)
			settingData.segment_tag = text4[1];		
	}
	
	public void setChanged(boolean set)
	{
		isChanged = set;
		bt20.setSelected(isChanged);
	}
	
	public void setTextReset(boolean set)
	{
		textReset = set;
		bt30.setSelected(textReset);
	}	
	
	public void itemStateChanged(ItemEvent e)
	{

		
		// Reconstruct Panels
		if(e.getSource() == bt20)
		{
			if(bt20.isSelected())
				isChanged = true;
			else
				isChanged = false;
			return;
		}

		// Reset TextData
		if(e.getSource() == bt30)
		{
			if(bt30.isSelected())
			{
				textReset = true;
				updateTextSetting();
//				bt20.setSelected(true);
			}
			else
				textReset = false;
			return;
		}		
		
		
		// Settings for TextData Creation
		for(int i=0;i<setBox.length;i++)
			if(e.getSource() == setBox[i])
			{
				switch(i)
				{
					case 1: settingData.isEnglish = setBox[1].isSelected();
						break;
					case 2: settingData.chasenexe = setBox[2].isSelected();
						break;
					case 3: 
					case 4: if(setBox[3].isSelected())
								settingData.defaultCode = "SJIS";
							else 
								settingData.defaultCode = "EUC-JP";
						break;
					case 5: settingData.excludeHiragana = setBox[5].isSelected();
						break;
					case 6: settingData.excludeKatakana = setBox[6].isSelected();
						break;
					case 7: settingData.excludeOne = setBox[7].isSelected();
						break;
					case 8: settingData.inJapanese = setBox[8].isSelected();
						setCheckBoxNames1();
						setCheckBoxNames2();
						
						if(settingData.inJapanese)
							message.setText(menuInJapanese[0]);
						else
							message.setText("SETTINGS (Please push the Settings button after you customized)");						
						
						setTitleNames();
						setInstructions();
						setNames();
						
						break;
				}
				if(i == 8)
					setChanged(true);					
				else
					setTextReset(true);

				return;
			}

		
		
		for(int i=0;i<miningBox2.length;i++)//////////
			if(e.getSource() == miningBox2[i])
			{
				resetButton[selectedModuleNumber].setEnabled(false);
				resetButton[i].setEnabled(true);
				selectedModuleNumber = i;
				setVisualizationCheckBox();
				return;
			}		
	
		if(autoSet)
			return;		
		
		setChanged(true);			// Reconstruct Panels

		for(int k=0;k<miningBox.length;k++)
			if(e.getSource() == miningBox[k])
			{
				moduleData.miningModuleSelection[k] = miningBox[k].isSelected();
				
				int count=0, firstm=-1;
				for(int i=0;i<miningBox.length;i++)
					if(miningBox[i].isSelected())
					{
						if(firstm == -1)
							firstm = i;
						count++;
					}
				
				if(miningBox[k].isSelected())
					firstm = k;
				
				if(count == 0)
				{
					miningBox[k].setSelected(true);
					setCheckBox2AndResetButton(k);					
				}
				else
				{
					setCheckBox2AndResetButton(firstm);
					resetVisualizationSelection();
				}

				return;
			}	
		
		for(int i=0;i<visualizationBox2.length;i++)
			if(e.getSource() == visualizationBox2[i])
			{
				for(int k=0;k<miningBox2.length;k++)
					if(miningBox2[k].isSelected())
					{
						selectedModuleNumber = k;
						break;
					}
				
				int count=0;
				for(int k=0;k<visualizationBox2.length;k++)
					if(visualizationBox2[k].isSelected())
						count++;
				
				if(count == 0)
				{
					for(int k=0;k<visualizationBox2.length;k++)
						if(moduleData.visuModuleIDs[k] == moduleData.mining[selectedModuleNumber].pairingVisualizationID[0])
							visualizationBox2[k].setSelected(true);
					count = 1;
				}
				
				moduleData.mining[selectedModuleNumber].pairingVisualizationID = new int[count];

				count = 0;
				for(int k=0;k<visualizationBox2.length;k++)
					if(visualizationBox2[k].isSelected())
						moduleData.mining[selectedModuleNumber].pairingVisualizationID[count++] = moduleData.visuModuleIDs[k];

				resetVisualizationSelection();

				return;				
			}
	}
}
