package osa.attribute.atgrammar.gui.dialogs;

import javax.swing.JDialog;
import java.awt.HeadlessException;


import java.util.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



import osa.attribute.atgrammar.grammar.*;
import osa.attribute.atgrammar.grammar.symbols.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: </p>
 * <p>Company: </p>
 * @author not attributable
 * @version
 */

public class NewSymbolDialog
  extends JDialog
  {

  protected class NewSymbolDialogPane
    extends JPanel
    {
    protected class OkButtonActionListener
      implements ActionListener
      {
      public void actionPerformed(ActionEvent e)
        {
        int type=type_cmbx.getSelectedIndex();
        String name=name_txtfld.getText();
        switch(type)
              {
              case 0:
                if(dictionary.getNonTerminalSymbol(name)!=null)
                  {
                  }
                else
                  {
                  dictionary.putNonTerminalSymbol(new NonTerminalSymbol(name));
                  }
                break;
              case 1:
                if(dictionary.getTerminalSymbol(name)!=null)
                  {
                  dictionary.putTerminalSymbol(new TerminalSymbol(name));
                  }
                else
                  {
                  dictionary.putTerminalSymbol(new TerminalSymbol(name));
                  }
                break;
              case 2:
                if(dictionary.getOutputSymbol(name)!=null)
                  {
                  dictionary.putTerminalSymbol(new TerminalSymbol(name));
                  }
                else
                  {

                  }
                break;
              default:
                System.err.println("Error!");
              }
        }
      }

    protected class CancelButtonActionListener
      implements ActionListener
      {
      public void actionPerformed(ActionEvent e)
        {

        }
      }



    JLabel promt_lbl = new JLabel();
    JTextField name_txtfld = new JTextField();
    JComboBox type_cmbx;
    JLabel name_lbl = new JLabel();
    JLabel type_lbl = new JLabel();
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    JPanel jPanel2 = new JPanel();
    BorderLayout borderLayout1 = new BorderLayout();
    GridLayout gridLayout1 = new GridLayout();
    JPanel jPanel1 = new JPanel();
    JButton cancel_button = new JButton();
    JButton ok_button = new JButton();
    Component component1;
    Component component2;
    Component component3;

    public NewSymbolDialogPane()
      {
      Vector types=new Vector();
      types.add("Нетерминалльный");
      types.add("Терминалльный");
      types.add("Выходной");

      this.type_cmbx = new JComboBox();
      try{
         jbInit();
         }
      catch(Exception e)
         {
         e.printStackTrace();
         }
      }

    private void jbInit()
      throws Exception
      {
      component1 = Box.createHorizontalStrut(8);
      component2 = Box.createHorizontalStrut(8);
      component3 = Box.createHorizontalStrut(8);
      promt_lbl.setText("Введите новый символ...");
      this.setLayout(gridBagLayout1);
      name_txtfld.setText("jTextField1");
      name_lbl.setFont(new java.awt.Font("MS Sans Serif", 0, 11));
      name_lbl.setText("Имя символа:");
      type_lbl.setText("Тип символа:");
      jPanel2.setLayout(borderLayout1);
      gridLayout1.setColumns(5);
      gridLayout1.setHgap(5);
      gridLayout1.setVgap(5);
      jPanel1.setLayout(gridLayout1);
      cancel_button.setText("Cancel");
      ok_button.setText("OK");
      this.add(promt_lbl,               new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0
              ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
      this.add(name_txtfld,       new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0
              ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
      this.add(type_cmbx,        new GridBagConstraints(2, 2, 1, 1, 0.2, 0.0
              ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
      this.add(type_lbl,      new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
      this.add(name_lbl,      new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
      this.add(jPanel2,       new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0
              ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
      jPanel2.add(jPanel1, BorderLayout.CENTER);
      jPanel1.add(component1, null);
      jPanel1.add(ok_button, null);
      jPanel1.add(component2, null);
      jPanel1.add(cancel_button, null);
      jPanel1.add(component3, null);
      }
    }



  protected CommonDictionary dictionary;

  public NewSymbolDialog(CommonDictionary dictionary)
    {
    this.dictionary=dictionary;
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(new NewSymbolDialogPane(),BorderLayout.CENTER);
    }
  }