//
// Visuzalization module for TETDM 
// TextDisplay.java Version 0.36
// Copyright(C) 2011 2012 WATARU SUNAYAMA ALL RIGHTS RESERVED.
//
// This program is provided under the license.
// You should read the README file.
//

package module.VisualizationModules.TextDisplayHtml;

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

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

import java.io.*;


public class TextDisplay extends VisualizationModule implements MouseListener, MouseMotionListener, AdjustmentListener, MouseWheelListener
{
	//Text pane
	JTextPane text1;
	JScrollPane scroll1;

	//for DISPLAY
	String displayText;	//display text

    String nothing;
    String outputInJapanese;

	int fontsize;

	public TextDisplay()
	{
		setModuleID(1);
		setCategoryID(1);
		setUseMode(0);
        dataNumbers = new int[]{0,0,0,1,    // b,i,d,S
            0,0,0,0,    // bA,iA,dA,SA
            0,0,0};     // bA2,iA2,dA2
		setToolType(2);	
		
		
	}

	public void initializePanel()
	{
		text1 = new JTextPane();
		text1.setContentType("text/plain");
		scroll1 = new JScrollPane(text1);
		add(scroll1);
		scroll1.addMouseWheelListener(this);
		scroll1.getVerticalScrollBar().addAdjustmentListener(this);
		outputInJapanese = fileRead();
        
		text1.addMouseListener(this);
        text1.addMouseMotionListener(this);
	}
	
	public void initializeData()
	{
		fontsize = 14;

		if(isMenuInJapanese())
		    displayText = outputInJapanese;
		else
		    displayText = "Nothing";		    
	}
	
	public void displayOperations(int optionNumber)
	{
		switch(optionNumber)
		{
			case 0:
				text1.setFont(new Font(text.getFontName(), Font.BOLD, fontsize));
/*
				displayText="";
				for(int i=0;i<text.sentenceNumber;i++)
				{
					displayText+="-----";
					displayText+=text.sentence[i].sentenceText;
				}
				
				displayText="";
				for(int i=0;i<text.sentenceNumber;i++)
				{
					displayText+="-----";
					for(int j=0;j<text.sentence[i].wordNumber;j++)
					{
						displayText+="+++";
						displayText+=text.sentence[i].word[j];
					}
					
				}
*/				

				text1.setText(displayText);
				text1.setCaretPosition(0);				
				break;
				
			case 1:
				text.fileSave(text1.getText(),2);
				break;
                
			case 2:
				text.fileSave(text1.getText(),1);
				break;
				
			case 9:
				fontsize--;
				displayOperations(0);
				break;
				
			case 10:
				fontsize++;
				displayOperations(0);
				break;
				
			case 100:
				displayText = text.originalText;
				displayOperations(0);				
				break;				
		}		
	}	
	
	public boolean setData(int dataID, String t)
	{
        switch(dataID)
        {
            case 0:		displayText = t;
                return true;
        }

		return false;
	}
	
	public void setFont()
	{
		fontsize = getFontSize();
	}
	
    //Mouse Event

    public void mouseReleased(MouseEvent e)			//get selectedText
    {
        writeReleaseLog();
        
        String selectedText = text1.getSelectedText();
        
        if(selectedText != null)
            if(selectedText.length() < 10)
            {
                setMainFocusString(text1.getSelectedText());
                executeAllByFocus();
            }
    }
}
