//
// Core Program for TETDM 
// VisualizationModule.java Version 0.30
// Copyright(C) 2011 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 javax.swing.*;



public abstract class VisualizationModule extends JPanel
{
	private int moduleID = -1;
	private int panelID;	
	
	public TextData text;
	
	public String myModulePath;	
	
	boolean makePanel = true;
	boolean firstTime = true;

	public int oldSizeX, oldSizeY;
	public int sizeX=0, sizeY=0;
	public double changeX, changeY;
	
//	public boolean focusTouchDisplay = false;
//	public boolean focusClickDisplay = false;
	
	//-->public boolean focusDisplay = true;	
	
	public VisualizationModule(){}

	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 initPanel()
	{
		setLayout(new BorderLayout());
		setBackground(Color.white);
		
		myModulePath = text.absolutePath + this.getClass().getPackage().getName().replaceAll("\\.","/") + File.separator;

		initializePanel();			// Step.3
		
		System.out.println(" + Visualization: "+this.getClass().getName());
	}
	
	public final void selected(TextData tex)
	{
		text = tex;
		if(makePanel)
		{
			initPanel();			//(to Step.3)		
			makePanel = false;
		}
		initializeData();			// Step.4
	}
	
	//FOCUS
	public final void focusSelected(TextData tex)
	{
		text = tex;
		initializeData();			// Step.4
	}	

	public abstract void initializePanel();		// #Step.3
	public abstract void initializeData();				// #Step.4
	public abstract void displayOperations(int optionNumber);		// #Step.6

	public final void setData(){}		// for check only

	public void setData(int dataID, int data){ System.out.println("<int> dataID="+dataID+" was not set to Visualization Module."); }
	public void setData(int dataID, double data){ System.out.println("<double> dataID="+dataID+" was not set to Visualization Module."); }
	public void setData(int dataID, String data){ System.out.println("<String> dataID="+dataID+" was not set to Visualization Module."); }
	public void setData(int dataID, int data[]){ System.out.println("<int []> dataID="+dataID+" was not set to Visualization Module."); }
	public void setData(int dataID, double data[]){ System.out.println("<double []> dataID="+dataID+" was not set to Visualization Module."); }
	public void setData(int dataID, String data[]){ System.out.println("<String []> dataID="+dataID+" was not set to Visualization Module."); }
	
	//display for visualization
	public void setFont(){}
	
	public boolean getPanelSize()
	{
		boolean change = false;
		
		oldSizeX = sizeX;
		oldSizeY = sizeY;
		
		sizeX = getWidth();
		sizeY = getHeight();
		
		if(sizeX != oldSizeX || sizeY != oldSizeY)
			change = true;

		changeX = changeY = 1.0;
		if(oldSizeX != 0)
			changeX = sizeX / (double)oldSizeX;
		if(oldSizeY != 0)
			changeY = sizeY / (double)oldSizeY;
		
		return change;
	}
	
	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 setDisplayByTouchFocus()
	{
		if(focusTouchDisplay)
			displayOperations(0);
	}
	//FOCUS		
	public final void setDisplayByClickFocus()
	{
		if(focusClickDisplay)
			displayOperations(0);
	}	
*/
	//FOCUS		
	public final void setDisplayByTouchFocus()
	{
		displayOperations(4501);
	}
	//FOCUS		
	public final void setDisplayByClickFocus()
	{
		displayOperations(4502);
	}	
	
	
	//FOCUS		
	protected final void repaintOthersByTouch()
	{
		text.control.setDisplayOthersByTouchFocus(panelID);
	}
	//FOCUS		
	protected final void repaintOthersByClick()
	{
		text.control.setDisplayOthersByClickFocus(panelID);		
	}	
	//FOCUS
    protected final void executeOthersByTouch()
    {
		text.control.resetSelectPanelDataByTouchFocus(panelID);
    }
    //FOCUS
    protected final void executeOthersByClick()
    {
		text.control.resetSelectPanelDataByClickFocus(panelID);		
    }
	//FOCUS	ALL		
	protected final void executeAllByTouch()
	{
		text.control.resetSelectPanelDataByTouchFocusAll(panelID);
	}
	//FOCUS	ALL		
	protected final void executeAllByClick()
	{
		text.control.resetSelectPanelDataByClickFocusAll(panelID);
	}	
	
	//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);
	}
	
	//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 boolean isMenuInJapanese()
	{
		return text.settingData.inJapanese;
	}
}

