static void showColorPickerPopup(final @Nullable Project project,
                                   @Nullable Color currentColor,
                                   final @NotNull ColorListener listener,
                                   @Nullable RelativePoint location,
                                   boolean showAlpha,
                                   boolean showAlphaAsPercent,
                                   final @Nullable ColorPickerPopupCloseListener popupCloseListener) {
    if( !isEnoughSpaceToShowPopup() || !Registry.is("ide.new.color.picker")) {
      Color color = showDialog(IdeFocusManager.getGlobalInstance().getFocusOwner(), IdeBundle.message("dialog.title.choose.color"),
                               currentColor, showAlpha, null, showAlphaAsPercent);
      if (color != null) {
        listener.colorChanged(color, null);
      }
      return;
    }
    Ref<LightCalloutPopup> ref = Ref.create();

    ColorListener colorListener = new ColorListener() {
      final Object groupId = new Object();
      final Alarm alarm = new Alarm();

      @Override
      public void colorChanged(final Color color, final Object source) {
        Runnable apply = () -> CommandProcessor.getInstance().executeCommand(project,
                                                                             () -> listener.colorChanged(color, source),
                                                                             IdeBundle.message("command.name.apply.color"),
                                                                             groupId);
        alarm.cancelAllRequests();
        Runnable request = () -> ApplicationManager.getApplication().invokeLaterOnWriteThread(apply);
        if (source instanceof ColorPipetteButton && ((ColorPipetteButton)source).getCurrentState() == ColorPipetteButton.PipetteState.UPDATING) {
          alarm.addRequest(request, 150);
        } else {
          request.run();
        }
      }
    };

    List<Color> recentColors = RecentColorsComponent.getRecentColors();
    ColorPickerBuilder builder = new ColorPickerBuilder(showAlpha, showAlphaAsPercent)
      .setOriginalColor(currentColor)
      .addSaturationBrightnessComponent()
      .addColorAdjustPanel(new MaterialGraphicalColorPipetteProvider())
      .addColorValuePanel().withFocus();
    if (!recentColors.isEmpty()) {
      builder/*.addSeparator()*/
        .addCustomComponent(new ColorPickerComponentProvider() {
          @Override
          public @NotNull JComponent createComponent(@NotNull ColorPickerModel colorPickerModel) {
            return new RecentColorsPalette(colorPickerModel, recentColors);
          }
        });
    }
      builder.addColorListener(colorListener,true)
      .addColorListener(new ColorListener() {
        @Override
        public void colorChanged(Color color, Object source) {
          updatePointer(ref);
        }
      }, true)
        .addColorListener(new ColorListener() {
          @Override
          public void colorChanged(Color color, Object source) {
            RecentColorsComponent.saveRecentColors(RecentColorsComponent.appendColor(color, recentColors, 20));
          }
        }, false)
      .focusWhenDisplay(true)
      .setFocusCycleRoot(true)
      .addKeyAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelPopup(ref))
      .addKeyAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), applyColor(ref))
      .setPopupCloseListener(popupCloseListener);
    LightCalloutPopup popup = builder.build();
    ref.set(popup);

    if (location == null) {
      location = new RelativePoint(MouseInfo.getPointerInfo().getLocation());
    }
    popup.show(location.getScreenPoint());
    updatePointer(ref);
  }
static void showColorPickerPopup(final @Nullable Project project,
                                   @Nullable Color currentColor,
                                   final @NotNull ColorListener listener,
                                   @Nullable RelativePoint location,
                                   boolean showAlpha,
                                   boolean showAlphaAsPercent,
                                   final @Nullable ColorPickerPopupCloseListener popupCloseListener)