/*******************************************************************************
 * 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 javax.swing.*;
import java.awt.*;
import GenRGenS.IU.*;
import GenRGenS.*;
import GenRGenS.utility.callbacks.*;
import java.awt.event.*;

public class GenerationSpecificOptionsPanel extends JPanel
{
  TextArea textArea1 = new TextArea();
  JPanel help = new JPanel();
  JPanel panel4 = new JPanel();
  BorderLayout borderLayout2 = new BorderLayout();
  Label label1 = new Label();
  FlowLayout flowLayout1 = new FlowLayout();
  BorderLayout borderLayout1 = new BorderLayout();
  JPanel panel2 = new JPanel();
  Button button1 = new Button();
  JPanel panel3 = new JPanel();
  CardLayout cardLayout1 = new CardLayout();
  JPanel options = new JPanel();
  GridLayout gridLayout1 = new GridLayout();
  Box box1;
  JButton[] button2OptionIndex;
  String[] helpStrings;



  public void OnValidate()
  {
  }

  public void beforeVisible(GeneratorConfigFile f)
  {
    label1.setText(f.getLitteralName()+" Options :");
    Option[] opts = f.getOptions();
    button2OptionIndex = new JButton[opts.length];
    helpStrings =  new String[opts.length];
    for(int i =0;i<opts.length;i++)
    {
      box1.removeAll();
      Option o = opts[i];
      o.getOptionName();
      // On traitera dans les prochaines versions des parametrages plus riches (String, entiers etc ...)
      //if(o.getCallback().getTypename() == Callback.TYPE_BOOLEAN)
      {
        JPanel p = new JPanel();
        JCheckBox c = new JCheckBox(o.getOptionName());
        JButton b = new JButton("?");
        b.addActionListener(new java.awt.event.ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            b_actionPerformed(e);
          }
        });
        p.add(c);
        p.add(b);
        button2OptionIndex[i] = b;
        box1.add(p);
        helpStrings[i] = o.getLongHelp();
      }
    }
  }

  public void b_actionPerformed(ActionEvent e)
  {
    for(int i = 0; i<button2OptionIndex.length; i++)
    {
      JButton b = button2OptionIndex[i];
      if ((Object)b ==e.getSource())
      {
        textArea1.setText(helpStrings[i]);
        cardLayout1.show(panel3,"help");
      }
    }
  }

  public GenerationSpecificOptionsPanel()
  {
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    box1 = Box.createVerticalBox();
    textArea1.setText("help");
    this.setLayout(borderLayout2);
    help.setLayout(borderLayout1);
    panel4.setLayout(flowLayout1);
    label1.setFont(new java.awt.Font("DialogInput", 1, 12));
    label1.setText("Options :");
    button1.setLabel("Back");
    button1.addActionListener(new java.awt.event.ActionListener()
    {

      public void actionPerformed(ActionEvent e)
      {
        button1_actionPerformed(e);
      }
    });
    panel3.setLayout(cardLayout1);
    options.setLayout(gridLayout1);
    gridLayout1.setColumns(1);
    gridLayout1.setRows(0);
    this.add(panel4, BorderLayout.NORTH);
    panel4.add(label1, null);
    this.add(panel3, BorderLayout.CENTER);
    panel3.add(options, "Options");
    options.add(box1, null);
    panel3.add(help, "help");
    help.add(textArea1, BorderLayout.CENTER);
    help.add(panel2, BorderLayout.SOUTH);
    panel2.add(button1, null);
  }

  void button1_actionPerformed(ActionEvent e)
  {
    cardLayout1.show(panel3,"Options");
  }

}