//
// Mining module for TETDM 
// SentenceInformation.java Version 0.39
// Copyright(C) 2015 WATARU SUNAYAMA All RIGHTS RESERVED.
// This program is provided under the license.
// You Should read the README file.
//

package module.MiningModules.SentenceInformation;

import module.MiningModules.WordInformation.ShrinkPanel;
import module.MiningModules.WordInformation.OsusumePanel;

import source.*;
import source.TextData.*;

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

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


public class SentenceInformation extends MiningModule implements ActionListener
{
	String columnNames[];
	String dataNames[];
	
	double data[][];
	
	JToggleButton tButton[];
    int buttonNumber;
	ButtonGroup buttonGroup;	

    
    ShrinkPanel shrinkPanel;
    OsusumePanel osusumePanel;
    JPanel lowerPanel;
    
    
	public SentenceInformation()
    {
		setModuleID(37);
		setCategoryID(3);
		setUseMode(2);
		pairingVisualizationID = new int[]{24,4};
		setToolType(3);	
	}

	public void initializePanel()
	{
		String names[] = {"Sen.No","Length","Word","Keyword","Kind of Keyword"};
		
		if(isMenuInJapanese())
			columnNames = inJapanese;
		else
			columnNames = names;
		
		operationPanel.setBackground(Color.RED);		
        buttonNumber = columnNames.length-1;     
	    tButton = new JToggleButton[buttonNumber];		
        operationPanel.setLayout(new GridLayout(1,buttonNumber));
		
		buttonGroup = new ButtonGroup();
		
	    for(int i=0;i<buttonNumber;i++)
		{
		    tButton[i] = new JToggleButton(columnNames[i+1]);
			tButton[i].setBackground(Color.red);
		    tButton[i].addActionListener(this);			
		    operationPanel.add(tButton[i]);
			buttonGroup.add(tButton[i]);
		}
        ///////DATA SHRINK///////
        
        lowerPanel = new JPanel();
        lowerPanel.setLayout(new GridLayout(2,1));
        
        shrinkPanel = new ShrinkPanel(columnNames,1,buttonNumber+1, this, isMenuInJapanese(), text.control.absolutePath);
        lowerPanel.add(shrinkPanel);
        osusumePanel = new OsusumePanel(columnNames,1,buttonNumber+1, this, isMenuInJapanese(), text.control.absolutePath);
        lowerPanel.add(osusumePanel);
        
        add(lowerPanel, BorderLayout.SOUTH);
	}
	
	public void initializeData(){}
	
	public void miningOperations(int optionNumber)
	{
		switch(optionNumber)
		{               
			case 0:
				createSentenceData();
                shrinkPanel.initializeData(data,0);
                osusumePanel.initializeData(data,0);
				break;
		}
	}
	
	public void createSentenceData()
	{		
		dataNames = new String[text.sentenceNumber];
		for(int i=0;i<text.sentenceNumber;i++)
			dataNames[i] = "("+(text.sentence[i].sentenceID+1+")");
		
		data = new double[columnNames.length][dataNames.length];
		
		for(int i=0;i<dataNames.length;i++)
		{
			data[0][i] = text.sentence[i].sentenceText.trim().length();
			data[1][i] = text.sentence[i].wordNumber;
			data[2][i] = text.sentence[i].keywordNumber;
			data[3][i] = text.sentence[i].kindKeywordNumber;
			
		}		
		
		setDataStringArray(0, columnNames);
		setDataStringArray(1, dataNames);
		setDataDoubleArray2(0, data);
		setDataInteger(0,2);// Sentence focus
	}
	
	public void actionPerformed(ActionEvent e)
	{
		writeButtonLog(e);/////NEW LOG
		
		for(int i=0;i<buttonNumber;i++)
			if(e.getSource() == tButton[i])
			{
				setDataDoubleArray(0, data[i]);
				displayOperations(0);	//save text and re-calculation in all modules
			}
	}	
}


