@NotNull
 @Override
 public BalloonBuilder createHtmlTextBalloonBuilder(
     @NotNull String htmlContent, MessageType messageType, @Nullable HyperlinkListener listener) {
   return createHtmlTextBalloonBuilder(
       htmlContent, messageType.getDefaultIcon(), messageType.getPopupBackground(), listener);
 }
Пример #2
0
  public BalloonHandler notifyByBalloon(
      MessageType type,
      String htmlBody,
      @Nullable Icon icon,
      @Nullable HyperlinkListener listener) {
    final Balloon balloon =
        JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder(
                htmlBody.replace("\n", "<br>"),
                icon != null ? icon : type.getDefaultIcon(),
                type.getPopupBackground(),
                listener)
            .createBalloon();

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            Component comp = InfoAndProgressPanel.this;
            if (comp.isShowing()) {
              int offset = comp.getHeight() / 2;
              Point point = new Point(comp.getWidth() - offset, comp.getHeight() - offset);
              balloon.show(new RelativePoint(comp, point), Balloon.Position.above);
            } else {
              final JRootPane rootPane = SwingUtilities.getRootPane(comp);
              if (rootPane != null && rootPane.isShowing()) {
                final Container contentPane = rootPane.getContentPane();
                final Rectangle bounds = contentPane.getBounds();
                final Point target = UIUtil.getCenterPoint(bounds, new Dimension(1, 1));
                target.y = bounds.height - 3;
                balloon.show(new RelativePoint(contentPane, target), Balloon.Position.above);
              }
            }
          }
        });

    return new BalloonHandler() {
      @Override
      public void hide() {
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                balloon.hide();
              }
            });
      }
    };
  }
 public void run() {
   final Notification notification;
   if (myNotificationListener != null && myNotificationListener.length > 0) {
     final NotificationType type = myMessageType.toNotificationType();
     final StringBuilder sb = new StringBuilder(myMessage);
     for (NamedRunnable runnable : myNotificationListener) {
       final String name = runnable.toString();
       sb.append("<br/><a href=\"").append(name).append("\">").append(name).append("</a>");
     }
     notification =
         NOTIFICATION_GROUP.createNotification(
             type.name(),
             sb.toString(),
             myMessageType.toNotificationType(),
             new NotificationListener() {
               @Override
               public void hyperlinkUpdate(
                   @NotNull Notification notification, @NotNull HyperlinkEvent event) {
                 if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
                   if (myNotificationListener.length == 1) {
                     myNotificationListener[0].run();
                   } else {
                     final String description = event.getDescription();
                     if (description != null) {
                       for (NamedRunnable runnable : myNotificationListener) {
                         if (description.equals(runnable.toString())) {
                           runnable.run();
                           break;
                         }
                       }
                     }
                   }
                   notification.expire();
                 }
               }
             });
   } else {
     notification = NOTIFICATION_GROUP.createNotification(myMessage, myMessageType);
   }
   notification.notify(myProject.isDefault() ? null : myProject);
 }