com.intellij.ui.popup.AbstractPopup Java Examples

The following examples show how to use com.intellij.ui.popup.AbstractPopup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void bindHintHiding(LightweightHint hint, PopupBridge popupBridge) {
  AtomicBoolean inProcess = new AtomicBoolean();
  hint.addHintListener(e -> {
    if (hint.getUserData(DISABLE_BINDING) == null && inProcess.compareAndSet(false, true)) {
      try {
        AbstractPopup popup = popupBridge.getPopup();
        if (popup != null) {
          popup.cancel();
        }
      }
      finally {
        inProcess.set(false);
      }
    }
  });
  popupBridge.performOnCancel(() -> {
    if (hint.getUserData(DISABLE_BINDING) == null && inProcess.compareAndSet(false, true)) {
      try {
        hint.hide();
      }
      finally {
        inProcess.set(false);
      }
    }
  });
}
 
Example #2
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private AbstractPopup getCurrentHint() {
  if (myPopupReference == null) return null;
  AbstractPopup hint = myPopupReference.get();
  if (hint == null || !hint.isVisible()) {
    if (hint != null) {
      // hint's window might've been hidden by AWT without notifying us
      // dispose to remove the popup from IDE hierarchy and avoid leaking components
      hint.cancel();
    }
    myPopupReference = null;
    myCurrentEditor = null;
    myContext = null;
    return null;
  }
  return hint;
}
 
Example #3
Source File: ShowImplementationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateInBackground(Editor editor,
                                @Nullable PsiElement element,
                                @Nonnull ImplementationViewComponent component,
                                String title,
                                @Nonnull AbstractPopup popup,
                                @Nonnull Ref<UsageView> usageView) {
  final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef);
  if (updaterTask != null) {
    updaterTask.cancelTask();
  }

  if (element == null) return; //already found
  final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf(), component);
  task.init(popup, new ImplementationViewComponentUpdater(component, isIncludeAlwaysSelf() ? 1 : 0), usageView);

  myTaskRef = new WeakReference<>(task);
  ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}
 
Example #4
Source File: QuickDocUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static DocumentationComponent getActiveDocComponent(@Nonnull Project project) {
  DocumentationManager documentationManager = DocumentationManager.getInstance(project);
  DocumentationComponent component;
  JBPopup hint = documentationManager.getDocInfoHint();
  if (hint != null) {
    component = (DocumentationComponent)((AbstractPopup)hint).getComponent();
  }
  else if (documentationManager.hasActiveDockedDocWindow()) {
    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION);
    Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent();
    component = selectedContent == null ? null : (DocumentationComponent)selectedContent.getComponent();
  }
  else {
    component = EditorMouseHoverPopupManager.getInstance().getDocumentationComponent();
  }
  return component;
}
 
Example #5
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showHintInEditor(AbstractPopup hint, Editor editor, Context context) {
  closeHint();
  myMouseMovementTracker.reset();
  myKeepPopupOnMouseMove = false;
  editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, context.getPopupPosition(editor));
  try {
    PopupPositionManager.positionPopupInBestPosition(hint, editor, null);
  }
  finally {
    editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
  }
  Window window = hint.getPopupWindow();
  if (window != null) {
    window.setFocusableWindowState(true);
    IdeEventQueue.getInstance().addDispatcher(e -> {
      if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getSource() == window) {
        myKeepPopupOnMouseMove = true;
      }
      return false;
    }, hint);
  }
}
 
Example #6
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void scheduleProcessing(@Nonnull Editor editor, @Nonnull Context context, boolean updateExistingPopup, boolean forceShowing, boolean requestFocus) {
  ProgressIndicatorBase progress = new ProgressIndicatorBase();
  myCurrentProgress = progress;
  myAlarm.addRequest(() -> {
    ProgressManager.getInstance().executeProcessUnderProgress(() -> {
      Info info = context.calcInfo(editor);
      ApplicationManager.getApplication().invokeLater(() -> {
        if (progress != myCurrentProgress) {
          return;
        }

        myCurrentProgress = null;
        if (info == null || !editor.getContentComponent().isShowing() || (!forceShowing && isPopupDisabled(editor))) {
          return;
        }

        PopupBridge popupBridge = new PopupBridge();
        JComponent component = info.createComponent(editor, popupBridge, requestFocus);
        if (component == null) {
          closeHint();
        }
        else {
          if (updateExistingPopup && isHintShown()) {
            updateHint(component, popupBridge);
          }
          else {
            AbstractPopup hint = createHint(component, popupBridge, requestFocus);
            showHintInEditor(hint, editor, context);
            myPopupReference = new WeakReference<>(hint);
            myCurrentEditor = new WeakReference<>(editor);
          }
          myContext = context;
        }
      });
    }, progress);
  }, context.getShowingDelay());
}
 
Example #7
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void performWhenAvailable(@Nonnull Consumer<AbstractPopup> consumer) {
  if (popup == null) {
    consumers.add(consumer);
  }
  else {
    consumer.accept(popup);
  }
}
 
Example #8
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void closeHint() {
  AbstractPopup hint = getCurrentHint();
  if (hint != null) {
    hint.cancel();
  }
  myPopupReference = null;
  myCurrentEditor = null;
  myContext = null;
}
 
Example #9
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void rebuildPopup(@NotNull final UsageViewImpl usageView,
    @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes,
    @NotNull final JTable table, @NotNull final JBPopup popup,
    @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition,
    boolean findUsagesInProgress) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
  if (shouldShowMoreSeparator) {
    nodes.add(MORE_USAGES_SEPARATOR_NODE);
  }

  String title = presentation.getTabText();
  String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator,
      nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress);

  ((AbstractPopup) popup).setCaption(fullTitle);

  List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
  MyModel tableModel = setTableModel(table, usageView, data);
  List<UsageNode> existingData = tableModel.getItems();

  int row = table.getSelectedRow();

  int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
  if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
    TableScrollingUtil.ensureSelectionExists(table);
    newSelection = table.getSelectedRow();
  } else {
    table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
  }
  TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);

  setSizeAndDimensions(table, popup, popupPosition, data);
}
 
Example #10
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateHint(JComponent component, PopupBridge popupBridge) {
  AbstractPopup popup = getCurrentHint();
  if (popup != null) {
    WrapperPanel wrapper = (WrapperPanel)popup.getComponent();
    wrapper.setContent(component);
    validatePopupSize(popup);
    popupBridge.setPopup(popup);
  }
}
 
Example #11
Source File: FileStructurePopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void show() {
  JComponent panel = createCenterPanel();
  MnemonicHelper.init(panel);
  myTree.addTreeSelectionListener(__ -> {
    if (myPopup.isVisible()) {
      PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class);
      if (updateProcessor != null) {
        AbstractTreeNode node = getSelectedNode();
        updateProcessor.updatePopup(node);
      }
    }
  });

  myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTree).setTitle(myTitle).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true)
          .setMovable(true).setBelongsToGlobalPopupStack(true)
          //.setCancelOnClickOutside(false) //for debug and snapshots
          .setCancelOnOtherWindowOpen(true).setCancelKeyEnabled(false).setDimensionServiceKey(null, getDimensionServiceKey(), true).setCancelCallback(() -> myCanClose).setNormalWindowLevel(true)
          .createPopup();

  Disposer.register(myPopup, this);
  Disposer.register(myPopup, () -> {
    if (!myTreeHasBuilt.isDone()) {
      myTreeHasBuilt.setRejected();
    }
  });
  myTree.getEmptyText().setText("Loading...");
  myPopup.showCenteredInCurrentWindow(myProject);

  ((AbstractPopup)myPopup).setShowHints(true);

  IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);

  rebuildAndSelect(false, myInitialElement).onProcessed(path -> UIUtil.invokeLaterIfNeeded(() -> {
    TreeUtil.ensureSelection(myTree);
    myTreeHasBuilt.setDone();
    installUpdater();
  }));
}
 
Example #12
Source File: ListBackgroundUpdaterTask.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated please use {@link BackgroundUpdaterTask}
 */
@Deprecated
public void init(@Nonnull AbstractPopup popup, @Nonnull Object component, @Nonnull Ref<UsageView> usageView) {
  myPopup = popup;
  if (component instanceof JBList) {
    init((JBPopup)myPopup, new JBListUpdater((JBList)component), usageView);
  }
}
 
Example #13
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void registerSizeTracker() {
  AbstractPopup hint = myHint;
  if (hint == null || mySizeTrackerRegistered) return;
  mySizeTrackerRegistered = true;
  hint.addResizeListener(this::onManualResizing, this);
  ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, new AnActionListener() {
    @Override
    public void afterActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
      if (action instanceof WindowAction) onManualResizing();
    }
  });
}
 
Example #14
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void rebuildPopup(@NotNull final UsageViewImpl usageView,
    @NotNull final List<Usage> usages,
    @NotNull List<UsageNode> nodes,
    @NotNull final JTable table,
    @NotNull final JBPopup popup,
    @NotNull final UsageViewPresentation presentation,
    @NotNull final RelativePoint popupPosition,
    boolean findUsagesInProgress) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
  if (shouldShowMoreSeparator) {
    nodes.add(MORE_USAGES_SEPARATOR_NODE);
  }

  String title = presentation.getTabText();
  String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress);

  ((AbstractPopup)popup).setCaption(fullTitle);

  List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
  MyModel tableModel = setTableModel(table, usageView, data);
  List<UsageNode> existingData = tableModel.getItems();

  int row = table.getSelectedRow();

  int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
  if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
    TableScrollingUtil.ensureSelectionExists(table);
    newSelection = table.getSelectedRow();
  }
  else {
    table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
  }
  TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);

  setSizeAndDimensions(table, popup, popupPosition, data);
}
 
Example #15
Source File: AbstractExpandableItemsHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isHintsAllowed(Window window) {
  if (window instanceof RootPaneContainer) {
    final JRootPane pane = ((RootPaneContainer)window).getRootPane();
    if (pane != null) {
      return Boolean.TRUE.equals(pane.getClientProperty(AbstractPopup.SHOW_HINTS));
    }
  }
  return false;
}
 
Example #16
Source File: FocusManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getFocusedDescendantFor(Component comp) {
  final Component focused = getFocusOwner();
  if (focused == null) return null;

  if (focused == comp || SwingUtilities.isDescendingFrom(focused, comp)) return focused;

  List<JBPopup> popups = AbstractPopup.getChildPopups(comp);
  for (JBPopup each : popups) {
    if (each.isFocused()) return focused;
  }

  return null;
}
 
Example #17
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void validatePopupSize(@Nonnull AbstractPopup popup) {
  JComponent component = popup.getComponent();
  if (component != null) popup.setSize(component.getPreferredSize());
}
 
Example #18
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void showTextFieldPanel() {
  final JLayeredPane layeredPane = getLayeredPane();
  final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize();
  final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2;
  final int paneHeight = layeredPane.getHeight();
  final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2;

  ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField);
  builder.setLocateWithinScreenBounds(false);
  builder.setKeyEventHandler(event -> {
    if (myTextPopup == null || !AbstractPopup.isCloseRequest(event) || !myTextPopup.isCancelKeyEnabled()) {
      return false;
    }

    IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
    if (isDescendingFromTemporarilyFocusableToolWindow(focusManager.getFocusOwner())) {
      focusManager.requestFocus(myTextField, true);
      return false;
    }
    else {
      myTextPopup.cancel(event);
      return true;
    }
  }).setCancelCallback(() -> {
    myTextPopup = null;
    close(false);
    return Boolean.TRUE;
  }).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false);

  Point point = new Point(x, y);
  SwingUtilities.convertPointToScreen(point, layeredPane);
  Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height));
  myTextPopup = builder.createPopup();
  myTextPopup.setSize(bounds.getSize());
  myTextPopup.setLocation(bounds.getLocation());

  MnemonicHelper.init(myTextFieldPanel);
  if (myProject != null && !myProject.isDefault()) {
    DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup);
  }

  Disposer.register(myTextPopup, () -> cancelListUpdater());
  IdeEventQueue.getInstance().getPopupManager().closeAllPopups(false);
  myTextPopup.show(layeredPane);
}
 
Example #19
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@Nonnull JTable table, @Nonnull JBPopup popup, @Nonnull RelativePoint popupPosition, @Nonnull List<UsageNode> data) {
  JComponent content = popup.getContent();
  Window window = SwingUtilities.windowForComponent(content);
  Dimension d = window.getSize();

  int width = calcMaxWidth(table);
  width = (int)Math.max(d.getWidth(), width);
  Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize();
  width = Math.max((int)headerSize.getWidth(), width);
  width = Math.max(myWidth, width);

  if (myWidth == -1) myWidth = width;
  int newWidth = Math.max(width, d.width + width - myWidth);

  myWidth = newWidth;

  int rowsToShow = Math.min(30, data.size());
  Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
  Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
  if (!data.isEmpty()) {
    ScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(rectangle.getSize());
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);


  Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize();

  int footer = footerSize.height;
  int footerBorder = footer == 0 ? 0 : 1;
  Insets insets = ((AbstractPopup)popup).getPopupBorder().getBorderInsets(content);
  rectangle.height += headerSize.height + footer + footerBorder + insets.top + insets.bottom;
  ScreenUtil.fitToScreen(rectangle);
  Dimension newDim = rectangle.getSize();
  window.setBounds(rectangle);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
}
 
Example #20
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void rebuildTable(@Nonnull final UsageViewImpl usageView,
                          @Nonnull final List<Usage> usages,
                          @Nonnull List<UsageNode> nodes,
                          @Nonnull final JTable table,
                          @Nullable final JBPopup popup,
                          @Nonnull final UsageViewPresentation presentation,
                          @Nonnull final RelativePoint popupPosition,
                          boolean findUsagesInProgress,
                          @Nonnull AtomicInteger outOfScopeUsages,
                          @Nonnull SearchScope searchScope) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
  if (shouldShowMoreSeparator) {
    nodes.add(MORE_USAGES_SEPARATOR_NODE);
  }
  boolean hasOutsideScopeUsages = usages.contains(USAGES_OUTSIDE_SCOPE_SEPARATOR);
  if (hasOutsideScopeUsages && !shouldShowMoreSeparator) {
    nodes.add(USAGES_OUTSIDE_SCOPE_NODE);
  }

  String title = presentation.getTabText();
  String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator || hasOutsideScopeUsages,
                                  nodes.size() - (shouldShowMoreSeparator || hasOutsideScopeUsages ? 1 : 0), findUsagesInProgress);
  if (popup != null) {
    ((AbstractPopup)popup).setCaption(fullTitle);
  }

  List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
  MyModel tableModel = setTableModel(table, usageView, data, outOfScopeUsages, searchScope);
  List<UsageNode> existingData = tableModel.getItems();

  int row = table.getSelectedRow();

  int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
  if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
    ScrollingUtil.ensureSelectionExists(table);
    newSelection = table.getSelectedRow();
  }
  else {
    // do not pre-select the usage under caret by default
    if (newSelection == 0 && table.getModel().getRowCount() > 1) {
      Object valueInTopRow = table.getModel().getValueAt(0, 0);
      if (valueInTopRow instanceof UsageNode && usageView.isOriginUsage(((UsageNode)valueInTopRow).getUsage())) {
        newSelection++;
      }
    }
    table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
  }
  ScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);

  if (popup != null) {
    setSizeAndDimensions(table, popup, popupPosition, data);
  }
}
 
Example #21
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@NotNull JTable table,
    @NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition,
    @NotNull List<UsageNode> data) {
  JComponent content = popup.getContent();
  Window window = SwingUtilities.windowForComponent(content);
  Dimension d = window.getSize();

  int width = calcMaxWidth(table);
  width = (int)Math.max(d.getWidth(), width);
  Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize();
  width = Math.max((int)headerSize.getWidth(), width);
  width = Math.max(myWidth, width);

  if (myWidth == -1) myWidth = width;
  int newWidth = Math.max(width, d.width + width - myWidth);

  myWidth = newWidth;

  int rowsToShow = Math.min(30, data.size());
  Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
  Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
  dimension = rectangle.getSize();
  Point location = window.getLocation();
  if (!location.equals(rectangle.getLocation())) {
    window.setLocation(rectangle.getLocation());
  }

  if (!data.isEmpty()) {
    TableScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(dimension);
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);


  Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize();

  int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/;
  Dimension newDim = new Dimension(dimension.width, newHeight);
  window.setSize(newDim);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
  table.revalidate();
  table.repaint();
}
 
Example #22
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private AbstractPopup getPopup() {
  return popup;
}
 
Example #23
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void setPopup(@Nonnull AbstractPopup popup) {
  assert this.popup == null;
  this.popup = popup;
  consumers.forEach(c -> c.accept(popup));
  consumers = null;
}
 
Example #24
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public DocumentationComponent getDocumentationComponent() {
  AbstractPopup hint = getCurrentHint();
  return hint == null ? null : UIUtil.findComponentOfType(hint.getComponent(), DocumentationComponent.class);
}
 
Example #25
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static AbstractPopup createHint(JComponent component, PopupBridge popupBridge, boolean requestFocus) {
  WrapperPanel wrapper = new WrapperPanel(component);
  AbstractPopup popup = (AbstractPopup)JBPopupFactory.getInstance().createComponentPopupBuilder(wrapper, component).setResizable(true).setFocusable(requestFocus).setRequestFocus(requestFocus).createPopup();
  popupBridge.setPopup(popup);
  return popup;
}
 
Example #26
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setHint(JBPopup hint) {
  myHint = (AbstractPopup)hint;
}
 
Example #27
Source File: TouchBarsManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Disposable showPopupBar(AbstractPopup abstractPopup, JComponent content) {
  // nothing
  return null;
}
 
Example #28
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) {
  JComponent content = popup.getContent();
  Window window = SwingUtilities.windowForComponent(content);
  Dimension d = window.getSize();

  int width = calcMaxWidth(table);
  width = (int) Math.max(d.getWidth(), width);
  Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
  width = Math.max((int) headerSize.getWidth(), width);
  width = Math.max(myWidth, width);

  if (myWidth == -1) myWidth = width;
  int newWidth = Math.max(width, d.width + width - myWidth);

  myWidth = newWidth;

  int rowsToShow = Math.min(30, data.size());
  Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
  Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
  dimension = rectangle.getSize();
  Point location = window.getLocation();
  if (!location.equals(rectangle.getLocation())) {
    window.setLocation(rectangle.getLocation());
  }

  if (!data.isEmpty()) {
    TableScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(dimension);
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);

  Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

  int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/;
  Dimension newDim = new Dimension(dimension.width, newHeight);
  window.setSize(newDim);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
  table.revalidate();
  table.repaint();
}