/**
 * LOGICAL-PARADOX.ORG
 * Copyright (C)2004 satoshi akabane(akabane@logical-paradox.org)
 *
 */
package org.logical_paradox.console;

import java.awt.Color;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.logical_paradox.console.event.ListenerFactory;

/**
 * コンソールのGUI的コンフィグレーション
 * @author satoshi akabane@logical-paradox.org
 * @version $Revision: 1.4 $
 */
public class ConsoleConfig {
	private String windowTitle;
	private int windowWidth;
	private int windowHeight;
	private String fontFamily;
	private Color foregroundColor;
	private Color backgroundColor;
	private String listenerFactoryClassName;
	private String promptString;

	/**
	 * コンストラクタ
	 */
	public ConsoleConfig() {
	}
	public ConsoleConfig(String resourceName) {
		this();
		load(resourceName);
	}
	/**
	 * リソースファイルからプロパティをロードする
	 * @param resourceName リソース名
	 */
	public void load(String resourceName) {
		PropertyResourceBundle rc = (PropertyResourceBundle) ResourceBundle.getBundle(resourceName);

		// リソースの展開
		windowTitle = rc.getString("WINDOW_TITLE");
		windowWidth = Integer.parseInt(rc.getString("WINDOW_WIDTH"));
		windowHeight = Integer.parseInt(rc.getString("WINDOW_HEIGHT"));
		fontFamily = rc.getString("FONT_FAMILY");
		String[] color = rc.getString("FOREGROUND_COLOR").split(",");
		String[] bgcolor = rc.getString("BACKGROUND_COLOR").split(",");
		listenerFactoryClassName = rc.getString("LISTENER_FACTORY_CLASS");
		promptString = rc.getString("PROMPT_STRING");

		foregroundColor = new Color(Integer.parseInt(color[0].trim()), Integer.parseInt(color[1].trim()), Integer.parseInt(color[2].trim()));
		backgroundColor = new Color(Integer.parseInt(bgcolor[0].trim()), Integer.parseInt(bgcolor[1].trim()), Integer.parseInt(bgcolor[2].trim()));
	}

	public String getWindowTitle() {
		return windowTitle;
	}
	public int getWindowWidth() {
		return windowWidth;
	}
	public int getWindowHeight() {
		return windowHeight;
	}
	public String getFontFamily() {
		return fontFamily;
	}
	public Color getForegroundColor() {
		return foregroundColor;
	}
	public Color getBackgroundColor() {
		return backgroundColor;
	}
	public ListenerFactory getListenerFactory() throws Exception {
		return (ListenerFactory)Class.forName(listenerFactoryClassName).newInstance();
	}
	public String getPromptString() {
		return promptString;
	}
	public void setPromptString(String ppt) {
		promptString = ppt;
	}
}
