package jp.ac.kyutech.mns.ist;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import jp.ac.kyutech.mns.ist.util.QuickMenuActionManager;

public class ConfigPanel_Database extends ConfigPanel implements Runnable {
	private static final long serialVersionUID = -1308877143307915884L;
	Thread t;
	final SimpleATN satn;
	
	JLabel current;
	public ConfigPanel_Database(final SimpleATN satn, JFrame parent){
		super(parent);
		this.satn = satn;
//		t = new Thread(this);
//		t.start();
		run();
		
		//設定画面用の画面
		tabIcon = QuickMenuActionManager.createNavigationIcon("_database"+"24");
		tabTitle = "Database";
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		
		JPanel currentP = new JPanel();
		currentP.setBorder(BorderFactory.createTitledBorder("Databaseの設定"));
		currentP.setLayout(new BoxLayout(currentP, BoxLayout.Y_AXIS));
		currentP.setAlignmentX(CENTER_ALIGNMENT);
		
		
		current = new JLabel("");//satn.mysqldb.db
		current.setBorder(BorderFactory.createTitledBorder("現在のデータベース"));
		currentP.add(current);
		
		JButton selectDB = new JButton("データベースを変更");
		currentP.add(selectDB);
		selectDB.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				satn.mysqldb.change_db(findActiveParent());
			}
		});

		currentP.add(new JLabel(" "));

		JButton importSQL = new JButton("新規データベースを作成し，sqlファイルからインポート");
		currentP.add(importSQL);
		importSQL.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				satn.mysqldb_root.import_file(findActiveParent());
			}
		});
		currentP.add(importSQL);
//
////		currentP.add(new JLabel(" "));
//		currentP.add(new JLabel(" "));
//
//		base = new JLabel(basedir.getAbsolutePath());
//		base.setBorder(BorderFactory.createTitledBorder("検索起点フォルダ"));
//		currentP.add(base);
//
//		home = new JLabel(new File(System.getProperty("user.dir")).getAbsolutePath());
//		home.setBorder(BorderFactory.createTitledBorder("カレントディレクトリ （jar / jnlp の起動場所）"));
//		currentP.add(home);

		add(currentP);
}
	public JFrame findActiveParent(){
		if (frame.isShowing()) return frame;
		else return satn;
	}
	public void update(){
		if (satn.mysqldb.db != null) current.setText("現在のデータベースは "+satn.mysqldb.db+" です．");
	}

	@Override
	public void run() {
	}

}
