/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QuickHelpModal.java
 *
 * Created on 04.04.2011, 15:04:16
 */

package csa.gui.dialogs;

import csa.config.Configuration;
import csa.gui.components.ModalInternalFrame;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

/**
 *
 * @author malban
 */
public class QuickHelpModal extends javax.swing.JPanel {

    /** Creates new form QuickHelpModal */
    private QuickHelpModal() {
        initComponents();


        // jEditorPane1.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
        // Editor pane has bug with html: <meta http-equiv=Content-Type content=text/html>
        // see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4695909

    }

    public static void showHelpHtml(String html)
    {
        JFrame frame = Configuration.getConfiguration().getMainFrame();
        QuickHelpModal panel = new QuickHelpModal();
        panel.jEditorPane1.setContentType("text/html");
        panel.jEditorPane1.setText(html);
        JInternalFrame modal = new ModalInternalFrame("Help", frame.getRootPane(), frame, panel);
        panel.modelDialog = modal;
        modal.setVisible(true);
    }
    public static void showHelpText(String text)
    {
        JFrame frame = Configuration.getConfiguration().getMainFrame();
        QuickHelpModal panel = new QuickHelpModal();
        panel.jEditorPane1.setContentType("text/plain");
        panel.jEditorPane1.setText(text);
        JInternalFrame modal = new ModalInternalFrame("Help", frame.getRootPane(), frame, panel);
        panel.modelDialog = modal;
        modal.setVisible(true);
    }
    public static void showHelpHtmlFile(String page)
    {
        JFrame frame = Configuration.getConfiguration().getMainFrame();
        QuickHelpModal panel = new QuickHelpModal();
        panel.jEditorPane1.setContentType("text/html");
        try
        {
            panel.jEditorPane1.setPage(page);
        }
        catch (Throwable e)
        {
            panel.jEditorPane1.setContentType("text/plain");
            panel.jEditorPane1.setText("Can´t display page:\n"+page);
        }
        JInternalFrame modal = new ModalInternalFrame("Help", frame.getRootPane(), frame, panel);
        panel.modelDialog = modal;
        modal.setVisible(true);
    }
    JInternalFrame modelDialog;
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        jButton1 = new javax.swing.JButton();

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jEditorPane1.setContentType("text/html");
        jEditorPane1.setName("jEditorPane1"); // NOI18N
        jScrollPane1.setViewportView(jEditorPane1);

        jButton1.setText("Done");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton1))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        modelDialog.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
