package de.ugoe.cs.quest.plugin.mfc.eventcore; import java.util.ArrayList; import java.util.List; import de.ugoe.cs.util.StringTools; /** *
* This class implements a node in the {@link WindowTree} that is maintained * during parsing a session. *
** The window tree is structure that contains the hierarchy of the windows of a * application as well as basic information about each window: the hwnd; its * name; its resource id; its class name. *
* * @author Steffen Herbold * @version 1.0 */ public class WindowTreeNode { /** ** Name of the window. May change over time. *
*/ private String windowName; /** ** Handle of the window. Used as unique identifier during its existence. *
*/ private final int hwnd; /** ** Resource id of the window. *
*/ private final int resourceId; /** ** Class name of the window. *
*/ private final String className; /** ** True, if the window is modal. *
*/ private final boolean isModal; /** *
* Parent of the window. null
if the window has no parent.
*
* List of the windows children. May be empty. *
*/ private List* Creates a new WindowTreeNode. *
** The constructor is protected WindowTreeNode may only be created from the * WindowTree. *
* * @param hwnd * hwnd of the window * @param parent * reference to the parent's WindowTreeNode * @param windowName * name of the window * @param resourceId * resource id of the window * @param className * class name of the window * @param isModal * modality of the window */ protected WindowTreeNode(int hwnd, WindowTreeNode parent, String windowName, int resourceId, String className, boolean isModal) { this.hwnd = hwnd; this.parent = parent; this.windowName = windowName; this.resourceId = resourceId; this.className = className; this.isModal = isModal; children = new ArrayList* Returns a reference to the WindowTreeNode of the parent. *
* * @return WindowTreeNode of the parent */ public WindowTreeNode getParent() { return parent; } /** ** Returns the list of the windows children. *
* * @return list of the windows children */ public List* Returns the name of the window. *
* * @return name of the window */ public String getName() { return windowName; } /** ** Returns the hwnd of the window. *
* * @return hwnd of the window */ public int getHwnd() { return hwnd; } /** ** Returns the resource id of the window. *
* * @return resource id of the window */ public int getResourceId() { return resourceId; } /** ** Returns the class name of the window. *
* * @return class name of the window */ public String getClassName() { return className; } /** ** Sets the name of the window. *
* * @param text * new name of the window */ public void setName(String text) { windowName = text; } /** ** Removes a the window and all its children from the {@link WindowTree}. *
* * @return list of the children of the window for further clean up. */ public List* Removes a child window. *
* * @param child * reference to the child window to be removed */ public void removeChild(WindowTreeNode child) { children.remove(child); } /** ** Adds a new child window and creates WindowTreeNode for it. *
* * @param childHwnd * hwnd of the child window * @param childWindowName * name of the child window * @param resourceId * resource id of the child window * @param className * class name of the child window * @param isModal * modality of the child window * @return reference to the WindowTreeNode created for the child window */ public WindowTreeNode addChild(int childHwnd, String childWindowName, int resourceId, String className, boolean isModal) { WindowTreeNode child = new WindowTreeNode(childHwnd, this, childWindowName, resourceId, className, isModal); children.add(child); return child; } /** *
* Returns a string identfier of the window:
* {@code [resourceId;"windowName";"className";modality]}
*
* Returns an XML representation of the window, including its parents. It is
* defined as follows:
*
* parent#xmlRepresentation()
*
* <window name="this.windowname" class="this.className" resourceId="this.resourceId" isModal="this.isModel"/>
*
* Returns the names of the parents and itself separated by dots, e.g., * "GrandParent.Parent.windowName" *
* * @return names of the parents separated by dots */ public String getParentNames() { String parentNames = ""; if (parent != null) { parentNames = parent.getParentNames() + "."; } parentNames += windowName; return parentNames; } }