
//
// Mining module for TETDM 
// DocumentPolish.java Version 0.30 
// This is one of the sample modules.
// You should read the README file.
//

package module.MiningModules.DocumentPolish;		

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

import java.io.*;
import java.util.*;

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

public class DocumentPolish extends MiningModule implements ActionListener
{
	String checkedText;	

	
	int buttonNumber;
	int mining[][], visual[][], size[][];
	ButtonGroup buttonGroup;	
    
	public DocumentPolish()
	{
		setModuleID(41);						// Set your module ID after you have got it
		setCategoryID(9);		
		pairingVisualizationID = new int[]{3};
        defaultSetPanelModuleID = new int[]{41,1};
        defaultSetPanelVisualizationID = new int[]{3,1};
		setToolType(1);
        setUseMode(3);
	}
	
	void panelDataCreation(int m[], int v[], int s[], int number)
	{
		mining[number] = m;
		visual[number] = v;
		size[number] = s;
	}	
	
	public void initializePanel()
    {
		buttonNumber = 6;
		
		operationPanel.setBackground(Color.GREEN);
		operationPanel.setLayout(new GridLayout(buttonNumber,1));
		
		toggleButton = new JToggleButton[buttonNumber];
		mining = new int[buttonNumber][];
		visual = new int[buttonNumber][];
		size = new int[buttonNumber][];
		
		// set0
		int m0[] = {41,19,35,23,11};
		int v0[] = {3,3,24,16,8};
		int s0[] = {1,4,4,4,4};
		
		// set1
		int m1[] = {41,6,0,0,24,0};
		int v1[] = {3,9,1005,1015,18,1013};
		int s1[] = {1,4,4,4,4,4};
		
		// set2
		int m2[] = {41,17,13};
		int v2[] = {3,3,12};
		int s2[] = {1,4,4};
		
		// set3
		int m3[] = {41,12,30,11};
		int v3[] = {3,2,2,8};
		int s3[] = {1,4,4,4};
		
		// set4
		int m4[] = {41,14,16,5,9};
		int v4[] = {3,14,3,2,2};
		int s4[] = {1,4,4,4,4};
		
		// set5
		int m5[] = {41,2,4,26};
		int v5[] = {3,3,1,3};
		int s5[] = {1,4,4,4};
		
		panelDataCreation(m0,v0,s0,0);
		panelDataCreation(m1,v1,s1,1);
		panelDataCreation(m2,v2,s2,2);
		panelDataCreation(m3,v3,s3,3);
		panelDataCreation(m4,v4,s4,4);
		panelDataCreation(m5,v5,s5,5);		

		
		String buttonNames[] = {"Construction","Paragraph Relation","Paragraph Expression","Sentence Relation","Sentence Expression","Word Expression"};
		
		if(isMenuInJapanese())
			for(int i=0;i<buttonNumber;i++)
				buttonNames[i] = inJapanese[i];
		
		buttonGroup = new ButtonGroup();		
		
		for(int i=0;i<buttonNumber;i++)
		{
			toggleButton[i] = new JToggleButton(buttonNames[i]);
			toggleButton[i].setBackground(Color.GREEN);
			toggleButton[i].addActionListener(this);
			operationPanel.add(toggleButton[i]);
			buttonGroup.add(toggleButton[i]);			
		}
		
		int focus = getMainFocusInteger();
		if(focus >= 0 && focus < buttonNumber)
			toggleButton[focus].setSelected(true);		
    }

	public void initializeData(){}
	
	public void miningOperations(int optionNumber)
	{
		switch(optionNumber)
		{
			case 0:
				checkedText = check_text();				
				resetData();
				setDataString(checkedText);				
				break;
		}
	}
	
    public String check_text()
	{
		StringWriter sw1 = new StringWriter();
		BufferedWriter bw1 = new BufferedWriter(sw1);
		
		try
		{
			//header
			bw1.write("<HTML><HEAD><TITLE>ANALYSIS</TITLE></HEAD><BODY>");
			bw1.write("<H1>"+inJapanese[6]+" ["+(new File(text.sourceFilename).getName())+"] </H1>");
			
			
			//BASIC TABLE
			bw1.write("<H1>"+inJapanese[7]+"</H1>");
			bw1.write("<TABLE BORDER=2 BORDERCOLOR=black>");
			
			bw1.write("<H3>"+inJapanese[8]+"</H3>");
			bw1.write("<TABLE BORDER=2 BORDERCOLOR=black>");			
			
			bw1.write("<TR>");
			bw1.write("<TD ALIGN=center>"+inJapanese[9]+"</TD>");
			bw1.write("</TR>");			
			
			bw1.write("<TR>");
			bw1.write("<TD ALIGN=center>"+inJapanese[10]+"</TD>");
			bw1.write("</TR>");	
			
			bw1.write("<TR>");
			bw1.write("<TD ALIGN=center>"+inJapanese[11]+"</TD>");
			bw1.write("</TR>");				
			
			bw1.write("</TABLE>");
			bw1.write("</TABLE>");			
			
			bw1.write("</BODY></HTML>");
			bw1.flush();
		}
		catch(Exception e){
			System.out.println("Error in TextSetInfoApplication");
            e.printStackTrace();            
		}
		
		return sw1.toString();
	}	
	
	//Action listener
	public void actionPerformed(ActionEvent e)
	{
		writeSelectionButtonLog(e);/////NEW LOG
		
		for(int i=0;i<buttonNumber;i++)
			if(e.getSource() == toggleButton[i])
			{
				setMainFocusInteger(i);				
				panelSetFromModule(mining[i], visual[i], size[i]);
				return;
			}
		
	}
}
