<commit_before>/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.util.projectWizard;

import com.intellij.facet.ui.ValidationResult;
import com.intellij.icons.AllIcons;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.wm.impl.welcomeScreen.AbstractActionWithPanel;
import com.intellij.openapi.wm.impl.welcomeScreen.FlatWelcomeFrame;
import com.intellij.platform.DirectoryProjectGenerator;
import com.intellij.platform.WebProjectGenerator;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.NullableConsumer;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

public class ProjectSettingsStepBase extends AbstractActionWithPanel implements DumbAware {
  protected final DirectoryProjectGenerator myProjectGenerator;
  private final NullableConsumer<ProjectSettingsStepBase> myCallback;
  protected TextFieldWithBrowseButton myLocationField;
  protected final File myProjectDirectory;
  private JButton myCreateButton;
  private JLabel myErrorLabel;

  public ProjectSettingsStepBase(DirectoryProjectGenerator projectGenerator,
                                 NullableConsumer<ProjectSettingsStepBase> callback) {
    super();
    getTemplatePresentation().setIcon(projectGenerator.getLogo());
    getTemplatePresentation().setText(projectGenerator.getName());
    myProjectGenerator = projectGenerator;
    myCallback = callback;
    myProjectDirectory = FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), "untitled", "");
  }

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
  }

  @Override
  public JPanel createPanel() {
    final JPanel basePanel = createBasePanel();
    initGeneratorListeners();
    registerValidators();

    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JPanel scrollPanel = new JPanel(new BorderLayout());

    myErrorLabel = new JLabel("");
    myErrorLabel.setForeground(JBColor.RED);
    myCreateButton = new JButton("Create");
    myCreateButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        boolean isValid = checkValid();
        if (isValid && myCallback != null) {
          final DialogWrapper dialog = DialogWrapper.findInstance(myCreateButton);
          if (dialog != null) {
            dialog.close(DialogWrapper.OK_EXIT_CODE);
          }
          myCallback.consume(ProjectSettingsStepBase.this);
        }
      }
    });
    myCreateButton.putClientProperty(DialogWrapper.DEFAULT_ACTION, Boolean.TRUE);

    scrollPanel.add(basePanel, BorderLayout.NORTH);
    final JPanel advancedSettings = createAdvancedSettings();
    if (advancedSettings != null) {
      scrollPanel.add(advancedSettings, BorderLayout.CENTER);
    }
    final JBScrollPane scrollPane = new JBScrollPane(scrollPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                                                      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);
    mainPanel.add(scrollPane, BorderLayout.CENTER);

    final JPanel bottomPanel = new JPanel(new BorderLayout());

    bottomPanel.add(myErrorLabel, BorderLayout.NORTH);
    bottomPanel.add(myCreateButton, BorderLayout.EAST);
    mainPanel.add(bottomPanel, BorderLayout.SOUTH);
    UIUtil.setBackgroundRecursively(mainPanel, FlatWelcomeFrame.getMainBackground());
    return mainPanel;
  }

  protected void initGeneratorListeners() {
    if (myProjectGenerator instanceof WebProjectTemplate) {
      ((WebProjectTemplate)myProjectGenerator).getPeer().addSettingsStateListener(new WebProjectGenerator.SettingsStateListener() {
        @Override
        public void stateChanged(boolean validSettings) {
          checkValid();
        }
      });
    }
  }

  protected Icon getIcon() {
    return myProjectGenerator.getLogo();
  }

  protected JPanel createBasePanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.SOUTHWEST;
    myLocationField = new TextFieldWithBrowseButton();
    myLocationField.setText(myProjectDirectory.toString());<commit_msg>Revert "use same background for dialog"<commit_after>/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.util.projectWizard;

import com.intellij.facet.ui.ValidationResult;
import com.intellij.icons.AllIcons;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.wm.impl.welcomeScreen.AbstractActionWithPanel;
import com.intellij.platform.DirectoryProjectGenerator;
import com.intellij.platform.WebProjectGenerator;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.NullableConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

public class ProjectSettingsStepBase extends AbstractActionWithPanel implements DumbAware {
  protected final DirectoryProjectGenerator myProjectGenerator;
  private final NullableConsumer<ProjectSettingsStepBase> myCallback;
  protected TextFieldWithBrowseButton myLocationField;
  protected final File myProjectDirectory;
  private JButton myCreateButton;
  private JLabel myErrorLabel;

  public ProjectSettingsStepBase(DirectoryProjectGenerator projectGenerator,
                                 NullableConsumer<ProjectSettingsStepBase> callback) {
    super();
    getTemplatePresentation().setIcon(projectGenerator.getLogo());
    getTemplatePresentation().setText(projectGenerator.getName());
    myProjectGenerator = projectGenerator;
    myCallback = callback;
    myProjectDirectory = FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), "untitled", "");
  }

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
  }

  @Override
  public JPanel createPanel() {
    final JPanel basePanel = createBasePanel();
    initGeneratorListeners();
    registerValidators();

    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JPanel scrollPanel = new JPanel(new BorderLayout());

    myErrorLabel = new JLabel("");
    myErrorLabel.setForeground(JBColor.RED);
    myCreateButton = new JButton("Create");
    myCreateButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        boolean isValid = checkValid();
        if (isValid && myCallback != null) {
          final DialogWrapper dialog = DialogWrapper.findInstance(myCreateButton);
          if (dialog != null) {
            dialog.close(DialogWrapper.OK_EXIT_CODE);
          }
          myCallback.consume(ProjectSettingsStepBase.this);
        }
      }
    });
    myCreateButton.putClientProperty(DialogWrapper.DEFAULT_ACTION, Boolean.TRUE);

    scrollPanel.add(basePanel, BorderLayout.NORTH);
    final JPanel advancedSettings = createAdvancedSettings();
    if (advancedSettings != null) {
      scrollPanel.add(advancedSettings, BorderLayout.CENTER);
    }
    final JBScrollPane scrollPane = new JBScrollPane(scrollPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                                                      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);
    mainPanel.add(scrollPane, BorderLayout.CENTER);

    final JPanel bottomPanel = new JPanel(new BorderLayout());

    bottomPanel.add(myErrorLabel, BorderLayout.NORTH);
    bottomPanel.add(myCreateButton, BorderLayout.EAST);
    mainPanel.add(bottomPanel, BorderLayout.SOUTH);
    return mainPanel;
  }

  protected void initGeneratorListeners() {
    if (myProjectGenerator instanceof WebProjectTemplate) {
      ((WebProjectTemplate)myProjectGenerator).getPeer().addSettingsStateListener(new WebProjectGenerator.SettingsStateListener() {
        @Override
        public void stateChanged(boolean validSettings) {
          checkValid();
        }
      });
    }
  }

  protected Icon getIcon() {
    return myProjectGenerator.getLogo();
  }

  protected JPanel createBasePanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.SOUTHWEST;
    myLocationField = new TextFieldWithBrowseButton();
    myLocationField.setText(myProjectDirectory.toString());
{'fraction_non_alphanumeric': 0.08737683584309351, 'fraction_numerical': 0.002230897936419409, 'mean_word_length': 4.1875602700096435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4268363', 'n_tokens_mistral': 2972, 'n_tokens_neox': 2884, 'n_words': 638}