private void setHeaderComponent(JComponent c) {
    boolean doRevalidate = false;
    if (myHeaderComponent != null) {
      myHeaderPanel.remove(myHeaderComponent);
      myHeaderPanel.add(myCaption, BorderLayout.NORTH);
      myHeaderComponent = null;
      doRevalidate = true;
    }

    if (c != null) {
      myHeaderPanel.remove(myCaption);
      myHeaderPanel.add(c, BorderLayout.NORTH);
      myHeaderComponent = c;

      final Dimension size = myContent.getSize();
      if (size.height < c.getPreferredSize().height * 2) {
        size.height += c.getPreferredSize().height;
        setSize(size);
      }

      doRevalidate = true;
    }

    if (doRevalidate) myContent.revalidate();
  }
  public InjectionsSettingsUI(final Project project, final Configuration configuration) {
    myProject = project;
    myConfiguration = configuration;

    final CfgInfo currentInfo = new CfgInfo(configuration, "Project");
    myInfos =
        configuration instanceof Configuration.Prj
            ? new CfgInfo[] {
              new CfgInfo(((Configuration.Prj) configuration).getParentConfiguration(), "IDE"),
              currentInfo
            }
            : new CfgInfo[] {currentInfo};

    myRoot = new JPanel(new BorderLayout());

    myInjectionsTable = new InjectionsTable(getInjInfoList(myInfos));
    myInjectionsTable.getEmptyText().setText("No injections configured");

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myInjectionsTable);
    createActions(decorator);

    // myRoot.add(new TitledSeparator("Languages injection places"), BorderLayout.NORTH);
    myRoot.add(decorator.createPanel(), BorderLayout.CENTER);
    myCountLabel = new JLabel();
    myCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    myCountLabel.setForeground(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.getFgColor());
    myRoot.add(myCountLabel, BorderLayout.SOUTH);
    updateCountLabel();
  }
  private void ensurePresentation() {
    if (myCurrentHorizontal != myConfiguration.SHORT_DIFF_HORISONTALLY) {
      final DiffPanel panel = getCurrentPanel();

      myPanel.removeAll();
      myPanel.add(myTopPanel, BorderLayout.NORTH);
      myPanel.add(panel.getComponent(), BorderLayout.CENTER);
      myPanel.revalidate();
      myPanel.repaint();

      myCurrentHorizontal = myConfiguration.SHORT_DIFF_HORISONTALLY;
    }
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   JPanel result = new JPanel(new BorderLayout());
   JLabel label = new JLabel("Lines around:");
   label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0));
   JPanel wrapper = new JPanel(new BorderLayout());
   wrapper.add(label, BorderLayout.NORTH);
   result.add(wrapper, BorderLayout.WEST);
   final JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 1);
   slider.setMinorTickSpacing(1);
   slider.setPaintTicks(true);
   slider.setPaintTrack(true);
   slider.setSnapToTicks(true);
   UIUtil.setSliderIsFilled(slider, true);
   slider.setPaintLabels(true);
   slider.setLabelTable(LABELS);
   result.add(slider, BorderLayout.CENTER);
   final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject);
   for (int i = 0; i < ourMarks.length; i++) {
     int mark = ourMarks[i];
     if (mark == configuration.SHORT_DIFF_EXTRA_LINES) {
       slider.setValue(i + 1);
     }
   }
   JBPopup popup =
       JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).createPopup();
   popup.setFinalRunnable(
       new Runnable() {
         @Override
         public void run() {
           int value = slider.getModel().getValue();
           if (configuration.SHORT_DIFF_EXTRA_LINES != ourMarks[value - 1]) {
             configuration.SHORT_DIFF_EXTRA_LINES = ourMarks[value - 1];
             myFragmentedContent.recalculate();
             refreshData(myFragmentedContent);
           }
         }
       });
   InputEvent inputEvent = e.getInputEvent();
   if (inputEvent instanceof MouseEvent) {
     int width = result.getPreferredSize().width;
     MouseEvent inputEvent1 = (MouseEvent) inputEvent;
     Point point1 = new Point(inputEvent1.getX() - width / 2, inputEvent1.getY());
     RelativePoint point = new RelativePoint(inputEvent1.getComponent(), point1);
     popup.show(point);
   } else {
     popup.showInBestPositionFor(e.getDataContext());
   }
 }
    private JComponent createActionPanel() {
      JPanel actions = new NonOpaquePanel();
      actions.setBorder(JBUI.Borders.emptyLeft(10));
      actions.setLayout(new BoxLayout(actions, BoxLayout.Y_AXIS));
      ActionManager actionManager = ActionManager.getInstance();
      ActionGroup quickStart =
          (ActionGroup) actionManager.getAction(IdeActions.GROUP_WELCOME_SCREEN_QUICKSTART);
      DefaultActionGroup group = new DefaultActionGroup();
      collectAllActions(group, quickStart);

      for (AnAction action : group.getChildren(null)) {
        JPanel button = new JPanel(new BorderLayout());
        button.setOpaque(false);
        button.setBorder(JBUI.Borders.empty(8, 20));
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                action,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        action.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isVisible()) {
          String text = presentation.getText();
          if (text != null && text.endsWith("...")) {
            text = text.substring(0, text.length() - 3);
          }
          Icon icon = presentation.getIcon();
          if (icon.getIconHeight() != JBUI.scale(16) || icon.getIconWidth() != JBUI.scale(16)) {
            icon = JBUI.emptyIcon(16);
          }
          action = wrapGroups(action);
          ActionLink link = new ActionLink(text, icon, action, createUsageTracker(action));
          link.setPaintUnderline(false);
          link.setNormalColor(getLinkNormalColor());
          button.add(link);
          if (action instanceof WelcomePopupAction) {
            button.add(createArrow(link), BorderLayout.EAST);
          }
          installFocusable(button, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, true);
          actions.add(button);
        }
      }

      WelcomeScreenActionsPanel panel = new WelcomeScreenActionsPanel();
      panel.actions.add(actions);
      return panel.root;
    }
  private JPanel readSplitter(
      JPanel panel, Element splitterElement, Ref<EditorWindow> currentWindow) {
    final boolean orientation =
        "vertical".equals(splitterElement.getAttributeValue("split-orientation"));
    final float proportion =
        Float.valueOf(splitterElement.getAttributeValue("split-proportion")).floatValue();
    final Element first = splitterElement.getChild("split-first");
    final Element second = splitterElement.getChild("split-second");

    Splitter splitter;
    if (panel == null) {
      panel = new JPanel(new BorderLayout());
      panel.setOpaque(false);
      splitter = new Splitter(orientation, proportion, 0.1f, 0.9f);
      panel.add(splitter, BorderLayout.CENTER);
      splitter.setFirstComponent(readExternalPanel(first, null, currentWindow));
      splitter.setSecondComponent(readExternalPanel(second, null, currentWindow));
    } else if (panel.getComponent(0) instanceof Splitter) {
      splitter = (Splitter) panel.getComponent(0);
      readExternalPanel(first, (JPanel) splitter.getFirstComponent(), currentWindow);
      readExternalPanel(second, (JPanel) splitter.getSecondComponent(), currentWindow);
    } else {
      readExternalPanel(first, panel, currentWindow);
      readExternalPanel(second, panel, currentWindow);
    }
    return panel;
  }
 private JComponent createRecentProjects() {
   JPanel panel = new JPanel(new BorderLayout());
   panel.add(new NewRecentProjectPanel(this), BorderLayout.CENTER);
   panel.setBackground(getProjectsBackground());
   panel.setBorder(new CustomLineBorder(getSeparatorColor(), JBUI.insetsRight(1)));
   return panel;
 }
  private Content getOrCreateConsoleContent(final ContentManager contentManager) {
    final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name");
    Content content = contentManager.findContent(displayName);
    if (content == null) {
      releaseEditor();
      final EditorFactory editorFactory = EditorFactory.getInstance();
      final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""), myProject);
      EditorSettings editorSettings = editor.getSettings();
      editorSettings.setLineMarkerAreaShown(false);
      editorSettings.setIndentGuidesShown(false);
      editorSettings.setLineNumbersShown(false);
      editorSettings.setFoldingOutlineShown(false);

      ((EditorEx) editor).getScrollPane().setBorder(null);
      myEditorAdapter = new EditorAdapter(editor, myProject, false);
      final JPanel panel = new JPanel(new BorderLayout());
      panel.add(editor.getComponent(), BorderLayout.CENTER);

      content = ContentFactory.SERVICE.getInstance().createContent(panel, displayName, true);
      contentManager.addContent(content);

      for (Pair<String, TextAttributes> pair : myPendingOutput) {
        myEditorAdapter.appendString(pair.first, pair.second);
      }
      myPendingOutput.clear();
    }
    return content;
  }
  public InfoAndProgressPanel() {

    setOpaque(false);

    myRefreshIcon = new RefreshFileSystemIcon();
    //  new AsyncProcessIcon("Refreshing filesystem") {
    //  protected Icon getPassiveIcon() {
    //    return myEmptyRefreshIcon;
    //  }
    //
    //  @Override
    //  public Dimension getPreferredSize() {
    //    if (!isRunning()) return new Dimension(0, 0);
    //    return super.getPreferredSize();
    //  }
    //
    //  @Override
    //  public void paint(Graphics g) {
    //    g.translate(0, -1);
    //    super.paint(g);
    //    g.translate(0, 1);
    //  }
    // };

    myRefreshIcon.setPaintPassiveIcon(false);

    myRefreshAndInfoPanel.setLayout(new BorderLayout());
    myRefreshAndInfoPanel.setOpaque(false);
    myRefreshAndInfoPanel.add(myRefreshIcon, BorderLayout.WEST);
    myRefreshAndInfoPanel.add(myInfoPanel, BorderLayout.CENTER);

    myProgressIcon = new AsyncProcessIcon("Background process");
    myProgressIcon.setOpaque(false);

    myProgressIcon.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            handle(e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            handle(e);
          }
        });

    myProgressIcon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    myProgressIcon.setBorder(StatusBarWidget.WidgetBorder.INSTANCE);
    myProgressIcon.setToolTipText(ActionsBundle.message("action.ShowProcessWindow.double.click"));

    myUpdateQueue =
        new MergingUpdateQueue("Progress indicator", 50, true, MergingUpdateQueue.ANY_COMPONENT);
    myPopup = new ProcessPopup(this);

    setRefreshVisible(false);

    restoreEmptyStatus();
  }
  public void setConsoleEditorEnabled(boolean consoleEditorEnabled) {
    if (isConsoleEditorEnabled() == consoleEditorEnabled) return;
    final FileEditorManagerEx fileManager = FileEditorManagerEx.getInstanceEx(getProject());
    if (consoleEditorEnabled) {
      fileManager.closeFile(myVirtualFile);
      myPanel.removeAll();
      myPanel.add(myHistoryViewer.getComponent());
      myPanel.add(myConsoleEditor.getComponent());

      myHistoryViewer.setHorizontalScrollbarVisible(false);
      myCurrentEditor = myConsoleEditor;
    } else {
      myPanel.removeAll();
      myPanel.add(myHistoryViewer.getComponent(), BorderLayout.CENTER);
      myHistoryViewer.setHorizontalScrollbarVisible(true);
    }
  }
    private JComponent createSettingsAndDocs() {
      JPanel panel = new NonOpaquePanel(new BorderLayout());
      NonOpaquePanel toolbar = new NonOpaquePanel();
      AnAction register = ActionManager.getInstance().getAction("Register");
      boolean registeredVisible = false;
      if (register != null) {
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                register,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        register.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isEnabled()) {
          ActionLink registerLink = new ActionLink("Register", register);
          registerLink.setNormalColor(getLinkNormalColor());
          NonOpaquePanel button = new NonOpaquePanel(new BorderLayout());
          button.setBorder(JBUI.Borders.empty(4, 10));
          button.add(registerLink);
          installFocusable(button, register, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, true);
          NonOpaquePanel wrap = new NonOpaquePanel();
          wrap.setBorder(JBUI.Borders.emptyLeft(10));
          wrap.add(button);
          panel.add(wrap, BorderLayout.WEST);
          registeredVisible = true;
        }
      }

      toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
      toolbar.add(
          createActionLink(
              "Configure",
              IdeActions.GROUP_WELCOME_SCREEN_CONFIGURE,
              AllIcons.General.GearPlain,
              !registeredVisible));
      toolbar.add(createActionLink("Get Help", IdeActions.GROUP_WELCOME_SCREEN_DOC, null, false));

      panel.add(toolbar, BorderLayout.EAST);

      panel.setBorder(JBUI.Borders.empty(0, 0, 8, 11));
      return panel;
    }
  private void buildInProcessCount() {
    removeAll();
    setLayout(new BorderLayout());

    final JPanel progressCountPanel = new JPanel(new BorderLayout(0, 0));
    progressCountPanel.setOpaque(false);
    String processWord = myOriginals.size() == 1 ? " process" : " processes";
    final LinkLabel label =
        new LinkLabel(
            myOriginals.size() + processWord + " running...",
            null,
            new LinkListener() {
              @Override
              public void linkSelected(final LinkLabel aSource, final Object aLinkData) {
                triggerPopupShowing();
              }
            });

    if (SystemInfo.isMac) label.setFont(UIUtil.getLabelFont().deriveFont(11.0f));

    label.setOpaque(false);

    final Wrapper labelComp = new Wrapper(label);
    labelComp.setOpaque(false);
    progressCountPanel.add(labelComp, BorderLayout.CENTER);

    // myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder());
    progressCountPanel.add(myProgressIcon, BorderLayout.WEST);

    add(myRefreshAndInfoPanel, BorderLayout.CENTER);

    progressCountPanel.setBorder(new EmptyBorder(0, 0, 0, 4));
    add(progressCountPanel, BorderLayout.EAST);

    revalidate();
    repaint();
  }
 public void setAdText(@NotNull final String s, int alignment) {
   if (myAdComponent == null) {
     myAdComponent =
         HintUtil.createAdComponent(s, BorderFactory.createEmptyBorder(1, 5, 1, 5), alignment);
     JPanel wrapper =
         new JPanel(new BorderLayout()) {
           @Override
           protected void paintComponent(Graphics g) {
             g.setColor(Gray._135);
             g.drawLine(0, 0, getWidth(), 0);
             super.paintComponent(g);
           }
         };
     wrapper.setOpaque(false);
     wrapper.setBorder(new EmptyBorder(1, 0, 0, 0));
     wrapper.add(myAdComponent, BorderLayout.CENTER);
     myContent.add(wrapper, BorderLayout.SOUTH);
     pack(false, true);
   } else {
     myAdComponent.setText(s);
     myAdComponent.setHorizontalAlignment(alignment);
   }
 }
  private JComponent createSouthPanel() {
    final JCheckBox checkBox = new JCheckBox(IdeBundle.message("checkbox.narrow.down.on.typing"));
    checkBox.setSelected(PropertiesComponent.getInstance().getBoolean(narrowDownPropertyKey, true));
    checkBox.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            myShouldNarrowDown = checkBox.isSelected();
            PropertiesComponent.getInstance()
                .setValue(narrowDownPropertyKey, Boolean.toString(myShouldNarrowDown));

            if (mySpeedSearch.isPopupActive()
                && !StringUtil.isEmpty(mySpeedSearch.getEnteredPrefix())) {
              myAbstractTreeBuilder.queueUpdate();
            }
          }
        });

    checkBox.setFocusable(false);
    UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, checkBox);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(checkBox, BorderLayout.WEST);
    return panel;
  }
  public void initComponents() {
    final EditorColorsScheme colorsScheme = myConsoleEditor.getColorsScheme();
    final DelegateColorScheme scheme =
        new DelegateColorScheme(colorsScheme) {
          @NotNull
          @Override
          public Color getDefaultBackground() {
            final Color color = getColor(ConsoleViewContentType.CONSOLE_BACKGROUND_KEY);
            return color == null ? super.getDefaultBackground() : color;
          }
        };
    myConsoleEditor.setColorsScheme(scheme);
    myHistoryViewer.setColorsScheme(scheme);
    myPanel.add(myHistoryViewer.getComponent());
    myPanel.add(myConsoleEditor.getComponent());
    setupComponents();
    DataManager.registerDataProvider(myPanel, new TypeSafeDataProviderAdapter(this));

    myHistoryViewer
        .getComponent()
        .addComponentListener(
            new ComponentAdapter() {
              public void componentResized(ComponentEvent e) {
                if (myForceScrollToEnd.getAndSet(false)) {
                  final JScrollBar scrollBar =
                      myHistoryViewer.getScrollPane().getVerticalScrollBar();
                  scrollBar.setValue(scrollBar.getMaximum());
                }
              }

              public void componentShown(ComponentEvent e) {
                componentResized(e);
              }
            });
    setPromptInner(myPrompt);
  }
  public void buildUi() {
    myTopPanel = new JPanel(new BorderLayout());
    final JPanel wrapper = new JPanel();
    // final BoxLayout boxLayout = new BoxLayout(wrapper, BoxLayout.X_AXIS);
    wrapper.setLayout(new BorderLayout());
    myTitleLabel.setBorder(BorderFactory.createEmptyBorder(1, 2, 0, 0));
    wrapper.add(myTitleLabel, BorderLayout.WEST);
    DefaultActionGroup dag = new DefaultActionGroup();
    myPreviousDiff.copyShortcutFrom(ActionManager.getInstance().getAction("PreviousDiff"));
    myNextDiff.copyShortcutFrom(ActionManager.getInstance().getAction("NextDiff"));
    dag.add(new MyChangeContextAction());
    dag.add(myPreviousDiff);
    dag.add(myNextDiff);
    myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myPanel);
    myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myPanel);

    dag.add(new PopupAction());
    ActionToolbar toolbar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, dag, true);
    wrapper.add(toolbar.getComponent(), BorderLayout.EAST);

    myTopPanel.add(wrapper, BorderLayout.CENTER);

    final JPanel wrapperDiffs = new JPanel(new GridBagLayout());
    final JPanel oneMore = new JPanel(new BorderLayout());
    oneMore.add(wrapperDiffs, BorderLayout.NORTH);

    myCurrentHorizontal = myConfiguration.SHORT_DIFF_HORISONTALLY;
    myHorizontal = createPanel(true);
    myVertical = createPanel(false);

    myPanel.add(myTopPanel, BorderLayout.NORTH);
    myPanel.add(getCurrentPanel().getComponent(), BorderLayout.CENTER);

    myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myParent);
    myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myParent);
  }
  public static Pair<JPanel, JBList> createActionGroupPanel(
      ActionGroup action, final JComponent parent, final Runnable backAction) {
    JPanel actionsListPanel = new JPanel(new BorderLayout());
    actionsListPanel.setBackground(getProjectsBackground());
    final JBList list = new JBList(action.getChildren(null));
    list.setBackground(getProjectsBackground());
    list.installCellRenderer(
        new NotNullFunction<AnAction, JComponent>() {
          final JLabel label = new JLabel();

          {
            label.setBorder(JBUI.Borders.empty(3, 7));
          }

          @NotNull
          @Override
          public JComponent fun(AnAction action) {
            label.setText(action.getTemplatePresentation().getText());
            Icon icon = action.getTemplatePresentation().getIcon();
            label.setIcon(icon);
            return label;
          }
        });
    JScrollPane pane = ScrollPaneFactory.createScrollPane(list, true);
    pane.setBackground(getProjectsBackground());
    actionsListPanel.add(pane, BorderLayout.CENTER);
    if (backAction != null) {
      final JLabel back = new JLabel(AllIcons.Actions.Back);
      back.setBorder(JBUI.Borders.empty(3, 7, 10, 7));
      back.setHorizontalAlignment(SwingConstants.LEFT);
      new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
          backAction.run();
          return true;
        }
      }.installOn(back);
      actionsListPanel.add(back, BorderLayout.SOUTH);
    }
    final Ref<Component> selected = Ref.create();
    final JPanel main = new JPanel(new BorderLayout());
    main.add(actionsListPanel, BorderLayout.WEST);

    ListSelectionListener selectionListener =
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
              // Update when a change has been finalized.
              // For instance, selecting an element with mouse fires two consecutive
              // ListSelectionEvent events.
              return;
            }
            if (!selected.isNull()) {
              main.remove(selected.get());
            }
            Object value = list.getSelectedValue();
            if (value instanceof AbstractActionWithPanel) {
              JPanel panel = ((AbstractActionWithPanel) value).createPanel();
              panel.setBorder(JBUI.Borders.empty(7, 10));
              selected.set(panel);
              main.add(selected.get());

              for (JButton button : UIUtil.findComponentsOfType(main, JButton.class)) {
                if (button.getClientProperty(DialogWrapper.DEFAULT_ACTION) == Boolean.TRUE) {
                  parent.getRootPane().setDefaultButton(button);
                  break;
                }
              }

              main.revalidate();
              main.repaint();
            }
          }
        };
    list.addListSelectionListener(selectionListener);
    if (backAction != null) {
      new AnAction() {
        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
          backAction.run();
        }
      }.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, main);
    }
    return Pair.create(main, list);
  }
  AbstractPopup init(
      final Project project,
      @NotNull final JComponent component,
      @Nullable final JComponent preferredFocusedComponent,
      final boolean requestFocus,
      final boolean focusable,
      final boolean forceHeavyweight,
      final boolean movable,
      final String dimensionServiceKey,
      final boolean resizable,
      @Nullable final String caption,
      @Nullable final Computable<Boolean> callback,
      final boolean cancelOnClickOutside,
      @Nullable final Set<JBPopupListener> listeners,
      final boolean useDimServiceForXYLocation,
      InplaceButton commandButton,
      @Nullable final IconButton cancelButton,
      @Nullable final MouseChecker cancelOnMouseOutCallback,
      final boolean cancelOnWindow,
      @Nullable final ActiveIcon titleIcon,
      final boolean cancelKeyEnabled,
      final boolean locateBycontent,
      final boolean placeWithinScreenBounds,
      @Nullable final Dimension minSize,
      float alpha,
      @Nullable MaskProvider maskProvider,
      boolean inStack,
      boolean modalContext,
      @Nullable Component[] focusOwners,
      @Nullable String adText,
      int adTextAlignment,
      final boolean headerAlwaysFocusable,
      @NotNull List<Pair<ActionListener, KeyStroke>> keyboardActions,
      Component settingsButtons,
      @Nullable final Processor<JBPopup> pinCallback,
      boolean mayBeParent,
      boolean showShadow) {
    if (requestFocus && !focusable) {
      assert false
          : "Incorrect argument combination: requestFocus="
              + requestFocus
              + " focusable="
              + focusable;
    }

    myActivityKey = new UiActivity.Focus("Popup:" + this);
    myProject = project;
    myComponent = component;
    myPopupBorder = PopupBorder.Factory.create(true, showShadow);
    myShadowed = showShadow;
    myPaintShadow =
        showShadow
            && !SystemInfo.isMac
            && !movable
            && !resizable
            && Registry.is("ide.popup.dropShadow");
    myContent = createContentPanel(resizable, myPopupBorder, isToDrawMacCorner() && resizable);
    myMayBeParent = mayBeParent;

    myContent.add(component, BorderLayout.CENTER);
    if (adText != null) {
      setAdText(adText, adTextAlignment);
    }

    myCancelKeyEnabled = cancelKeyEnabled;
    myLocateByContent = locateBycontent;
    myLocateWithinScreen = placeWithinScreenBounds;
    myAlpha = alpha;
    myMaskProvider = maskProvider;
    myInStack = inStack;
    myModalContext = modalContext;
    myFocusOwners = focusOwners;
    myHeaderAlwaysFocusable = headerAlwaysFocusable;
    myMovable = movable;

    ActiveIcon actualIcon = titleIcon == null ? new ActiveIcon(EmptyIcon.ICON_0) : titleIcon;

    myHeaderPanel = new JPanel(new BorderLayout());

    if (caption != null) {
      if (caption.length() > 0) {
        myCaption = new TitlePanel(actualIcon.getRegular(), actualIcon.getInactive());
        ((TitlePanel) myCaption).setText(caption);
      } else {
        myCaption = new CaptionPanel();
      }

      if (pinCallback != null) {
        myCaption.setButtonComponent(
            new InplaceButton(
                new IconButton(
                    "Pin",
                    IconLoader.getIcon("/general/autohideOff.png"),
                    IconLoader.getIcon("/general/autohideOff.png"),
                    IconLoader.getIcon("/general/autohideOffInactive.png")),
                new ActionListener() {
                  public void actionPerformed(final ActionEvent e) {
                    pinCallback.process(AbstractPopup.this);
                  }
                }));
      } else if (cancelButton != null) {
        myCaption.setButtonComponent(
            new InplaceButton(
                cancelButton,
                new ActionListener() {
                  public void actionPerformed(final ActionEvent e) {
                    cancel();
                  }
                }));
      } else if (commandButton != null) {
        myCaption.setButtonComponent(commandButton);
      }
    } else {
      myCaption = new CaptionPanel();
      myCaption.setBorder(null);
      myCaption.setPreferredSize(new Dimension(0, 0));
    }

    setWindowActive(myHeaderAlwaysFocusable);

    myHeaderPanel.add(myCaption, BorderLayout.NORTH);
    myContent.add(myHeaderPanel, BorderLayout.NORTH);

    myForcedHeavyweight = true;
    myResizable = resizable;
    myPreferredFocusedComponent = preferredFocusedComponent;
    myRequestFocus = requestFocus;
    myFocusable = focusable;
    myDimensionServiceKey = dimensionServiceKey;
    myCallBack = callback;
    myCancelOnClickOutside = cancelOnClickOutside;
    myCancelOnMouseOutCallback = cancelOnMouseOutCallback;
    myListeners = listeners == null ? new HashSet<JBPopupListener>() : listeners;
    myUseDimServiceForXYLocation = useDimServiceForXYLocation;
    myCancelOnWindow = cancelOnWindow;
    myMinSize = minSize;

    for (Pair<ActionListener, KeyStroke> pair : keyboardActions) {
      myContent.registerKeyboardAction(
          pair.getFirst(), pair.getSecond(), JComponent.WHEN_IN_FOCUSED_WINDOW);
    }

    if (settingsButtons != null) {
      myCaption.addSettingsComponent(settingsButtons);
    }

    return this;
  }
  private void buildInInlineIndicator(@NotNull final InlineProgressIndicator inline) {
    removeAll();
    setLayout(new InlineLayout());
    add(myRefreshAndInfoPanel);

    final JPanel inlinePanel = new JPanel(new BorderLayout());

    inline.getComponent().setBorder(new EmptyBorder(1, 0, 0, 2));
    final JComponent inlineComponent = inline.getComponent();
    inlineComponent.setOpaque(false);
    inlinePanel.add(inlineComponent, BorderLayout.CENTER);

    // myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder());
    inlinePanel.add(myProgressIcon, BorderLayout.WEST);

    inline.updateProgressNow();
    inlinePanel.setOpaque(false);

    add(inlinePanel);

    myRefreshAndInfoPanel.revalidate();
    myRefreshAndInfoPanel.repaint();

    if (UISettings.getInstance().PRESENTATION_MODE) {
      final JRootPane pane = myInfoPanel.getRootPane();
      final RelativePoint point = new RelativePoint(pane, new Point(pane.getWidth() - 250, 60));
      final PresentationModeProgressPanel panel = new PresentationModeProgressPanel(inline);
      final MyInlineProgressIndicator delegate =
          new MyInlineProgressIndicator(true, inline.getInfo(), inline) {
            @Override
            protected void updateProgress() {
              super.updateProgress();
              panel.update();
            }
          };

      Disposer.register(inline, delegate);

      JBPopupFactory.getInstance()
          .createBalloonBuilder(panel.getRootPanel())
          .setFadeoutTime(0)
          .setFillColor(Gray.TRANSPARENT)
          .setShowCallout(false)
          .setBorderColor(Gray.TRANSPARENT)
          .setBorderInsets(new Insets(0, 0, 0, 0))
          .setAnimationCycle(0)
          .setCloseButtonEnabled(false)
          .setHideOnClickOutside(false)
          .setDisposable(inline)
          .setHideOnFrameResize(false)
          .setHideOnKeyOutside(false)
          .setBlockClicksThroughBalloon(true)
          .setHideOnAction(false)
          .createBalloon()
          .show(
              new PositionTracker<Balloon>(pane) {
                @Override
                public RelativePoint recalculateLocation(Balloon object) {
                  final EditorComponentImpl editorComponent =
                      UIUtil.findComponentOfType(pane, EditorComponentImpl.class);
                  if (editorComponent != null) {
                    return new RelativePoint(
                        editorComponent.getParent().getParent(),
                        new Point(
                            editorComponent.getParent().getParent().getWidth() - 150,
                            editorComponent.getParent().getParent().getHeight() - 70));
                  }
                  return point;
                }
              },
              Balloon.Position.above);
    }
  }
  private void addCheckbox(final JPanel panel, final TreeAction action) {
    String text =
        action instanceof FileStructureFilter
            ? ((FileStructureFilter) action).getCheckBoxText()
            : action instanceof FileStructureNodeProvider
                ? ((FileStructureNodeProvider) action).getCheckBoxText()
                : null;

    if (text == null) return;

    Shortcut[] shortcuts =
        action instanceof FileStructureFilter
            ? ((FileStructureFilter) action).getShortcut()
            : ((FileStructureNodeProvider) action).getShortcut();

    final JCheckBox chkFilter = new JCheckBox();
    UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, chkFilter);

    final boolean selected = getDefaultValue(action);
    chkFilter.setSelected(selected);
    myTreeActionsOwner.setActionIncluded(
        action, action instanceof FileStructureFilter ? !selected : selected);
    chkFilter.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            final boolean state = chkFilter.isSelected();
            if (!myAutoClicked.contains(chkFilter)) {
              saveState(action, state);
            }
            myTreeActionsOwner.setActionIncluded(
                action, action instanceof FileStructureFilter ? !state : state);
            // final String filter = mySpeedSearch.isPopupActive() ?
            // mySpeedSearch.getEnteredPrefix() : null;
            // mySpeedSearch.hidePopup();
            Object selection =
                ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements());
            if (selection instanceof FilteringTreeStructure.FilteringNode) {
              selection = ((FilteringTreeStructure.FilteringNode) selection).getDelegate();
            }
            myTreeStructure.rebuildTree();
            myFilteringStructure.rebuild();

            final Object sel = selection;
            final Runnable runnable =
                new Runnable() {
                  public void run() {
                    ApplicationManager.getApplication()
                        .runReadAction(
                            new Runnable() {
                              @Override
                              public void run() {
                                myAbstractTreeBuilder
                                    .refilter(sel, true, false)
                                    .doWhenProcessed(
                                        new Runnable() {
                                          @Override
                                          public void run() {
                                            if (mySpeedSearch.isPopupActive()) {
                                              mySpeedSearch.refreshSelection();
                                            }
                                          }
                                        });
                              }
                            });
                  }
                };
            if (ApplicationManager.getApplication().isUnitTestMode()) {
              runnable.run();
            } else {
              ApplicationManager.getApplication().invokeLater(runnable);
            }
          }
        });
    chkFilter.setFocusable(false);

    if (shortcuts.length > 0) {
      text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          chkFilter.doClick();
        }
      }.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree);
    }
    chkFilter.setText(text);
    panel.add(chkFilter);
    myCheckBoxes.put(action.getClass(), chkFilter);
  }
  public JComponent createCenterPanel() {
    List<FileStructureFilter> fileStructureFilters = new ArrayList<FileStructureFilter>();
    List<FileStructureNodeProvider> fileStructureNodeProviders =
        new ArrayList<FileStructureNodeProvider>();
    if (myTreeActionsOwner != null) {
      for (Filter filter : myBaseTreeModel.getFilters()) {
        if (filter instanceof FileStructureFilter) {
          final FileStructureFilter fsFilter = (FileStructureFilter) filter;
          myTreeActionsOwner.setActionIncluded(fsFilter, true);
          fileStructureFilters.add(fsFilter);
        }
      }

      if (myBaseTreeModel instanceof ProvidingTreeModel) {
        for (NodeProvider provider : ((ProvidingTreeModel) myBaseTreeModel).getNodeProviders()) {
          if (provider instanceof FileStructureNodeProvider) {
            fileStructureNodeProviders.add((FileStructureNodeProvider) provider);
          }
        }
      }
    }
    final JPanel panel = new JPanel(new BorderLayout());
    JPanel comboPanel = new JPanel(new GridLayout(0, 2, 0, 0));

    final Shortcut[] F4 =
        ActionManager.getInstance()
            .getAction(IdeActions.ACTION_EDIT_SOURCE)
            .getShortcutSet()
            .getShortcuts();
    final Shortcut[] ENTER = CustomShortcutSet.fromString("ENTER").getShortcuts();
    final CustomShortcutSet shortcutSet = new CustomShortcutSet(ArrayUtil.mergeArrays(F4, ENTER));
    new AnAction() {
      public void actionPerformed(AnActionEvent e) {
        final boolean succeeded = navigateSelectedElement();
        if (succeeded) {
          unregisterCustomShortcutSet(panel);
        }
      }
    }.registerCustomShortcutSet(shortcutSet, panel);

    new AnAction() {
      public void actionPerformed(AnActionEvent e) {
        if (mySpeedSearch != null && mySpeedSearch.isPopupActive()) {
          mySpeedSearch.hidePopup();
        } else {
          myPopup.cancel();
        }
      }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("ESCAPE"), myTree);

    new ClickListener() {
      @Override
      public boolean onClick(MouseEvent e, int clickCount) {
        navigateSelectedElement();
        return true;
      }
    }.installOn(myTree);

    for (FileStructureFilter filter : fileStructureFilters) {
      addCheckbox(comboPanel, filter);
    }

    for (FileStructureNodeProvider provider : fileStructureNodeProviders) {
      addCheckbox(comboPanel, provider);
    }
    myPreferredWidth = Math.max(comboPanel.getPreferredSize().width, 350);
    panel.add(comboPanel, BorderLayout.NORTH);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree());
    scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.BOTTOM));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.add(createSouthPanel(), BorderLayout.SOUTH);
    DataManager.registerDataProvider(
        panel,
        new DataProvider() {
          @Override
          public Object getData(@NonNls String dataId) {
            if (PlatformDataKeys.PROJECT.is(dataId)) {
              return myProject;
            }
            if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
              final Object node =
                  ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements());
              if (!(node instanceof FilteringTreeStructure.FilteringNode)) return null;
              return getPsi((FilteringTreeStructure.FilteringNode) node);
            }
            if (LangDataKeys.POSITION_ADJUSTER_POPUP.is(dataId)) {
              return myPopup;
            }
            if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
              return myTreeExpander;
            }
            return null;
          }
        });

    return panel;
  }