Debug Utilities
A few utilities useful for debugging are available in the package ej.widget.util.debug
of the widget library.
Print the Hierarchy of Widgets
The method HierarchyInspector.hierarchyToString(Widget) returns a String representing the hierarchy of a widget. In other words, it prints the widget and its children recursively in a tree format.
It may be used to analyse the content of a page and have a quick estimation of the number of widgets and the depth of the hierarchy.
For example:
Scroll
+--ScrollableList
| +--Label
| +--Dock
| | +--ImageWidget
| | +--Label
| +--Label
Print the Path to a Widget
The method HierarchyInspector.pathToWidgetToString(Widget) returns a String representing the list of ancestors of the widget.
For example: Desktop > Scroll > ScrollableList > Label
.
It may be used to identify a widget in a trace.
It is also possible to choose the separator by using HierarchyInspector.pathToWidgetToString(Widget, char) method.
For example: Desktop ; Scroll ; ScrollableList ; Label
.
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.
Print the Bounds of a Widget
The method BoundsInspector.boundsToString(Widget) returns a String with the widget type and its bounds. The returned String contains:
the simple name of the class of the widget,
its position relative to its parent,
its size,
its absolute position.
For example: Label: 0,0 7x25 (absolute: 75,75)
Print the bounds of all the widgets in a hierarchy
The method BoundsInspector.boundsRecursiveToString(Widget) returns a String representing the type and bounds of each widget in the hierarchy of a widget.
For example:
Scroll: 0,0 480x272 (absolute: 0,0)
+--ScrollableList: 0,0 480x272 (absolute: 0,0)
| +--Label: 0,0 480x50 (absolute: 0,0)
| +--Dock: 0,50 480x50 (absolute: 0,50)
| | +--ImageWidget: 0,0 70x50 (absolute: 0,50)
| | +--Label: 70,0 202x50 (absolute: 70,50)
| +--Label: 0,100 480x50 (absolute: 0,100)