package charactermanaj.util;

import java.awt.Component;
import java.awt.Dimension;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public final class ErrorMessageHelper {
	
	private ErrorMessageHelper() {
		super();
	}

	// TODO: エラーコードを定義し、ユーザーフレンドリーなものにすべき。
	
	public static void showErrorDialog(Component parent, Throwable ex) {
		JTextArea textArea = new JTextArea();
		
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		ex.printStackTrace(pw);
		pw.close();
		textArea.setText(sw.toString());
		
		JScrollPane scr = new JScrollPane(textArea);
		scr.setPreferredSize(new Dimension(400, 150));
		scr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		scr.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		
		ex.printStackTrace();
		JOptionPane.showMessageDialog(parent, scr, "ERROR", JOptionPane.ERROR_MESSAGE);
	}

}
