@Override
 protected void hyperlinkActivated(HyperlinkEvent e) {
   final Module moduleByName =
       ModuleManager.getInstance(myProject).findModuleByName(e.getDescription());
   if (moduleByName != null) {
     myConfiguration.getConfigurationModule().setModule(moduleByName);
     try {
       final Executor executor =
           myConsoleProperties.isDebug()
               ? DefaultDebugExecutor.getDebugExecutorInstance()
               : DefaultRunExecutor.getRunExecutorInstance();
       final ProgramRunner runner =
           RunnerRegistry.getInstance().getRunner(executor.getId(), myConfiguration);
       assert runner != null;
       runner.execute(
           executor,
           new ExecutionEnvironment(
               myConfiguration,
               myProject,
               getRunnerSettings(),
               getConfigurationSettings(),
               null));
       final Balloon balloon = myToolWindowManager.getToolWindowBalloon(myTestRunDebugId);
       if (balloon != null) {
         balloon.hide();
       }
     } catch (ExecutionException e1) {
       LOG.error(e1);
     }
   }
 }
 public void hideBalloon() {
   if (myBalloonRef != null) {
     final Balloon balloon = myBalloonRef.get();
     if (balloon != null) {
       balloon.hide();
     }
     myBalloonRef = null;
   }
 }
 public void expire() {
   NotificationsManager.getNotificationsManager().expire(this);
   if (myBalloonRef != null) {
     final Balloon balloon = myBalloonRef.get();
     if (balloon != null) {
       balloon.hide();
     }
     myBalloonRef = null;
   }
   myExpired = true;
 }
  private void removeFromEditor() {
    Editor editor = mySearchResults.getEditor();
    if (myReplacementBalloon != null) {
      myReplacementBalloon.hide();
    }

    if (editor != null) {

      for (VisibleAreaListener visibleAreaListener : myVisibleAreaListenersToRemove) {
        editor.getScrollingModel().removeVisibleAreaListener(visibleAreaListener);
      }
      myVisibleAreaListenersToRemove.clear();
      Project project = mySearchResults.getProject();
      if (project != null && !project.isDisposed()) {
        for (RangeHighlighter h : myHighlighters) {
          HighlightManager.getInstance(project).removeSegmentHighlighter(editor, h);
        }
        if (myCursorHighlighter != null) {
          HighlightManager.getInstance(project)
              .removeSegmentHighlighter(editor, myCursorHighlighter);
          myCursorHighlighter = null;
        }
      }
      myHighlighters.clear();
      if (myListeningSelection) {
        editor.getSelectionModel().removeSelectionListener(this);
        myListeningSelection = false;
      }
    }
  }
  private void hideBalloon() {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      myReplacementPreviewText = null;
      return;
    }

    if (myReplacementBalloon != null) {
      myReplacementBalloon.hide();
      myReplacementBalloon = null;
    }
  }
 /**
  * Asks to show balloon that contains information related to the given component.
  *
  * @param component component for which we want to show information
  * @param messageType balloon message type
  * @param message message to show
  */
 public static void showBalloon(
     @NotNull JComponent component, @NotNull MessageType messageType, @NotNull String message) {
   final BalloonBuilder delegate =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, null);
   BalloonBuilder balloonBuilder = new GradleBalloonBuilder(delegate, APPLICATION_BALLOONS);
   ApplicationBalloonsDisposeActivator.ensureActivated();
   Balloon balloon = balloonBuilder.setFadeoutTime(TimeUnit.SECONDS.toMillis(1)).createBalloon();
   Dimension size = component.getSize();
   Balloon.Position position;
   int x;
   int y;
   if (size == null) {
     x = y = 0;
     position = Balloon.Position.above;
   } else {
     x = Math.min(10, size.width / 2);
     y = size.height;
     position = Balloon.Position.below;
   }
   balloon.show(new RelativePoint(component, new Point(x, y)), position);
 }
 public void setBalloon(@NotNull final Balloon balloon) {
   hideBalloon();
   myBalloonRef = new WeakReference<>(balloon);
   balloon.addListener(
       new JBPopupAdapter() {
         @Override
         public void onClosed(LightweightWindowEvent event) {
           if (SoftReference.dereference(myBalloonRef) == balloon) {
             myBalloonRef = null;
           }
         }
       });
 }
    @Override
    public RelativePoint recalculateLocation(final Balloon object) {
      FindResult cursor = mySearchResults.getCursor();
      if (cursor == null) return null;
      final TextRange cur = cursor;
      int startOffset = cur.getStartOffset();
      int endOffset = cur.getEndOffset();

      if (startOffset >= myEditor.getDocument().getTextLength()) {
        if (!object.isDisposed()) {
          requestBalloonHiding(object);
        }
        return null;
      }
      if (!SearchResults.insideVisibleArea(myEditor, cur)) {
        requestBalloonHiding(object);

        VisibleAreaListener visibleAreaListener =
            new VisibleAreaListener() {
              @Override
              public void visibleAreaChanged(VisibleAreaEvent e) {
                if (SearchResults.insideVisibleArea(myEditor, cur)) {
                  showReplacementPreview();
                  final VisibleAreaListener visibleAreaListener = this;
                  final boolean remove = myVisibleAreaListenersToRemove.remove(visibleAreaListener);
                  if (remove) {
                    myEditor.getScrollingModel().removeVisibleAreaListener(visibleAreaListener);
                  }
                }
              }
            };
        myEditor.getScrollingModel().addVisibleAreaListener(visibleAreaListener);
        myVisibleAreaListenersToRemove.add(visibleAreaListener);
      }

      Point startPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(startOffset));
      Point endPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(endOffset));
      Point point = new Point((startPoint.x + endPoint.x) / 2, startPoint.y);

      return new RelativePoint(myEditor.getContentComponent(), point);
    }
  private void showBalloon(FindResult cursor, Editor editor, String replacementPreviewText) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      myReplacementPreviewText = replacementPreviewText;
      return;
    }

    ReplacementView replacementView = new ReplacementView(replacementPreviewText, cursor);

    BalloonBuilder balloonBuilder =
        JBPopupFactory.getInstance().createBalloonBuilder(replacementView);
    balloonBuilder.setFadeoutTime(0);
    balloonBuilder.setFillColor(IdeTooltipManager.GRAPHITE_COLOR);
    balloonBuilder.setAnimationCycle(0);
    balloonBuilder.setHideOnClickOutside(false);
    balloonBuilder.setHideOnKeyOutside(false);
    balloonBuilder.setHideOnAction(false);
    balloonBuilder.setCloseButtonEnabled(true);
    myReplacementBalloon = balloonBuilder.createBalloon();

    myReplacementBalloon.show(
        new ReplacementBalloonPositionTracker(editor), Balloon.Position.above);
  }
 public void navigate(int injectedOffset) {
   if (myAction.isShowInBalloon()) {
     final JComponent component = myAction.createBalloonComponent(myNewFile);
     if (component != null) {
       final Balloon balloon =
           JBPopupFactory.getInstance()
               .createBalloonBuilder(component)
               .setShadow(true)
               .setAnimationCycle(0)
               .setHideOnClickOutside(true)
               .setHideOnKeyOutside(true)
               .setHideOnAction(false)
               .setFillColor(UIUtil.getControlColor())
               .createBalloon();
       new AnAction() {
         @Override
         public void actionPerformed(AnActionEvent e) {
           balloon.hide();
         }
       }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
       Disposer.register(myNewFile.getProject(), balloon);
       final Balloon.Position position = QuickEditAction.getBalloonPosition(myEditor);
       RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor);
       if (position == Balloon.Position.above) {
         final Point p = point.getPoint();
         point =
             new RelativePoint(
                 point.getComponent(), new Point(p.x, p.y - myEditor.getLineHeight()));
       }
       balloon.show(point, position);
     }
   } else {
     final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject);
     final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile);
     if (editors.length == 0) {
       final EditorWindow curWindow = fileEditorManager.getCurrentWindow();
       mySplittedWindow =
           curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true);
     }
     Editor editor =
         fileEditorManager.openTextEditor(
             new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true);
     // fold missing values
     if (editor != null) {
       editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this);
       final FoldingModel foldingModel = editor.getFoldingModel();
       foldingModel.runBatchFoldingOperation(
           () -> {
             for (RangeMarker o :
                 ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) {
               String replacement = o.getUserData(REPLACEMENT_KEY);
               if (StringUtil.isEmpty(replacement)) continue;
               FoldRegion region =
                   foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(), replacement);
               if (region != null) region.setExpanded(false);
             }
           });
     }
     SwingUtilities.invokeLater(
         () -> myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE));
   }
 }
  @Override
  protected void doShowPopup(
      final Project project,
      final JComponent component,
      final Point whereToShow,
      final Object breakpoint) {
    if (!(breakpoint instanceof BreakpointWithHighlighter)) return;

    final BreakpointWithHighlighter javaBreakpoint = (BreakpointWithHighlighter) breakpoint;
    Key<? extends BreakpointWithHighlighter> category = javaBreakpoint.getCategory();

    final BreakpointFactory[] allFactories =
        ApplicationManager.getApplication().getExtensions(BreakpointFactory.EXTENSION_POINT_NAME);
    BreakpointFactory breakpointFactory = null;
    for (BreakpointFactory factory : allFactories) {
      if (factory.getBreakpointCategory().equals(category)) {
        breakpointFactory = factory;
      }
    }
    assert breakpointFactory != null : "can't find factory for breakpoint " + javaBreakpoint;

    final BreakpointPropertiesPanel propertiesPanel =
        breakpointFactory.createBreakpointPropertiesPanel(project, true);
    propertiesPanel.initFrom(javaBreakpoint, false);

    final JComponent mainPanel = propertiesPanel.getPanel();
    final String displayName = javaBreakpoint.getDisplayName();

    final JBPopupListener saveOnClose =
        new JBPopupListener() {
          @Override
          public void beforeShown(LightweightWindowEvent event) {}

          @Override
          public void onClosed(LightweightWindowEvent event) {
            propertiesPanel.saveTo(
                javaBreakpoint,
                new Runnable() {
                  @Override
                  public void run() {}
                });
          }
        };

    final Runnable showMoreOptions =
        new Runnable() {
          @Override
          public void run() {
            UIUtil.invokeLaterIfNeeded(
                new Runnable() {
                  @Override
                  public void run() {
                    final JBPopup popup =
                        BreakpointsMasterDetailPopupFactory.getInstance(project)
                            .createPopup(javaBreakpoint);
                    if (popup != null) {
                      popup.showCenteredInCurrentWindow(project);
                    }
                  }
                });
          }
        };
    final Balloon balloon =
        DebuggerUIUtil.showBreakpointEditor(
            project, mainPanel, displayName, whereToShow, component, showMoreOptions, breakpoint);
    balloon.addListener(saveOnClose);

    propertiesPanel.setDelegate(
        new BreakpointPropertiesPanel.Delegate() {
          @Override
          public void showActionsPanel() {
            propertiesPanel.setActionsPanelVisible(true);
            balloon.hide();
            final Balloon newBalloon =
                DebuggerUIUtil.showBreakpointEditor(
                    project,
                    mainPanel,
                    displayName,
                    whereToShow,
                    component,
                    showMoreOptions,
                    breakpoint);
            newBalloon.addListener(saveOnClose);
          }
        });

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                IdeFocusManager.findInstance().requestFocus(mainPanel, true);
              }
            });
  }