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

/**
 * 
 */
class Gui extends JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;
 	JTextArea TextArea_GoalList;
 	JTextArea TextArea_initInitialState;
	JButton b1;
	//グラフィック
	pGraphics grap;
	
	Gui() throws IOException {
		//初期化
		//フレームの表示
		myframe();
	}
	
	void myframe(){
		JFrame f = new JFrame("Planning");
		JPanel panel1 = new JPanel();
		// コンテンツ区画の取得
		Container cont = f.getContentPane();
		// コンポーネントの作成
		b1 = new JButton("Planning!!");
		TextArea_GoalList = new JTextArea("ontable A\nB on A\nclear B", 10, 20);
		TextArea_initInitialState = new JTextArea("ontable B\nA on B\nclear A\nhandEmpty", 10, 20);
		
		b1.addActionListener(this);
		// グリッドレイアウト
		//GridLayout grid = new GridLayout();
		//cont.setLayout(grid);
		 cont.setLayout(new GridLayout(2, 2));
		 panel1.setLayout(new GridLayout(1, 1));



		TextArea_GoalList.setWrapStyleWord(true);
		TextArea_GoalList.setLineWrap(true);
		JScrollPane scrollPane1 = new JScrollPane(TextArea_GoalList);
		getContentPane().add(scrollPane1);
		
		TextArea_initInitialState.setWrapStyleWord(true);
		TextArea_initInitialState.setLineWrap(true);
		JScrollPane scrollPane2 = new JScrollPane(TextArea_initInitialState);
		getContentPane().add(scrollPane2);

		//グラフィックス用クラスの呼び出し
		grap=new pGraphics();		
		
		//ボタン
		panel1.add(b1);
		//パネルをフレームに配置
		cont.add(panel1);
		cont.add(scrollPane1);
		cont.add(scrollPane2);
		//cont.add(grap);
		// フレームのサイズを指定
		f.setSize(500, 500);
		// フレームの表示・非表示を指定
		f.setVisible(true);
		// ×を押した時の処理
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	//プランニングボタンが押された時の処理
	void start(){
		//テキストエリアから読み取り、改行コードで区切ったものをStringの配列に入れます。
		String[] golas = (TextArea_GoalList.getText()).split("\n");
		String[] inits = (TextArea_initInitialState.getText()).split("\n");
		//プランナーを呼び出して完了！
		  (new Planner()).start(golas,inits);
		
		  //グラフィック描写開始
			//ほんとは結果を受け取って描写
		  //まだ未実装
		  grap.start();
		 
	}
	

	@Override
	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == b1) {
			this.start();
		}
		
	}
}