Java Code Examples for com.intellij.openapi.ui.popup.Balloon#Position

The following examples show how to use com.intellij.openapi.ui.popup.Balloon#Position . 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: ExternalSystemUiUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * 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(@Nonnull JComponent component, @Nonnull MessageType messageType, @Nonnull String message) {
  final BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, null)
    .setDisposable(ApplicationManager.getApplication())
    .setFadeoutTime(BALLOON_FADEOUT_TIME);
  Balloon balloon = builder.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);
}
 
Example 2
Source File: LightweightHint.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void fixActualPoint(Point actualPoint) {
  if (!isAwtTooltip()) return;
  if (!myIsRealPopup) return;

  Dimension size = myComponent.getPreferredSize();
  Balloon.Position position = myHintHint.getPreferredPosition();
  int shift = BalloonImpl.getPointerLength(position, false);
  switch (position) {
    case below:
      actualPoint.y += shift;
      break;
    case above:
      actualPoint.y -= (shift + size.height);
      break;
    case atLeft:
      actualPoint.x -= (shift + size.width);
      break;
    case atRight:
      actualPoint.y += shift;
      break;
  }
}
 
Example 3
Source File: LightweightHint.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean fitsLayeredPane(JLayeredPane pane, JComponent component, RelativePoint desiredLocation, HintHint hintHint) {
  if (hintHint.isAwtTooltip()) {
    Dimension size = component.getPreferredSize();
    Dimension paneSize = pane.getSize();

    Point target = desiredLocation.getPointOn(pane).getPoint();
    Balloon.Position pos = hintHint.getPreferredPosition();
    int pointer = BalloonImpl.getPointerLength(pos, false) + BalloonImpl.getNormalInset();
    if (pos == Balloon.Position.above || pos == Balloon.Position.below) {
      boolean heightFit = target.y - size.height - pointer > 0 || target.y + size.height + pointer < paneSize.height;
      return heightFit && size.width + pointer < paneSize.width;
    }
    else {
      boolean widthFit = target.x - size.width - pointer > 0 || target.x + size.width + pointer < paneSize.width;
      return widthFit && size.height + pointer < paneSize.height;
    }
  }
  else {
    final Rectangle lpRect = new Rectangle(pane.getLocationOnScreen().x, pane.getLocationOnScreen().y, pane.getWidth(), pane.getHeight());
    Rectangle componentRect = new Rectangle(desiredLocation.getScreenPoint().x, desiredLocation.getScreenPoint().y, component.getPreferredSize().width, component.getPreferredSize().height);
    return lpRect.contains(componentRect);
  }
}
 
Example 4
Source File: ColorPickerProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void show(Color initialColor,
JComponent component,
Point offset,
Balloon.Position position,
ColorListener colorListener,
Runnable onCancel,
Runnable onOk);
 
Example 5
Source File: GuiUtils.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
public static void showNotification(final JComponent component, final MessageType info, final String message, final Balloon.Position position) {
    runInSwingThread(new Runnable() {
        @Override
        public void run() {
            JBPopupFactory.getInstance().createBalloonBuilder(new JLabel(message))
                    .setFillColor(info.getPopupBackground())
                    .createBalloon()
                    .show(new RelativePoint(component, new Point(0, 0)), position);
        }
    });
}
 
Example 6
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
void tooltipAvailable(@Nullable String toolTip, @Nonnull MouseEvent e, @Nullable GutterMark renderer) {
  myCalculatingInBackground = null;
  TooltipController controller = TooltipController.getInstance();
  if (toolTip == null || toolTip.isEmpty() || myEditor.isDisposed()) {
    controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, false);
  }
  else {
    final Ref<Point> t = new Ref<>(e.getPoint());
    int line = myEditor.yToVisualLine(e.getY());
    List<GutterMark> row = getGutterRenderers(line);
    Balloon.Position ballPosition = Balloon.Position.atRight;
    if (!row.isEmpty()) {
      Map<Integer, GutterMark> xPos = new TreeMap<>();
      final int[] currentPos = {0};
      processIconsRow(line, row, (x, y, r) -> {
        xPos.put(x, r);
        if (renderer == r) {
          currentPos[0] = x;
          Icon icon = scaleIcon(r.getIcon());
          t.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
        }
      });

      List<Integer> xx = new ArrayList<>(xPos.keySet());
      int posIndex = xx.indexOf(currentPos[0]);
      if (xPos.size() > 1 && posIndex == 0) {
        ballPosition = Balloon.Position.below;
      }
    }

    RelativePoint showPoint = new RelativePoint(this, t.get());

    TooltipRenderer tr = ((EditorMarkupModel)myEditor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip);
    HintHint hint = new HintHint(this, t.get()).setAwtTooltip(true).setPreferredPosition(ballPosition).setRequestFocus(ScreenReader.isActive());
    if (myEditor.getComponent().getRootPane() != null) {
      controller.showTooltipByMouseMove(myEditor, showPoint, tr, false, GUTTER_TOOLTIP_GROUP, hint);
    }
  }
}
 
Example 7
Source File: LightweightHint.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updatePosition(Balloon.Position position) {
  if (myHintHint != null) {
    myHintHint.setPreferredPosition(position);
  }
  if (myCurrentIdeTooltip != null) {
    myCurrentIdeTooltip.setPreferredPosition(position);
  }
}
 
Example 8
Source File: ColorPickerProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void show(Color initialColor,
JComponent component,
Point offset,
Balloon.Position position,
ColorListener colorListener,
Runnable onCancel,
Runnable onOk);
 
Example 9
Source File: GotItMessage.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void show(RelativePoint point, Balloon.Position position) {
  final GotItPanel panel = new GotItPanel();
  panel.myTitle.setText(myTitle);
  panel.myMessage.setText(myMessage);

  panel.myButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(panel.myRoot);
  if (myDisposable != null) {
    builder.setDisposable(myDisposable);
  }

  builder.setFillColor(UIUtil.getListBackground());
  builder.setHideOnClickOutside(false);
  builder.setHideOnAction(false);
  builder.setHideOnFrameResize(false);
  builder.setHideOnKeyOutside(false);
  builder.setShowCallout(myShowCallout);
  builder.setBlockClicksThroughBalloon(true);
  final Balloon balloon = builder.createBalloon();
  panel.myButton.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      balloon.hide();
      if (myCallback != null) {
        myCallback.run();
      }
    }
  });

  balloon.show(point, position);
}
 
Example 10
Source File: QuickEditAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Balloon.Position getBalloonPosition(Editor editor) {
  final int line = editor.getCaretModel().getVisualPosition().line;
  final Rectangle area = editor.getScrollingModel().getVisibleArea();
  int startLine  = area.y / editor.getLineHeight() + 1;
  return (line - startLine) * editor.getLineHeight() < 200 ? Balloon.Position.below : Balloon.Position.above;
}
 
Example 11
Source File: IdeTooltip.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Balloon.Position getPreferredPosition() {
  return myPreferredPosition;
}
 
Example 12
Source File: IdeTooltip.java    From consulo with Apache License 2.0 4 votes vote down vote up
public IdeTooltip setPreferredPosition(Balloon.Position position) {
  myPreferredPosition = position;
  return this;
}
 
Example 13
Source File: HintHint.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Balloon.Position getPreferredPosition() {
  return myPreferredPosition;
}
 
Example 14
Source File: HintHint.java    From consulo with Apache License 2.0 4 votes vote down vote up
public HintHint setPreferredPosition(Balloon.Position position) {
  myPreferredPosition = position;
  return this;
}
 
Example 15
Source File: NotificationBalloonShadowBorderProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void paintPointingShape(@Nonnull Rectangle bounds, @Nonnull Point pointTarget, @Nonnull Balloon.Position position, @Nonnull Graphics2D g) {
  int x, y, length;

  if (position == Balloon.Position.above) {
    length = INSETS.bottom;
    x = pointTarget.x;
    y = bounds.y + bounds.height + length;
  }
  else if (position == Balloon.Position.below) {
    length = INSETS.top;
    x = pointTarget.x;
    y = bounds.y - length;
  }
  else if (position == Balloon.Position.atRight) {
    length = INSETS.left;
    x = bounds.x - length;
    y = pointTarget.y;
  }
  else {
    length = INSETS.right;
    x = bounds.x + bounds.width + length;
    y = pointTarget.y;
  }

  Polygon p = new Polygon();
  p.addPoint(x, y);

  length += 2;
  if (position == Balloon.Position.above) {
    p.addPoint(x - length, y - length);
    p.addPoint(x + length, y - length);
  }
  else if (position == Balloon.Position.below) {
    p.addPoint(x - length, y + length);
    p.addPoint(x + length, y + length);
  }
  else if (position == Balloon.Position.atRight) {
    p.addPoint(x + length, y - length);
    p.addPoint(x + length, y + length);
  }
  else {
    p.addPoint(x - length, y - length);
    p.addPoint(x - length, y + length);
  }

  g.setColor(myFillColor);
  g.fillPolygon(p);

  g.setColor(myBorderColor);

  length -= 2;
  if (position == Balloon.Position.above) {
    g.drawLine(x, y, x - length, y - length);
    g.drawLine(x, y, x + length, y - length);
  }
  else if (position == Balloon.Position.below) {
    g.drawLine(x, y, x - length, y + length);
    g.drawLine(x, y, x + length, y + length);
  }
  else if (position == Balloon.Position.atRight) {
    g.drawLine(x, y, x + length, y - length);
    g.drawLine(x, y, x + length, y + length);
  }
  else {
    g.drawLine(x, y, x - length, y - length);
    g.drawLine(x, y, x - length, y + length);
  }
}
 
Example 16
Source File: BalloonImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void show(PositionTracker<Balloon> tracker, Balloon.Position position) {
  show(tracker, getAbstractPositionFor(position));
}
 
Example 17
Source File: BalloonImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void show(final RelativePoint target, final Balloon.Position position) {
  show(target, getAbstractPositionFor(position));
}