Widget Library

The Widget library provides very common widgets with basic implementations. These simple widgets may not provide every desired feature, but they can easily be forked since their implementation is very simple.

The widget library does not provide any example. However, the widget demo provides examples for these widgets.

Source

To use the widgets provided by the widget library, add the following line to a module description file:

<dependency org="ej.library.ui" name="widget" rev="4.1.0"/>

To fork one of the provided widgets, duplicate the associated Java class from the widget library JAR into the source code of your application. It is recommended to move the duplicated class to an other package and to rename the class in order to avoid confusion between your forked class and the original class.

Provided Widgets

Widgets:

  • Label: displays a text.
  • ImageWidget: displays an image which is loaded from a resource.
  • Button: displays a text and reacts to click events.
  • ImageButton: displays an image which is loaded from a resource and reacts to click events.

Containers:

  • List: lays out any number of children horizontally or vertically.
  • Flow: lays out any number of children horizontally or vertically, using multiple rows if necessary.
  • Grid: lays out any number of children in a grid.
  • Dock: lays out any number of children by docking each child one by one on a side.
  • SimpleDock: lays out three children horizontally or vertically.
  • OverlapContainer: lays out any number of children by stacking them.
  • Canvas: lays out any number of children freely.

Color Utilities

The widget library offers some color utilities.

The ColorHelper is helpful for decomposing colors into components (alpha, red, blue, green) and building back a color from components.

The GradientHelper can blend two colors and create a gradient from two colors.

The resulting gradient is a list of distinct colors from the start color to the end color. The colors are truncated to the display color depth. As a consequence, for the same start and end colors, a gradient created for a 32-bit display will contain more colors than on a 16-bit display.

The LightHelper proposes several primitives concerning the luminance of the colors. The luminance of a color is computed from the luminance and the quantity of each of its components. The green being the brighter, then the red and finally the blue.

Debug Utilities

A few utilities useful for debugging are available in the package ej.widget.util.debug of the widget library.

Count the Number of Widgets or Containers

The methods HierarchyInspector.countNumberOfWidgets(Widget) and HierarchyInspector.countNumberOfContainers(Widget) respectively count the number of widgets and containers in a hierarchy.

It may be used to evaluate the complexity of a hierarchy of widgets.

Count the Maximum Depth of a Hierarchy

The method HierarchyInspector.countMaxDepth(Widget) counts the maximum depth of a hierarchy. In other words, the depth of the widget with the biggest number of parents recursively.

It may be used to evaluate the complexity of a hierarchy of widgets.