<commit_before>/*
 * Copyright 2000-2017 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.openapi.editor.impl;

import com.intellij.ide.ui.UISettings;
import com.intellij.ide.ui.UISettingsListener;
import com.intellij.ui.JBColor;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.tabs.JBTabsFactory;
import com.intellij.ui.tabs.newImpl.TabsHeightController;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

/**
 * @author gregsh
 */
public class EditorHeaderComponent extends JPanel implements UISettingsListener {
  public EditorHeaderComponent() {
    super(new BorderLayout(0, 0));
    uiSettingsChanged(UISettings.getInstance());
  }

  @Override
  public void paint(@NotNull Graphics g) {
    UISettings.setupAntialiasing(g);
    super.paint(g);
  }

  @Override
  public void uiSettingsChanged(UISettings uiSettings) {
    if(JBTabsFactory.getUseNewTabs()) {
      setBorder(new CustomLineBorder(JBColor.border(), 0, 0, 1, 0));
    } else {
      boolean topBorderRequired = uiSettings.getEditorTabPlacement() != SwingConstants.TOP &&
                                  (uiSettings.getShowNavigationBar() || uiSettings.getShowMainToolbar());
      setBorder(new CustomLineBorder(JBColor.border(), topBorderRequired ? 1 : 0, 0, 1, 0));
    }
  }

  @Override
  public Dimension getPreferredSize() {
    if(JBTabsFactory.getUseNewTabs()) {
      Dimension size = super.getPreferredSize();
      Insets insets = getInsets();
      int tabsHeight = TabsHeightController.getToolWindowHeight() - insets.top - insets.bottom;
      return tabsHeight > size.height ? new Dimension(size.width, tabsHeight) : size;
    } else {
      return super.getPreferredSize();
    }
  }
}<commit_msg>New tabs UI: There is no border between database console/table editor and Toolbar/Navigation bar when tabs are hidden (#IDEA-214996)<commit_after>/*
 * Copyright 2000-2017 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.openapi.editor.impl;

import com.intellij.ide.ui.UISettings;
import com.intellij.ide.ui.UISettingsListener;
import com.intellij.ui.JBColor;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.tabs.JBTabsFactory;
import com.intellij.ui.tabs.newImpl.TabsHeightController;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

/**
 * @author gregsh
 */
public class EditorHeaderComponent extends JPanel implements UISettingsListener {
  public EditorHeaderComponent() {
    super(new BorderLayout(0, 0));
    uiSettingsChanged(UISettings.getInstance());
  }

  @Override
  public void paint(@NotNull Graphics g) {
    UISettings.setupAntialiasing(g);
    super.paint(g);
  }

  @Override
  public void uiSettingsChanged(UISettings uiSettings) {
    boolean topBorderRequired = uiSettings.getShowNavigationBar() || uiSettings.getShowMainToolbar();

    if (JBTabsFactory.getUseNewTabs()) {
      topBorderRequired = uiSettings.getEditorTabPlacement() == 0 && topBorderRequired;
    }
    else {
      topBorderRequired = uiSettings.getEditorTabPlacement() != SwingConstants.TOP;
    }

    setBorder(new CustomLineBorder(JBColor.border(), topBorderRequired ? 1 : 0, 0, 1, 0));
  }

  @Override
  public Dimension getPreferredSize() {
    if (JBTabsFactory.getUseNewTabs()) {
      Dimension size = super.getPreferredSize();
      Insets insets = getInsets();
      int offset = UISettings.getInstance().getEditorTabPlacement() == 0 ? 0 : insets.top + insets.bottom;
      int tabsHeight = TabsHeightController.getToolWindowHeight() - offset;
      return tabsHeight > size.height ? new Dimension(size.width, tabsHeight) : size;
    }
    else {
      return super.getPreferredSize();
    }
  }
}
{'fraction_non_alphanumeric': 0.10256410256410256, 'fraction_numerical': 0.010631644777986242, 'mean_word_length': 4.0135841170323925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3407263', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1397, 'n_words': 383}