package osa.attribute.atgrammar.gui.dialogs;

import java.util.*;

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

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 TypesEditingPanel
  extends JPanel
  {

  protected class TypesListSelectionListener
    implements ListSelectionListener
    {
    public void valueChanged(ListSelectionEvent e)
      {
      JList source_list=(JList)e.getSource();
      int selected_index=source_list.getSelectedIndex();
        if(source_list.getSelectedIndex()>-1)
          {
          remove_btn.setEnabled(true);
          rename_btn.setEnabled(true);
          }
        else
          {
          remove_btn.setEnabled(false);
          rename_btn.setEnabled(false);
          }
        }
      }

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

      }
    }

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

      }
    }

  protected class RenameBtnActionListener
    implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
      {
      AttributeType selected_type=(AttributeType)types_list.getSelectedValue();
      if(selected_type.getName().equals("void"))
        {
        }
      }
    }

  protected class TypesListModel
    extends AbstractListModel
    {
    ArrayList list_model;

    public TypesListModel(ArrayList list)
      {
      for(int i=0;i<source_list_size;i++)
         {

         }
      this.list_model=list_model;
      }

    public int getSize()
      {
      return list_model.size();
      }

    public Object getElementAt(int index)
      {
      AttributeType type=(AttributeType)list_model.get(index);
      return type;
      }
    }

  BorderLayout borderLayout1 = new BorderLayout();
  JScrollPane types_list_scroll_pane = new JScrollPane();
  JPanel buttons_pane = new JPanel();
  GridLayout gridLayout1 = new GridLayout();
  JButton add_btn = new JButton();
  JButton rename_btn = new JButton();
  JButton remove_btn = new JButton();
  JLabel jLabel1 = new JLabel();
  JList types_list = new JList();

  protected AttributeTypeSystem type_system;

  public TypesEditingPanel( AttributeTypeSystem type_system )
    {
    this.type_system=type_system;

    types_list.setModel(new TypesListModel(type_system.getTypesList()));
    types_list.addListSelectionListener(new TypesListSelectionListener());

    add_btn.addActionListener(new AddBtnActionListener());

    remove_btn.addActionListener(new RemoveBtnActionListener());
    rename_btn.addActionListener(new RenameBtnActionListener());

    add_btn.setEnabled(true);
    remove_btn.setEnabled(false);
    rename_btn.setEnabled(false);

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

  private void jbInit()
    throws Exception
    {
    this.setLayout(borderLayout1);
    buttons_pane.setLayout(gridLayout1);
    add_btn.setText("Добавить");
    rename_btn.setText("Переименовать");
    remove_btn.setText("Удалить");
    jLabel1.setText("jLabel1");
    gridLayout1.setColumns(3);
    gridLayout1.setHgap(5);
    gridLayout1.setRows(1);
    gridLayout1.setVgap(5);
    borderLayout1.setHgap(5);
    borderLayout1.setVgap(5);
    this.add(types_list_scroll_pane, BorderLayout.CENTER);
    types_list_scroll_pane.getViewport().add(types_list, null);
    this.add(buttons_pane,  BorderLayout.SOUTH);
    buttons_pane.add(add_btn, null);
    buttons_pane.add(remove_btn, null);
    buttons_pane.add(rename_btn, null);
    this.add(jLabel1, BorderLayout.NORTH);
    }
}