//
// Core Program for TETDM
// QuestionPanel.java Version 1.00
// Copyright(C) 2017-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 QuestionPanel extends JPanel implements ActionListener
{
    JPanel allTopPanel;
    JPanel middlePanel;
    
    JPanel checkPanel;
    JPanel labelPanel;
    
    
    //Top
    JLabel message;
    
    //Middle
    JScrollPane scroll[];
    
    JPanel checkBoxPanel;


    int ans;
    int number;
    int T,F;
    String Answer[] = new String[4];
    boolean sound;
    

    //Buttom
    JButton button[];
    
    int fontsize = 16;
    
    
    String menuInJapanese[];

    boolean autoSet;
    Control control;


    
    QuestionPanel(Control control, int number,String one,String two,String three,String four,int ans,int T,int F, boolean sound)
    {
        setLayout(new BorderLayout());
        this.control = control;
        this.number = number;

        this.ans = ans;
        this.T = T;
        this.F = F;
        this.sound = sound;
        
        Answer[0]=one;
        Answer[1]=two;
        Answer[2]=three;
        Answer[3]=four;
        button = new JButton[4];
        

        
        //ALL
        allTopPanel = new JPanel();
        allTopPanel.setBackground(Color.blue);
        add(allTopPanel, BorderLayout.NORTH);
        
        message = new JLabel();
        message.setFont(new Font(control.sp1.fontName, Font.BOLD, fontsize+2));
        message.setForeground(Color.white);
        
        setTitleNames();
        allTopPanel.add(message);
        

        
        //MIDDLE
        middlePanel = new JPanel();
        middlePanel.setLayout(new GridLayout(1,1));
        add(middlePanel);
        scroll = new JScrollPane[2];
        
        //MIDDLE-INSIDE
        
        checkPanel = new JPanel(new GridLayout(4,1));
        checkPanel.setBackground(Color.blue);
        
        labelPanel = new JPanel(new GridLayout(4,1));
        labelPanel.setBackground(Color.green);
        

        for(int i=0;i<4;i++)
        {
            button[i] = new JButton(Answer[i]);
            button[i].setBackground(Color.white);
            button[i].addActionListener(this);
        }
        
        for(int i=0;i<4;i++)
            labelPanel.add(button[i]);
        
        checkBoxPanel = new JPanel(new BorderLayout());
        checkBoxPanel.setBackground(Color.green);
        checkBoxPanel.add(labelPanel);
        checkBoxPanel.add(checkPanel, BorderLayout.WEST);
        
        scroll[0] = new JScrollPane(checkBoxPanel);
        middlePanel.add(scroll[0]);
    }

    public void setTitleNames()
    {
        if(control.sp1.inJapanese)
            message.setText("Select Answer");
        else
            message.setText("Select Answer");
    }
    
    public void componentWindowClose(Component c)
    {
        Window w = SwingUtilities.getWindowAncestor(c);
        w.dispose();
    }
    
    
    //Action listener
    public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;
        
        if(e.getSource() == button[ans-1] )
        {
            if(sound)
            {
                SoundPlay soundPlay = new SoundPlay(control.absolutePath, "correct_answer.wav");
                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e2){}
            }
            StoryControl.SerifControl(T, true);
            componentWindowClose((Component)e.getSource());
        }
        else
        {
            if(sound)
            {
                SoundPlay soundPlay = new SoundPlay(control.absolutePath, "incorrect_answer.wav");
                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e2){}
            }
            StoryControl.SerifControl(F, true);
            componentWindowClose((Component)e.getSource());
        }
    }
}
