/*
!=======================================================================
!
!  PROGRAM  PHASE-Viewer  (PHASE-Viewer 2014.01 ver.3.3.0)
!
!  Created on 2005/12/19, 16:17
!  AUTHOR(S): KOGA, Junichiro
!  File : ScriptDescriptionPanel.java
!  
!  Contact address :  Phase System Consortium
!                     E-mail: phase_system@nims.go.jp URL https://azuma.nims.go.jp
!
!
!   Since 2002, this program set had been intensively developed as a part of the following 
!  national projects supported by the Ministry of Education, Culture, Sports, Science and
!  Technology (MEXT) of Japan; "Frontier Simulation Software for Industrial Science
!  (FSIS)" from 2002 to 2005, "Revolutionary Simulation Software (RSS21)" from 2006 to
!  2008. "Research and Development of Innovative Simulation Software (RISS)" from 2008
!  to 2013. These projects is lead by the Center for Research on Innovative Simulation 
!  Software (CISS), the Institute of Industrial Science (IIS), the University of Tokyo.
!   Since 2013, this program set has been further developed centering on PHASE System
!  Consortium. 
!   The activity of development of this program set has been supervised by Takahisa Ohno.
!
!=======================================================================
 */

package ciss.phase_viewer.scripting;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;

import org.apache.log4j.Logger;

/**
 * とあるスクリプトの「説明文」を表示.
 * 
 * @author
 */
public class ScriptDescriptionPanel extends JPanel {
    private Logger logger = Logger.getLogger(ScriptDescriptionPanel.class
            .getName());
    private JTextPane textPane;

    /**
     * @param scriptFile
     *            初期スクリプトファイルへのパス
     */
    public ScriptDescriptionPanel(String scriptFile) {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        setBorder(new TitledBorder("description"));
        textPane = new JTextPane();
        textPane.setContentType("text;charset=Shift_JIS");
        textPane.setEditable(false);
        textPane.setText(ScriptUtils.getDescriptionFrom(scriptFile));
        JScrollPane scr = new JScrollPane(textPane);
        scr.setPreferredSize(new Dimension(500, 300));
        add(scr);
        textPane.setCaretPosition(0);
        revalidate();
    }

    /**
     * 何もせず初期化
     */
    public ScriptDescriptionPanel() {
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        setBorder(new TitledBorder("description"));
        textPane = new JTextPane();
        textPane.setContentType("text;charset=Shift_JIS");
        textPane.setEditable(false);
        JScrollPane scr = new JScrollPane(textPane);
        add(scr);
    }

    /**
     * このGUIは情報表示を目的としているためデフォルトでは編集不可にしているが, このメソッドを利用すれば編集可にもできる.
     * 
     * @param editable
     *            trueを渡せば編集可となる.
     */
    public void setEditable(boolean editable) {
        textPane.setEditable(editable);
    }

    /**
     * スクリプトファイルセット. そのスクリプトファイルから, 可能な場合説明文を取得し表示.
     * 
     * @param scriptFile
     *            スクリプトファイルへのパス.
     */
    public void setScriptFile(String scriptFile) {
        textPane.setText(ScriptUtils.getDescriptionFrom(scriptFile));
        textPane.setCaretPosition(0);
        revalidate();
    }

    /**
     * 「Scriptの説明用文字列」を返す.
     * 
     * @return Script説明用文字列.
     */
    public String getScriptDescriptionText() {
        return textPane.getText();
    }

}
