Class HierarchyInspector
- java.lang.Object
-
- ej.widget.debug.HierarchyInspector
-
public class HierarchyInspector extends java.lang.Object
Provides helpers to analyze a hierarchy of widgets.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
countInstances(ej.mwt.Widget root, java.lang.Class<? extends ej.mwt.Widget> clazz)
Counts instances of aWidget
type in a widget hierarchy.static int
countMaxDepth(ej.mwt.Widget root)
Counts the maximum depth of a widget hierarchy.static int
countNumberOfContainers(ej.mwt.Widget root)
Counts containers in a given widget hierarchy.static int
countNumberOfWidgets(ej.mwt.Widget root)
Counts widgets in a widget hierarchy.static java.lang.String
hierarchyStyleToString(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop.static java.lang.String
hierarchyToString(ej.mwt.Widget root)
Prints a widget hierarchy.static java.lang.String
pathToWidgetToString(ej.mwt.Widget widget)
Prints the path to the given widget with>
separator.static java.lang.String
pathToWidgetToString(ej.mwt.Widget widget, char separator)
Prints the path to the given widget.static void
printHierarchy(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop on the "standard" output stream.static void
printHierarchyStyle(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop on the "standard" output stream.static void
visitHierarchy(ej.mwt.Widget widget, WidgetVisitor visitor)
Visits a widget hierarchy.
-
-
-
Method Detail
-
visitHierarchy
public static void visitHierarchy(ej.mwt.Widget widget, WidgetVisitor visitor)
Visits a widget hierarchy.If the root widget is a
Container
, this method calls:visitWidget(root); beginContainer(); for (Widget child: getChildren(root)) { visitHierarchy(child, visitor); } endContainer()
Otherwise, it simply calls `visitWidget(root)`.- Parameters:
widget
- the root of the widget hierarchy.visitor
- the visitor.
-
countInstances
public static int countInstances(ej.mwt.Widget root, java.lang.Class<? extends ej.mwt.Widget> clazz)
Counts instances of aWidget
type in a widget hierarchy.The method is recursive: if the given widget is a container, it browses its children.
- Parameters:
root
- the root of the widget hierarchy.clazz
- the widget class.- Returns:
- the number of instances.
-
countNumberOfContainers
public static int countNumberOfContainers(ej.mwt.Widget root)
Counts containers in a given widget hierarchy.The method is recursive: if the given widget is a container, it browses its children.
- Parameters:
root
- the root of the widget hierarchy.- Returns:
- the number of containers.
-
countNumberOfWidgets
public static int countNumberOfWidgets(ej.mwt.Widget root)
Counts widgets in a widget hierarchy.The method is recursive: if the given widget is a container, it browses its children.
- Parameters:
root
- the root of the widget hierarchy.- Returns:
- the number of widgets.
-
countMaxDepth
public static int countMaxDepth(ej.mwt.Widget root)
Counts the maximum depth of a widget hierarchy.The method is recursive: if the given widget is a container, it browses its children.
- Parameters:
root
- the root of the widget hierarchy.- Returns:
- the maximum depth.
-
hierarchyToString
public static java.lang.String hierarchyToString(ej.mwt.Widget root)
Prints a widget hierarchy.Prints the root widget and its children recursively in a tree format.
- Parameters:
root
- the root of the widget hierarchy.- Returns:
- the widget hierarchy serialized in a tree format.
-
printHierarchy
public static void printHierarchy(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop on the "standard" output stream.For each widget and its children recursively in a tree format, prints its class name.
This method writes on the "standard" output stream, for use during time-sensitive operations, prefer
hierarchyStyleToString(Widget)
.- Parameters:
root
- the root of the widget hierarchy.- Throws:
java.lang.IllegalArgumentException
- ifroot
isnull
or is not attached.- See Also:
standard output stream
,Widget.isAttached()
-
hierarchyStyleToString
public static java.lang.String hierarchyStyleToString(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop.For each widget and its children recursively in a tree format, prints its class name and current style.
- Parameters:
root
- the root of the widget hierarchy.- Returns:
- the hierarchy.
- Throws:
java.lang.IllegalArgumentException
- ifroot
isnull
or is not attached.- See Also:
Widget.isAttached()
-
printHierarchyStyle
public static void printHierarchyStyle(ej.mwt.Widget root)
Prints the widget hierarchy of a desktop on the "standard" output stream.For each widget and its children recursively in a tree format, prints its class name and current style.
This method writes on the "standard" output stream, for use during time-sensitive operations, prefer
hierarchyStyleToString(Widget)
.- Parameters:
root
- the root of the widget hierarchy.- Throws:
java.lang.IllegalArgumentException
- ifroot
isnull
or is not attached.- See Also:
standard output stream
,Widget.isAttached()
-
pathToWidgetToString
public static java.lang.String pathToWidgetToString(ej.mwt.Widget widget)
Prints the path to the given widget with>
separator.- Parameters:
widget
- the widget to inspect.- Returns:
- the path.
- See Also:
pathToWidgetToString(Widget, char)
-
pathToWidgetToString
public static java.lang.String pathToWidgetToString(ej.mwt.Widget widget, char separator)
Prints the path to the given widget.Prints the containers from the root (including the desktop) to the widget, separated with the given separator. Example:
Desktop > Scroll > ScrollableList > Label
- Parameters:
widget
- the widget to inspect.separator
- the separator between the items.- Returns:
- the path.
-
-