How to render/format output from IDEA plugin

Rsarukkai
Nov 13, 06:36

Hi,
I am trying to build out an intellij plugin that adds a button to the toolbar - and upon clicking I want to create a window that can be filled with HTML compatible text (or some way formattable wrt background color, scrollable etc).

I have used AnAction to create a button thats added to the tool bar, but when I use Messages.showMessageDialog, the output is very constrained and not formattable (I also see the Java icon that I cannot get rid of).

Instead I tried using Messages.configureMessagePaneUi(textpane,"Test") - but am unable to actually render the pane (i.e. nothing shows up).

Any chance you can help me with sample code to be able to render content into a new window upon click of a plugin button?
Ideally I am looking to render more formatted content (e.g. HTML formatted with controlled background color, and including uri referenced images)
thanks.
-Ram

7 comments
Comment actions Permalink

Hello Ram,

here is one way to do this:

static void formatted(Editor editor, String html, String title) {
      JBPopupFactory factory = JBPopupFactory.getInstance();

      BalloonBuilder builder =
         factory.createHtmlTextBalloonBuilder(html, MessageType.INFO, null);

      builder.setTitle(title);

      builder.setFillColor(JBColor.background());

      Balloon b = builder.createBalloon();

      JComponent comp = editor.getComponent();
      Rectangle r = comp.getBounds();

      RelativePoint p = new RelativePoint(comp, new Point(r.x + r.width, r.y + r.height));
      b.show(p, Balloon.Position.atRight);
   }

0
Comment actions Permalink

Thanks! This was super helpful.

Just a couple of more help:
+ How do I set the size of the ballon and make it scrollable? Its very small and not big enough to display my content - and I don't see a width or height params.
+ Is there a way to not tie this to the editor? i.e. can i display a window even if i am not editing specific code/config files?

Thanks.
-Ram

0
Comment actions Permalink

here is how you could set height & width:

  static void formatted(Editor editor, String html, String title, Rectangle bounds) {
        JBPopupFactory factory = JBPopupFactory.getInstance();

        BalloonBuilder builder =
                factory.createHtmlTextBalloonBuilder(html, MessageType.INFO, null);

        builder.setTitle(title);

        builder.setFillColor(JBColor.background());

        Balloon b = builder.createBalloon();

        JComponent comp = editor.getComponent();
        Rectangle r = comp.getBounds();

        int x1 = r.x + r.width;
        int y1 = r.y + r.height;

        Point po = new Point(x1, y1);


        Point p1 = new Point(x1 - (int)bounds.getWidth(), y1 - (int)bounds.getHeight());
        bounds.setLocation(p1);
        b.setBounds(bounds);


        RelativePoint p = new RelativePoint(comp, po);
        b.show(p, Balloon.Position.atRight);
    }

0
Comment actions Permalink
  • make it scrollable

  • not tie this to the editor

I do not know how to do this.

Please dig into https://github.com/JetBrains/intellij-community.

If you find the answer, be kind to post it here.
0
Comment actions Permalink

Thanks. The issue I am having is that the rendered HTML is cut off and I am not sure how to expand the view window.
see attached screenshot



Attachment(s):
Screenshot 2015-11-18 15.37.55.png
0
Comment actions Permalink

here is another version which looks a bit better:

static void formatted(Editor editor,
                                  String html,
                                  String title,
                                  @Nullable Rectangle rect) {

        JComponent comp = editor.getComponent();

        RelativePoint p = getRelativePoint(comp);

        Balloon b = getBalloon(html, title, rect, comp);

        b.show(p, Balloon.Position.atRight);
    }


    @NotNull
    private static Balloon getBalloon(String html,
                                      String title,
                                      @Nullable Rectangle rect,
                                      JComponent comp) {

        JBPopupFactory factory = JBPopupFactory.getInstance();

        BalloonBuilder builder =
                factory.createHtmlTextBalloonBuilder(html, MessageType.INFO, null);

        builder.setTitle(title);

        builder.setFillColor(JBColor.background());

        Balloon b = builder.createBalloon();


        if (rect != null) {
            Point p = getBalloonpoint(comp);
            rect.setLocation(p);
            b.setBounds(rect);
        }
        return b;
    }


    private static Point getBalloonpoint(JComponent comp) {
        return getRelativePoint(comp).getPoint();
    }


    @NotNull
    private static RelativePoint getRelativePoint(JComponent comp) {
        JBPopupFactory factory = JBPopupFactory.getInstance();
        return factory.guessBestPopupLocation(comp);
    }

0
Comment actions Permalink

Ram, are you passing valid HTML?

wrapped in tags, styled etc?


I just checked: the popup window size auto adjusts to the content.

0

Please sign in to leave a comment.