public EncodingPanel(@NotNull final Project project) {
    super(project);
    update = new Alarm(this);
    myComponent =
        new TextPanel.ExtraSize() {
          @Override
          protected void paintComponent(@NotNull final Graphics g) {
            super.paintComponent(g);
            if (actionEnabled && getText() != null) {
              final Rectangle r = getBounds();
              final Insets insets = getInsets();
              Icon arrows = AllIcons.Ide.Statusbar_arrows;
              arrows.paintIcon(
                  this,
                  g,
                  r.width - insets.right - arrows.getIconWidth() - 2,
                  r.height / 2 - arrows.getIconHeight() / 2);
            }
          }
        };

    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent e, int clickCount) {
        update();
        showPopup(e);
        return true;
      }
    }.installOn(myComponent);
    myComponent.setBorder(WidgetBorder.WIDE);
  }
  private void update() {
    if (update.isDisposed()) return;

    update.cancelAllRequests();
    update.addRequest(
        () -> {
          if (isDisposed()) return;

          VirtualFile file = getSelectedFile();
          actionEnabled = false;
          String charsetName = null;
          Pair<Charset, String> check = null;

          if (file != null) {
            check = EncodingUtil.checkSomeActionEnabled(file);
            Charset charset = null;

            if (LoadTextUtil.wasCharsetDetectedFromBytes(file) != null) {
              charset = cachedCharsetFromContent(file);
            }

            if (charset == null) {
              charset = file.getCharset();
            }

            actionEnabled = check == null || check.second == null;

            if (!actionEnabled) {
              charset = check.first;
            }

            if (charset != null) {
              charsetName = charset.displayName();
            }
          }

          if (charsetName == null) {
            charsetName = "n/a";
          }

          String toolTipText;

          if (actionEnabled) {
            toolTipText = String.format("File Encoding%n%s", charsetName);

            myComponent.setForeground(UIUtil.getActiveTextColor());
            myComponent.setTextAlignment(Component.LEFT_ALIGNMENT);
          } else {
            String failReason = check == null ? "" : check.second;
            toolTipText = String.format("File encoding is disabled%n%s", failReason);

            myComponent.setForeground(UIUtil.getInactiveTextColor());
            myComponent.setTextAlignment(Component.CENTER_ALIGNMENT);
          }

          myComponent.setToolTipText(toolTipText);
          myComponent.setText(charsetName);

          if (myStatusBar != null) {
            myStatusBar.updateWidget(ID());
          }
        },
        200,
        ModalityState.any());
  }