package jetbrains.mps.ide.ui.dialogs.properties.renderers;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Component;
import javax.swing.JTable;
import jetbrains.mps.project.structure.modules.mappingpriorities.RuleType;
import javax.swing.JComponent;
import com.intellij.openapi.application.ApplicationManager;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.border.EmptyBorder;

@GeneratedClass(node = "r:ebb14179-d192-43be-86ee-73001bbf35b0(jetbrains.mps.ide.ui.dialogs.properties.renderers)/3995997045458515690", model = "r:ebb14179-d192-43be-86ee-73001bbf35b0(jetbrains.mps.ide.ui.dialogs.properties.renderers)")
public class RuleTypeRenderer extends DefaultTableCellRenderer {
  public RuleTypeRenderer() {
  }
  @Override
  public Component getTableCellRendererComponent(final JTable table, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
    String caption = (value instanceof RuleType ? ((RuleType) value).getPresentation() : "null");
    JComponent comp = (JComponent) super.getTableCellRendererComponent(table, caption, isSelected, hasFocus, row, column);
    if (hasFocus && table.isRowSelected(row)) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          table.editCellAt(row, column);
        }
      });
    }
    return RuleTypeRenderer.createCenterAlignmentInCell(comp);
  }
  public static JComponent createCenterAlignmentInCell(JComponent comp) {
    JPanel compPanel = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints(1, 1, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
    compPanel.add(comp, constraints);
    compPanel.setBackground(comp.getBackground());
    compPanel.setBorder(new EmptyBorder(2, 2, 2, 2));
    return compPanel;
  }
}
