<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions;

import com.intellij.codeInsight.hint.HintUtil;
import consulo.disposer.Disposable;
import com.intellij.openapi.MnemonicHelper;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.ui.ScrollingUtil;
import com.intellij.ui.WindowMoveListener;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.components.BorderLayoutPanel;
import consulo.awt.TargetAWT;
import consulo.ui.TextBoxWithExtensions;
import consulo.ui.shared.border.BorderStyle;

import javax.annotation.Nonnull;

import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.util.List;
import java.util.Optional;

public abstract class BigPopupUI extends BorderLayoutPanel implements Disposable {
  private static final int MINIMAL_SUGGESTIONS_LIST_HEIGHT = 100;

  protected final Project myProject;
  protected TextBoxWithExtensions mySearchField;
  protected JPanel suggestionsPanel;
  protected JBList<Object> myResultsList;
  protected JBPopup myHint;
  protected Runnable searchFinishedHandler = () -> {
  };
  protected final List<ViewTypeListener> myViewTypeListeners = ContainerUtil.createLockFreeCopyOnWriteList();
  protected ViewType myViewType = ViewType.SHORT;
  protected JLabel myHintLabel;

  public BigPopupUI(Project project) {
    myProject = project;
  }

  @Nonnull
  public abstract JBList<Object> createList();

  @Nonnull
  protected abstract ListCellRenderer<Object> createCellRenderer();

  @Nonnull
  protected abstract JPanel createTopLeftPanel();

  @Nonnull
  protected abstract JPanel createSettingsPanel();

  @Nonnull
  protected abstract String getInitialHint();

  protected void installScrollingActions() {
    ScrollingUtil.installActions(myResultsList, (JComponent)TargetAWT.to(getSearchField()));
  }

  //protected static class SearchField extends ExtendableTextField {
  //  public SearchField() {
  //    ExtendableTextField.Extension leftExtension = getLeftExtension();
  //    ExtendableTextField.Extension rightExtension = getRightExtension();
  //    if (leftExtension != null) {
  //      addExtension(leftExtension);
  //    }
  //    if (rightExtension != null) {
  //      addExtension(rightExtension);
  //    }
  //
  //    Insets insets = JBUI.CurrentTheme.BigPopup.searchFieldInsets();
  //    Border empty = JBUI.Borders.empty(insets.top, insets.left, insets.bottom, insets.right);
  //    Border topLine = JBUI.Borders.customLine(JBUI.CurrentTheme.BigPopup.searchFieldBorderColor(), 1, 0, 0, 0);
  //    setBorder(JBUI.Borders.merge(empty, topLine, true));
  //    setBackground(JBUI.CurrentTheme.BigPopup.searchFieldBackground());
  //    setFocusTraversalKeysEnabled(false);
  //
  //    if (Registry.is("new.search.everywhere.use.editor.font")) {
  //      Font editorFont = EditorUtil.getEditorFont();
  //      setFont(editorFont);
  //    }
  //
  //    int fontDelta = Registry.intValue("new.search.everywhere.font.size.delta");
  //    if (fontDelta != 0) {
  //      Font font = getFont();
  //      font = font.deriveFont((float)fontDelta + font.getSize());
  //      setFont(font);
  //    }
  //  }
  //
  //  @Override
  //  public Dimension getPreferredSize() {
  //    Dimension size = super.getPreferredSize();
  //    size.height = Integer.max(JBUIScale.scale(29), size.height);
  //    return size;
  //  }
  //
  //  @Nullable
  //  protected ExtendableTextField.Extension getRightExtension() {
  //    return null;
  //  }
  //
  //  @Nullable
  //  protected ExtendableTextField.Extension getLeftExtension() {
  //    return null;
  //  }
  //}

  @Nonnull
  protected TextBoxWithExtensions createSearchField() {
    return TextBoxWithExtensions.create();
  }

  public void init() {
    withBackground(JBUI.CurrentTheme.BigPopup.headerBackground());

    myResultsList = createList();

    JPanel topLeftPanel = createTopLeftPanel();
    JPanel settingsPanel = createSettingsPanel();
    mySearchField = createSearchField();
    mySearchField.addBorders(BorderStyle.EMPTY, null, 4);
    (TargetAWT.to(mySearchField)).setFocusTraversalKeysEnabled(false);
    suggestionsPanel = createSuggestionsPanel();

    myResultsList.setFocusable(false);
    myResultsList.setCellRenderer(createCellRenderer());

    if (Registry.is("new.search.everywhere.use.editor.font")) {
      Font editorFont = EditorUtil.getEditorFont();
      myResultsList.setFont(editorFont);
    }

    installScrollingActions();

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.setOpaque(false);
    topPanel.add(topLeftPanel, BorderLayout.WEST);
    topPanel.add(settingsPanel, BorderLayout.EAST);
    topPanel.add(TargetAWT.to(mySearchField), BorderLayout.SOUTH);

    WindowMoveListener moveListener = new WindowMoveListener(this);
    topPanel.addMouseListener(moveListener);
    topPanel.addMouseMotionListener(moveListener);

    addToTop(topPanel);
    addToCenter(suggestionsPanel);

    MnemonicHelper.init(this);
  }

  protected void addListDataListener(@Nonnull AbstractListModel<Object> model) {
    model.addListDataListener(new ListDataListener() {
      @Override
      public void intervalAdded(ListDataEvent e) {
        updateViewType(ViewType.FULL);
      }

      @Override
      public void intervalRemoved(ListDataEvent e) {
        if (myResultsList.isEmpty() && getSearchPattern().isEmpty()) {
          updateViewType(ViewType.SHORT);
        }<commit_msg>fix bottom border for bigpopup menu<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.actions;

import com.intellij.codeInsight.hint.HintUtil;
import consulo.disposer.Disposable;
import com.intellij.openapi.MnemonicHelper;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.ui.ScrollingUtil;
import com.intellij.ui.WindowMoveListener;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.components.BorderLayoutPanel;
import consulo.awt.TargetAWT;
import consulo.ui.TextBoxWithExtensions;
import consulo.ui.shared.border.BorderStyle;

import javax.annotation.Nonnull;

import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.util.List;
import java.util.Optional;

public abstract class BigPopupUI extends BorderLayoutPanel implements Disposable {
  private static final int MINIMAL_SUGGESTIONS_LIST_HEIGHT = 100;

  protected final Project myProject;
  protected TextBoxWithExtensions mySearchField;
  protected JPanel suggestionsPanel;
  protected JBList<Object> myResultsList;
  protected JBPopup myHint;
  protected Runnable searchFinishedHandler = () -> {
  };
  protected final List<ViewTypeListener> myViewTypeListeners = ContainerUtil.createLockFreeCopyOnWriteList();
  protected ViewType myViewType = ViewType.SHORT;
  protected JLabel myHintLabel;

  public BigPopupUI(Project project) {
    myProject = project;
  }

  @Nonnull
  public abstract JBList<Object> createList();

  @Nonnull
  protected abstract ListCellRenderer<Object> createCellRenderer();

  @Nonnull
  protected abstract JPanel createTopLeftPanel();

  @Nonnull
  protected abstract JPanel createSettingsPanel();

  @Nonnull
  protected abstract String getInitialHint();

  protected void installScrollingActions() {
    ScrollingUtil.installActions(myResultsList, (JComponent)TargetAWT.to(getSearchField()));
  }

  //protected static class SearchField extends ExtendableTextField {
  //  public SearchField() {
  //    ExtendableTextField.Extension leftExtension = getLeftExtension();
  //    ExtendableTextField.Extension rightExtension = getRightExtension();
  //    if (leftExtension != null) {
  //      addExtension(leftExtension);
  //    }
  //    if (rightExtension != null) {
  //      addExtension(rightExtension);
  //    }
  //
  //    Insets insets = JBUI.CurrentTheme.BigPopup.searchFieldInsets();
  //    Border empty = JBUI.Borders.empty(insets.top, insets.left, insets.bottom, insets.right);
  //    Border topLine = JBUI.Borders.customLine(JBUI.CurrentTheme.BigPopup.searchFieldBorderColor(), 1, 0, 0, 0);
  //    setBorder(JBUI.Borders.merge(empty, topLine, true));
  //    setBackground(JBUI.CurrentTheme.BigPopup.searchFieldBackground());
  //    setFocusTraversalKeysEnabled(false);
  //
  //    if (Registry.is("new.search.everywhere.use.editor.font")) {
  //      Font editorFont = EditorUtil.getEditorFont();
  //      setFont(editorFont);
  //    }
  //
  //    int fontDelta = Registry.intValue("new.search.everywhere.font.size.delta");
  //    if (fontDelta != 0) {
  //      Font font = getFont();
  //      font = font.deriveFont((float)fontDelta + font.getSize());
  //      setFont(font);
  //    }
  //  }
  //
  //  @Override
  //  public Dimension getPreferredSize() {
  //    Dimension size = super.getPreferredSize();
  //    size.height = Integer.max(JBUIScale.scale(29), size.height);
  //    return size;
  //  }
  //
  //  @Nullable
  //  protected ExtendableTextField.Extension getRightExtension() {
  //    return null;
  //  }
  //
  //  @Nullable
  //  protected ExtendableTextField.Extension getLeftExtension() {
  //    return null;
  //  }
  //}

  @Nonnull
  protected TextBoxWithExtensions createSearchField() {
    return TextBoxWithExtensions.create();
  }

  public void init() {
    withBackground(JBUI.CurrentTheme.BigPopup.headerBackground());

    myResultsList = createList();

    JPanel topLeftPanel = createTopLeftPanel();
    JPanel settingsPanel = createSettingsPanel();
    mySearchField = createSearchField();
    mySearchField.addBorders(BorderStyle.EMPTY, null, 4);
    (TargetAWT.to(mySearchField)).setFocusTraversalKeysEnabled(false);
    suggestionsPanel = createSuggestionsPanel();

    myResultsList.setFocusable(false);
    myResultsList.setCellRenderer(createCellRenderer());

    if (Registry.is("new.search.everywhere.use.editor.font")) {
      Font editorFont = EditorUtil.getEditorFont();
      myResultsList.setFont(editorFont);
    }

    installScrollingActions();

    JPanel top = new JPanel(new BorderLayout());
    top.setOpaque(false);
    top.add(topLeftPanel, BorderLayout.WEST);
    top.add(settingsPanel, BorderLayout.EAST);
    top.setBorder(JBUI.Borders.customLine(UIUtil.getBorderColor(), 0, 0, 1, 0));

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.setOpaque(false);
    topPanel.add(top, BorderLayout.NORTH);
    topPanel.add(TargetAWT.to(mySearchField), BorderLayout.SOUTH);

    WindowMoveListener moveListener = new WindowMoveListener(this);
    topPanel.addMouseListener(moveListener);
    topPanel.addMouseMotionListener(moveListener);

    addToTop(topPanel);
    addToCenter(suggestionsPanel);

    MnemonicHelper.init(this);
  }

  protected void addListDataListener(@Nonnull AbstractListModel<Object> model) {
    model.addListDataListener(new ListDataListener() {
      @Override
      public void intervalAdded(ListDataEvent e) {
        updateViewType(ViewType.FULL);
      }

      @Override
      public void intervalRemoved(ListDataEvent e) {
        if (myResultsList.isEmpty() && getSearchPattern().isEmpty()) {
          updateViewType(ViewType.SHORT);
        }
{'fraction_non_alphanumeric': 0.1134080052709603, 'fraction_numerical': 0.0037885027178389064, 'mean_word_length': 3.976639344262295, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7252554', 'n_tokens_mistral': 3791, 'n_tokens_neox': 3669, 'n_words': 664}