package jetbrains.mps.ide.make.actions;

/*Generated by MPS */

import javax.swing.JPanel;
import javax.swing.JCheckBox;
import java.awt.GridBagLayout;
import javax.swing.border.EmptyBorder;
import com.intellij.notification.impl.NotificationsConfigurationImpl;
import jetbrains.mps.ide.common.LayoutUtil;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Computable;

/*package*/ class WidgetSettingsPanel extends JPanel {
  private final JCheckBox myShowPopupBox;
  public WidgetSettingsPanel() {
    super(new GridBagLayout());
    myShowPopupBox = new JCheckBox("Display balloon on generation", TransientModelBallonDisplayer.isPopupShown());
    myShowPopupBox.setBorder(new EmptyBorder(2, 3, 0, 4));
    myShowPopupBox.setEnabled(NotificationsConfigurationImpl.getInstanceImpl().SHOW_BALLOONS);

    add(myShowPopupBox, LayoutUtil.createFieldConstraints(1));
  }
  public void showComponent(RelativePoint point) {
    final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(this, this).setRequestFocus(true).setMovable(true).setCancelCallback(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        onClose();
        return Boolean.TRUE;
      }
    }).createPopup();
    popup.show(point);
  }
  private void onClose() {
    TransientModelBallonDisplayer.setShowPopup(myShowPopupBox.isSelected());
  }
}
