package osa.attribute.atgrammar.gui.tables.attributes_table;

import javax.swing.*;
import javax.swing.table.*;

import java.awt.*;

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 AttributesTCR
  implements TableCellRenderer
  {
  public AttributesTCR()
    {
    }

  public Component getTableCellRendererComponent
    (JTable table,
     Object value,
     boolean isSelected,
     boolean hasFocus,
     int row,
     int column)
    {
    JPanel cell_pane=new JPanel();
    JLabel value_label=new JLabel();
    cell_pane.setLayout(new FlowLayout(FlowLayout.LEFT));

    if(value instanceof Attribute)
      {
      Attribute attribute;
      attribute=(Attribute)value;

      switch(column)
            {
            case 0:
              value_label.setText(new Integer(row+1).toString());
              break;
            case 1:
              value_label.setText(attribute.getName());
              break;
            case 2:
              value_label.setText(attribute.getType().getName());
              break;
            case 3:
              switch(attribute.getClassType())
                    {
                    case Attribute.UNDEFINED:
                      value_label.setText("Неопределённый");
                      break;
                    case Attribute.INHERITED:
                      value_label.setText("Наследуемый");
                      break;
                    case Attribute.SYNTHESIZED:
                      value_label.setText("Синтезируемый");
                      break;
                    default:
                    }
              break;
            default:
            }
      }
    else
      {
      value_label.setText("Error!");
      }
    cell_pane.add(value_label);
    return cell_pane;
    }
  }