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

package source.Tutorial;


import source.*;
import source.TextData.*;
import source.Utility.*;
import source.GameMode.*;
import source.Tutorial.*;

import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.GroupLayout.Alignment;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.applet.* ;
import static java.awt.BorderLayout.* ;


public class ImagePanel extends JFrame
{
    //Container pane = getContentPane();
    public JButton button[];
    public JPanel buttonPanel;


    Control control;
    int count;
    
    String TurorialPath;
    
    
    public ImagePanel(Control control, int count)
    {
        this.control = control;
        this.count = count;
        
        TurorialPath = control.absolutePath+"source"+ File.separator + "Tutorial" +File.separator;
        
        setBounds(100,100,720,500);
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        
        JPanel p = new JPanel();
        
        ImageIcon icon1 = new ImageIcon(TurorialPath+"image"+ File.separator +"tutorial"+count+".png");
        Image smallImg = icon1.getImage().getScaledInstance((int) (icon1.getIconWidth()*0.48), -1, Image.SCALE_SMOOTH);
        ImageIcon smallIcon = new ImageIcon(smallImg);
        
        JLabel label1 = new JLabel(smallIcon);
        label1.setPreferredSize(new Dimension(700,450));
        
        p.add(label1);
        
        Container contentPane = getContentPane();
        contentPane.add(p, BorderLayout.CENTER);
        
        buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1,2));
        contentPane.add(buttonPanel, BorderLayout.SOUTH);
        
        
        String button_name[] = {"back <","next >","close"};
        button = new JButton [2];
        
        button[0] = new JButton(button_name[0]);
        button[0].addActionListener(new MyBtn());
        buttonPanel.add(button[0]);
        
        if(count<7)
            button[1] = new JButton(button_name[1]);    //next
        else
            button[1] = new JButton(button_name[2]);    //close
        
        button[1].addActionListener(new MyBtn());
        buttonPanel.add(button[1]);
        
        if(count==1)    // back
            button[0].setEnabled(false);
    }

    class MyBtn implements ActionListener
    {
        public void componentWindowClose(Component c)
        {
            Window w = SwingUtilities.getWindowAncestor(c);
            w.dispose();
        }
        
        public void actionPerformed(ActionEvent e)
        {
            if(e.getSource() == button[0])//back
            {
                StoryControl.ImagePop(control, count-1);
                componentWindowClose((Component)e.getSource());
            }
            
            if(e.getSource() == button[1])//next or close
            {
                if(count==7)    //Chapter0 clear -> close
                {
                    try{
                        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(TurorialPath+"serif"+ File.separator +"ClearChecker0.txt")));
                        pw.println("1");
                        pw.close();
                    }
                    catch(IOException e2){
                        System.out.println("Error!!");
                    }

                    StoryControl.PopPanelForChapter(1,control);
                    componentWindowClose((Component)e.getSource());
                }
                else    //Chapter0 continue -> next
                {
                    StoryControl.ImagePop(control, count+1);
                    componentWindowClose((Component)e.getSource());
                }
            }
        }	
    }
    
     
    
}
