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 static Point getCenterOf(final Component aContainer, final JComponent content) {
    final JComponent component = getTargetComponent(aContainer);

    Point containerScreenPoint = component.getVisibleRect().getLocation();
    SwingUtilities.convertPointToScreen(containerScreenPoint, aContainer);

    return UIUtil.getCenterPoint(
        new Rectangle(containerScreenPoint, component.getVisibleRect().getSize()),
        content.getPreferredSize());
  }
 private static int getSplitCount(JComponent component) {
   if (component.getComponentCount() > 0) {
     final JComponent firstChild = (JComponent) component.getComponent(0);
     if (firstChild instanceof Splitter) {
       final Splitter splitter = (Splitter) firstChild;
       return getSplitCount(splitter.getFirstComponent())
           + getSplitCount(splitter.getSecondComponent());
     }
     return 1;
   }
   return 0;
 }
 public static Window setSize(JComponent content, final Dimension size) {
   final Window popupWindow = SwingUtilities.windowForComponent(content);
   final Point location = popupWindow.getLocation();
   popupWindow.setLocation(location.x, location.y);
   Insets insets = content.getInsets();
   if (insets != null) {
     size.width += insets.left + insets.right;
     size.height += insets.top + insets.bottom;
   }
   content.setPreferredSize(size);
   popupWindow.pack();
   return popupWindow;
 }
  public boolean isToDrawMacCorner() {
    if (!SystemInfo.isMac || myComponent.getComponentCount() <= 0) {
      return false;
    }

    if (myComponent.getComponentCount() > 0) {
      Component component = myComponent.getComponent(0);
      if (component instanceof JComponent
          && Boolean.TRUE.equals(((JComponent) component).getClientProperty(SUPPRESS_MAC_CORNER))) {
        return false;
      }
    }

    return true;
  }
  private void _requestFocus() {
    if (!myFocusable) return;

    if (myPreferredFocusedComponent != null) {
      myPreferredFocusedComponent.requestFocus();
    }
  }
  public void assertIsDispatchThread(@Nullable final JComponent component) {
    if (component == null) return;

    Thread curThread = Thread.currentThread();
    if (ourDispatchThread == curThread) {
      return;
    }

    if (Boolean.TRUE.equals(component.getClientProperty(WAS_EVER_SHOWN))) {
      assertIsDispatchThread();
    } else {
      final JRootPane root = component.getRootPane();
      if (root != null) {
        component.putClientProperty(WAS_EVER_SHOWN, Boolean.TRUE);
        assertIsDispatchThread();
      }
    }
  }
 private static Component setLabelColors(
     final Component label, final JTable table, final boolean isSelected, final int row) {
   if (label instanceof JComponent) {
     ((JComponent) label).setOpaque(true);
   }
   label.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   label.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
   return label;
 }
 private RelativePoint relativePointWithDominantRectangle(
     final JLayeredPane layeredPane, final Rectangle bounds) {
   Dimension preferredSize = getComponent().getPreferredSize();
   if (myDimensionServiceKey != null) {
     final Dimension dimension =
         DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
     if (dimension != null) {
       preferredSize = dimension;
     }
   }
   final Point leftTopCorner = new Point(bounds.x + bounds.width, bounds.y);
   final Point leftTopCornerScreen = (Point) leftTopCorner.clone();
   SwingUtilities.convertPointToScreen(leftTopCornerScreen, layeredPane);
   final RelativePoint relativePoint;
   if (!ScreenUtil.isOutsideOnTheRightOFScreen(
       new Rectangle(
           leftTopCornerScreen.x,
           leftTopCornerScreen.y,
           preferredSize.width,
           preferredSize.height))) {
     relativePoint = new RelativePoint(layeredPane, leftTopCorner);
   } else {
     if (bounds.x > preferredSize.width) {
       relativePoint =
           new RelativePoint(layeredPane, new Point(bounds.x - preferredSize.width, bounds.y));
     } else {
       setDimensionServiceKey(null); // going to cut width
       Rectangle screen =
           ScreenUtil.getScreenRectangle(leftTopCornerScreen.x, leftTopCornerScreen.y);
       final int spaceOnTheLeft = bounds.x;
       final int spaceOnTheRight = (screen.x + screen.width) - leftTopCornerScreen.x;
       if (spaceOnTheLeft > spaceOnTheRight) {
         relativePoint = new RelativePoint(layeredPane, new Point(0, bounds.y));
         myComponent.setPreferredSize(
             new Dimension(spaceOnTheLeft, Math.max(preferredSize.height, 200)));
       } else {
         relativePoint = new RelativePoint(layeredPane, leftTopCorner);
         myComponent.setPreferredSize(
             new Dimension(spaceOnTheRight, Math.max(preferredSize.height, 200)));
       }
     }
   }
   return relativePoint;
 }
  public void cancel(InputEvent e) {
    if (isDisposed()) return;

    if (myPopup != null) {
      if (!canClose()) {
        return;
      }
      storeDimensionSize(myContent.getSize());
      if (myUseDimServiceForXYLocation) {
        final JRootPane root = myComponent.getRootPane();
        if (root != null) {
          final Container popupWindow = root.getParent();
          if (popupWindow != null && popupWindow.isShowing()) {
            storeLocation(popupWindow.getLocationOnScreen());
          }
        }
      }

      if (e instanceof MouseEvent) {
        IdeEventQueue.getInstance().blockNextEvents(((MouseEvent) e));
      }

      myPopup.hide(false);

      if (ApplicationManagerEx.getApplicationEx() != null) {
        StackingPopupDispatcher.getInstance().onPopupHidden(this);
      }

      if (myInStack) {
        myFocusTrackback.setForcedRestore(!myOk && myFocusable);
        myFocusTrackback.restoreFocus();
      }

      disposePopup();

      if (myListeners != null) {
        for (JBPopupListener each : myListeners) {
          each.onClosed(new LightweightWindowEvent(this, myOk));
        }
      }
    }

    Disposer.dispose(this, false);
  }
    private void installFocusable(
        final JComponent comp,
        final AnAction action,
        final int prevKeyCode,
        final int nextKeyCode,
        final boolean focusListOnLeft) {
      comp.setFocusable(true);
      comp.setFocusTraversalKeysEnabled(true);
      comp.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
              final JList list =
                  UIUtil.findComponentOfType(FlatWelcomeFrame.this.getComponent(), JList.class);
              if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                InputEvent event = e;
                if (e.getComponent() instanceof JComponent) {
                  ActionLink link =
                      UIUtil.findComponentOfType((JComponent) e.getComponent(), ActionLink.class);
                  if (link != null) {
                    event =
                        new MouseEvent(
                            link,
                            MouseEvent.MOUSE_CLICKED,
                            e.getWhen(),
                            e.getModifiers(),
                            0,
                            0,
                            1,
                            false,
                            MouseEvent.BUTTON1);
                  }
                }
                action.actionPerformed(
                    AnActionEvent.createFromAnAction(
                        action,
                        event,
                        ActionPlaces.WELCOME_SCREEN,
                        DataManager.getInstance().getDataContext()));
              } else if (e.getKeyCode() == prevKeyCode) {
                focusPrev(comp);
              } else if (e.getKeyCode() == nextKeyCode) {
                focusNext(comp);
              } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                if (focusListOnLeft) {
                  if (list != null) {
                    list.requestFocus();
                  }
                } else {
                  focusPrev(comp);
                }
              } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                focusNext(comp);
              }
            }
          });
      comp.addFocusListener(
          new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
              comp.setOpaque(true);
              comp.setBackground(getActionLinkSelectionColor());
            }

            @Override
            public void focusLost(FocusEvent e) {
              comp.setOpaque(false);
              comp.setBackground(getMainBackground());
            }
          });
    }
  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);
    }
  }
 public static void suppressMacCornerFor(JComponent popupComponent) {
   popupComponent.putClientProperty(SUPPRESS_MAC_CORNER, Boolean.TRUE);
 }