Graphically, a balloon is a small popup window displaying information about an element in a user interface. Conceptually, a balloon is a container for a JComponent or a JavaFX view Node. You can add them to the Lightspeed overlay panel. The JComponent — or the JavaFX view Node — inside a balloon is referred to as a balloon content panel. Balloons can also have an arrow, pointing to a location in the view. Figure 1, “An example of a balloon in a Lightspeed view” shows an example of a balloon in a Lightspeed view.

lightspeed balloon example
Figure 1. An example of a balloon in a Lightspeed view

Creating balloons

To create and handle balloons, you can use ILcdBalloonContentProvider and TLspBalloonManager, or ILcdFXBalloonContentProvider and TLspFXBalloonManager for a JavaFX view. A balloon manager is responsible for controlling the visibility, size, arrow, and location of a balloon. The content provider provides the balloon manager with balloon content panels on demand.

To automatically make use of all content providers offered by LuciadLightspeed, just use the balloon manager constructor without the content provider argument. For more information, refer to Adding instant data format support to your application.

To set the object for which you want to create a balloon, use the setBalloonDescriptor() method of the balloon manager. An ALcdBalloonDescriptor contains all the necessary information to describe a balloon. It provides the following implementations:

To remove the balloon of a balloon manager, pass null as an argument to the setBalloonDescriptor() method.

The given balloon descriptor in the setBalloonDescriptor() method is passed to an ILcdBalloonContentProvider, or to a ILcdFXBalloonContentProvider for a JavaFX view. The balloon content provider is responsible for generating the balloon content. The balloon content can be any custom JComponent or JavaFX view Node. If no content is generated, the balloon manager will not display the balloon. It is important that the canGetContent() method only returns true for balloon descriptors that it can handle to allow for composite balloon content providers.

You can use the setBalloonsEnabled() method of the balloon manager to globally enable or disable the rendering of balloons.

Customizing balloons

You can customize the default positioning algorithm for ILspAWTView or ILcdGXYView by creating an extension of the balloon manager and overriding the computeBalloonBounds() method. You can supply a parameter that is used for calculating the bounds of a balloon, such as:

  • The balloon descriptor

  • The bounds of the view

  • A position that should be enforced by the algorithm

  • A size that should be enforced by the algorithm

  • Two Booleans to see whether the balloon has been manually resized or relocated by the user