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


package source;

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

import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JPanel;


//MAIN FRAME
public class MainFrame extends JFrame
{
    double version;
    
    int windowSizeX, windowSizeY;
    int popSizeY = 65;

	
	boolean logStart = false;
	
	Control controlPanel;
	Container pane = getContentPane();
	
	MainFrame myFrame;
	String windowName = "MAIN";		

	MainFrame(String filename, String absolutePath, boolean english, boolean utf8code, double version)
	{
		super("Total Environment for Text Data Mining (TETDM-"+version+")");
        this.version = version;
		

        
		pane.setLayout(new BorderLayout());
		
		try{
			GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();			
			DisplayMode displayMode = env.getDefaultScreenDevice().getDisplayMode();
			
			windowSizeX = displayMode.getWidth();
			windowSizeY = displayMode.getHeight() - popSizeY - 10;
//			windowSizeY = displayMode.getHeight() - popSizeY;			
		}
		catch(Exception e)
		{
			windowSizeX = 1024;
			windowSizeY = 768;
		}
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        WINDOWACTIONLOG windowActionLog = new WINDOWACTIONLOG(this, windowName);
        this.addComponentListener(windowActionLog.componentListener);                    //FOR LOG
        this.addWindowListener(windowActionLog.windowListener);
		

		controlPanel = new Control(this, filename, absolutePath, english, utf8code);
		pane.add(controlPanel);	
		setVisible(true);
		
		myFrame = this;
	}
	
//    public void reSize(int windowSizeX, int windowSizeY, int popSizeY, boolean gameMode)
    public void reSize(int sizeX, int sizeY, int popSizeY, boolean gameMode)
	{
        int X=0,Y;
		
		//y coordinate will be adjusted automatically at activation in mac use.
		if(gameMode == true)
			Y = popSizeY*2;
		else
			Y = popSizeY;
		
		setBounds(X, Y, sizeX, sizeY-Y);
	}	
	
/*	
	public void reSize(int mode, boolean gameMode)
	{
		X = 0;
		sizeX = windowSizeX;
		
		//y coordinate will be adjusted automatically at activation in mac use.
		if(gameMode == true)
			Y = popSizeY*2+65;
		else
			Y = popSizeY+65;
				
		if(mode == 0)
			Y += 40;
		
		sizeY = windowSizeY-Y;
		
		setBounds(X, Y, sizeX, sizeY);
	}
*/
    /*
	class MyWindowListener extends WindowAdapter {
		
		public void windowActivated(WindowEvent e)		
		{
			if(logStart == false)
				return;			
			
			controlPanel.writeActionLog(windowName+"-WINDOW", "CREATED");
			controlPanel.writeWindowLog(myFrame, windowName);			
		}
	}
	
	class MyComponentListener extends ComponentAdapter {
		
		public void componentMoved(ComponentEvent e) 
		{
			if(logStart == false)
				return;
			
			controlPanel.writeActionLog(windowName+"-WINDOW", "MOVED");
			controlPanel.writeWindowLog(myFrame, windowName);
		}		
		
		public void componentResized(ComponentEvent e)	
		{
			if(logStart == false)
				return;			

			controlPanel.writeActionLog(windowName+"-WINDOW", "RESIZED");
			controlPanel.writeWindowLog(myFrame, windowName);
		}
	}*/
}
