/*******************************************************************************
 * GenRGenS v.1.0, Generation of Random Genomic Sequences                      *
 * Copyright (C) 2001  Alain Denise/Yann Ponty                                 *
 *                                                                             *
 * This program is free software; you can redistribute it and/or               *
 * modify it under the terms of the GNU General Public License                 *
 * as published by the Free Software Foundation; either version 2              *
 * of the License, or (at your option) any later version.                      *
 *                                                                             *
 * This program is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
 * GNU General Public License for more details.                                *
 *                                                                             *
 * You should have received a copy of the GNU General Public License           *
 * along with this program; if not, write to the Free Software                 *
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
 *******************************************************************************/

package GenRGenS.IU;

/**
 * Title:        <p>
 * Description:  <p>
 * Copyright:    Copyright (c) <p>
 * Company:      <p>
 * @author
 * @version 1.0
 */
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.text.html.*;

public class HelpDialog extends JDialog
{
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JPanel jPanel1 = new JPanel();
  JButton jButton1 = new JButton();
  JEditorPane jEditorPane1 = new JEditorPane();
  JScrollPane jScrollPane1 = new JScrollPane();

  public HelpDialog(Frame frame, String title, boolean modal)
  {
    super(frame, title, modal);
    try
    {
      jbInit();
      pack();
    }
    catch(Exception ex)
    {
      ex.printStackTrace();
    }
  }

  public HelpDialog()
  {
    this(null, "Help ...", false);
  }

  public void setVisible(boolean b)
  {
    super.setVisible(b);
    if (b)
    {
      try
      {jEditorPane1.setPage(getClass().getResource("bin/help/index.html"));}
      catch(IOException e)
      {}
    }
  }

  void jbInit() throws Exception
  {
    panel1.setLayout(borderLayout1);
    jButton1.setText("Close");
    jButton1.addActionListener(new java.awt.event.ActionListener()
    {

      public void actionPerformed(ActionEvent e)
      {
        jButton1_actionPerformed(e);
      }
    });
    jEditorPane1.setContentType("text/html");
    jEditorPane1.setText("<HTML></HTML>");
    jEditorPane1.setEditable(false);
    jEditorPane1.addHyperlinkListener(new javax.swing.event.HyperlinkListener()
    {

      public void hyperlinkUpdate(HyperlinkEvent e)
      {
        jEditorPane1_hyperlinkUpdate(e);
      }
    });
    this.setTitle("");
    panel1.setPreferredSize(new Dimension(200, 170));
    getContentPane().add(panel1);
    panel1.add(jPanel1, BorderLayout.SOUTH);
    jPanel1.add(jButton1, null);
    jScrollPane1.getViewport().add(jEditorPane1);
    panel1.add(jScrollPane1, BorderLayout.CENTER);
  }

  void jButton1_actionPerformed(ActionEvent e)
  {
    setVisible(false);
  }

  void jEditorPane1_hyperlinkUpdate(HyperlinkEvent e)
  {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    {
      JEditorPane pane = (JEditorPane) e.getSource();
      if (e instanceof HTMLFrameHyperlinkEvent)
      {
        HTMLFrameHyperlinkEvent  evt = (HTMLFrameHyperlinkEvent)e;
        HTMLDocument doc = (HTMLDocument)pane.getDocument();
        doc.processHTMLFrameHyperlinkEvent(evt);
      }
      else
      {
        try
        {

          pane.setPage(e.getURL()); 
        }
        catch (Throwable t)
        {t.printStackTrace();}
      }
    }
  }
}
