package com.eddysystems.eddy;

import com.eddysystems.eddy.engine.Eddy;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.ui.HintHint;
import com.intellij.ui.JBColor;
import com.intellij.ui.LightweightHint;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;

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

class EddyHintLabel extends JPanel {
  private JEditorPane myPane;
  private SimpleColoredComponent myColored;
  private JLabel myIcon;

  public static final Color QUESTION_COLOR = new JBColor(new Color(181, 208, 251), new Color(55, 108, 137));
  public static final Color AUTOAPPLY_COLOR = new JBColor(new Color(255, 187, 200), new Color(252, 77, 120));

  EddyHintLabel() {
    setLayout(new BorderLayout());
  }

  EddyHintLabel(@NotNull SimpleColoredComponent component) {
    this();
    setText(component);
  }

  public void setText(@NotNull SimpleColoredComponent colored) {
    clearText();

    myColored = colored;
    add(myColored, BorderLayout.CENTER);

    setOpaque(true);
    setBackground(colored.getBackground());

    revalidate();
    repaint();
  }

  public void setText(String s, HintHint hintHint) {
    clearText();

    if (s != null) {
      myPane = IdeTooltipManager.initPane(s, hintHint, null);
      add(myPane, BorderLayout.CENTER);
    }

    setOpaque(true);
    setBackground(hintHint.getTextBackground());

    revalidate();
    repaint();
  }

  private void clearText() {
    if (myPane != null) {
      remove(myPane);
      myPane = null;
    }

    if (myColored != null) {
      remove(myColored);
      myColored = null;
    }
  }

  public void setIcon(Icon icon) {
    if (myIcon != null) {
      remove(myIcon);
    }

    myIcon = new JLabel(icon, SwingConstants.CENTER);
    myIcon.setVerticalAlignment(SwingConstants.TOP);

    add(myIcon, BorderLayout.WEST);

    revalidate();
    repaint();
  }

  @Override
  public String toString() {
    return "Hint: text='" + (myPane != null ? myPane.getText() : "") + '\'';
  }

  protected static LightweightHint makeHint(Eddy.Output output) {
    boolean auto = output.shouldAutoApply();

    final String hintText, text = output.bestTextAbbrev() + (output.single() ? "" : " (multiple options...)");

    if (auto) {
      hintText = ' ' + text + ' ' + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_ENTER));
    } else {
      hintText = ' ' + text + ' ' + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
    }

    HintHint hintHint = new HintHint().setTextBg(auto ? AUTOAPPLY_COLOR : QUESTION_COLOR)
      .setTextFg(JBColor.foreground())
      .setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD))
      .setAwtTooltip(true);

    final EddyHintLabel label = new EddyHintLabel();
    label.setIcon(EddyWidget.getIcon());
    label.setText(hintText, hintHint);

    return new LightweightHint(label);
  }

}

@@ -970,16 +970,22 @@
 ntLabel(
+final 
 @NotNull
@@ -1057,37 +1057,38 @@
 onent);%0A  %7D%0A%0A  p
-ublic
+rivate
  void setText(@N
@@ -1085,16 +1085,22 @@
 setText(
+final 
 @NotNull
@@ -1318,37 +1318,38 @@
 aint();%0A  %7D%0A%0A  p
-ublic
+rivate
  void setText(St
@@ -1350,17 +1350,32 @@
 ext(
+final 
 String 
-s,
+text, final
  Hin
@@ -1418,17 +1418,20 @@
     if (
-s
+text
  != null
@@ -1476,17 +1476,20 @@
 nitPane(
-s
+text
 , hintHi
@@ -1852,21 +1852,22 @@
   %7D%0A%0A  p
-ublic
+rivate
  void se
@@ -1872,16 +1872,22 @@
 setIcon(
+final 
 Icon ico
@@ -2296,16 +2296,22 @@
 akeHint(
+final 
 Eddy.Out
@@ -2328,16 +2328,22 @@
 ) %7B%0A    
+final 
 boolean 
@@ -2371,25 +2371,24 @@
 utoApply();%0A
-%0A
     final St
@@ -2395,18 +2395,8 @@
 ring
- hintText,
  tex
@@ -2480,30 +2480,24 @@
 %22);%0A
-%0A
     
-if (auto) %7B%0A     
+final String
  hin
@@ -2512,32 +2512,38 @@
 ' ' + text + ' '
+%0A     
  + KeymapUtil.ge
@@ -2599,32 +2599,50 @@
 nce().getAction(
+%0A          auto ? 
 IdeActions.ACTIO
@@ -2659,139 +2659,11 @@
 NTER
-));%0A    %7D else %7B%0A      hintText = ' ' + text + ' ' + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(
+ : 
 IdeA
@@ -2702,26 +2702,26 @@
 IONS));%0A
-    %7D%0A%0A   
+%0A    final
  HintHin

Use more private and final