<commit_before>// Copyright 2000-2020 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.lightEdit.statusBar;

import com.intellij.ide.DataManager;
import com.intellij.ide.IdeTooltip;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.ide.lightEdit.LightEditCompatible;
import com.intellij.ide.lightEdit.LightEditService;
import com.intellij.ide.lightEdit.actions.LightEditOpenFileInProjectAction;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.ui.JBPopupMenu;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.text.HtmlChunk;
import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.ui.TooltipWithClickableLinks;
import com.intellij.ui.components.ActionLink;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.popup.PopupState;
import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.JBPoint;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.function.Supplier;

public class LightEditModeNotificationWidget implements CustomStatusBarWidget {

  private final PopupState<JPopupMenu> myPopupState = PopupState.forPopupMenu();

  public LightEditModeNotificationWidget() {
  }

  @Override
  public @NonNls @NotNull String ID() {
    return "light.edit.mode.notification";
  }

  @Override
  public void install(@NotNull StatusBar statusBar) {
  }

  @Override
  public void dispose() {
  }

  @Override
  public JComponent getComponent() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBag gc = new GridBag().nextLine().setDefaultFill(GridBagConstraints.VERTICAL).setDefaultWeightY(1.0);
    JBLabel label = new JBLabel(ApplicationBundle.message("light.edit.status.bar.notification.label.text"));
    panel.add(label, gc.next().insets(JBUI.insets(0, 7, 0, 5)));
    ActionLink actionLink = createActionLink();
    panel.add(actionLink, gc.next());
    panel.setOpaque(false);

    IdeTooltip tooltip = createTooltip(actionLink);
    IdeTooltipManager.getInstance().setCustomTooltip(label, tooltip);
    IdeTooltipManager.getInstance().setCustomTooltip(actionLink, tooltip);

    return panel;
  }

  private @NotNull ActionLink createActionLink() {
    ActionLink actionLink = new ActionLink();
    actionLink.setText(ApplicationBundle.message("light.edit.status.bar.notification.link.text"));
    actionLink.setDropDownLinkIcon();
    actionLink.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        showPopupMenu(actionLink);
      }
    });
    return actionLink;<commit_msg>light edit: reconfigure tooltip on UI theme change (IDEA-251566)<commit_after>// Copyright 2000-2020 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.lightEdit.statusBar;

import com.intellij.ide.DataManager;
import com.intellij.ide.IdeTooltip;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.ide.lightEdit.LightEditCompatible;
import com.intellij.ide.lightEdit.LightEditService;
import com.intellij.ide.lightEdit.actions.LightEditOpenFileInProjectAction;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.ui.JBPopupMenu;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.text.HtmlChunk;
import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.ui.TooltipWithClickableLinks;
import com.intellij.ui.components.ActionLink;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.popup.PopupState;
import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.JBPoint;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.function.Supplier;

public class LightEditModeNotificationWidget implements CustomStatusBarWidget {

  private final PopupState<JPopupMenu> myPopupState = PopupState.forPopupMenu();

  public LightEditModeNotificationWidget() {
  }

  @Override
  public @NonNls @NotNull String ID() {
    return "light.edit.mode.notification";
  }

  @Override
  public void install(@NotNull StatusBar statusBar) {
  }

  @Override
  public void dispose() {
  }

  @Override
  public JComponent getComponent() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBag gc = new GridBag().nextLine().setDefaultFill(GridBagConstraints.VERTICAL).setDefaultWeightY(1.0);
    JBLabel label = new JBLabel(ApplicationBundle.message("light.edit.status.bar.notification.label.text"));
    panel.add(label, gc.next().insets(JBUI.insets(0, 7, 0, 5)));
    ActionLink actionLink = createActionLink();
    panel.add(actionLink, gc.next());
    panel.setOpaque(false);

    configureTooltip(label, actionLink);
    ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(EditorColorsManager.TOPIC, scheme -> {
      configureTooltip(label, actionLink);
    });

    return panel;
  }

  private void configureTooltip(@NotNull JBLabel label, @NotNull ActionLink actionLink) {
    IdeTooltip tooltip = createTooltip(actionLink);
    IdeTooltipManager.getInstance().setCustomTooltip(label, tooltip);
    IdeTooltipManager.getInstance().setCustomTooltip(actionLink, tooltip);
  }

  private @NotNull ActionLink createActionLink() {
    ActionLink actionLink = new ActionLink();
    actionLink.setText(ApplicationBundle.message("light.edit.status.bar.notification.link.text"));
    actionLink.setDropDownLinkIcon();
    actionLink.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        showPopupMenu(actionLink);
      }
    });
    return actionLink;
{'fraction_non_alphanumeric': 0.10698164309359012, 'fraction_numerical': 0.005717724947336744, 'mean_word_length': 5.276676109537299, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5837063', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2049, 'n_words': 373}