package de.ugoe.cs.quest.plugin.mfc.guimodel; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import de.ugoe.cs.quest.eventcore.guimodel.GUIElementFactory; import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; import de.ugoe.cs.quest.eventcore.guimodel.GUIModelException; import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementFactory; /** *
* This class provides an the interfaces for window trees. *
** The window tree represents the hierarchical structure of the windows "as it is" currently during * a session. It may change during the session due to creation and destruction of windows. *
* * @author Steffen Herbold * @version 1.0 */ public class WindowTree { /** ** Maintains a set of all the targets of all widgets that were at some point part of the window * tree. *
*/ private Set* Map of all GUI element specifications that are part of the tree for efficient searching. The * keys of the map are the hwnd's of the GUI elements. *
*/ private Map* Map of all children of GUI elements that are part of the tree. The keys of the map are the * hwnd's of the parent GUI elements. *
*/ private Map* Map of all parents of GUI elements that are part of the tree. The keys of the map are the * hwnd's of the child GUI elements. *
*/ private Map* the internally created GUI model *
*/ private GUIModel guiModel = new GUIModel(); /** ** the GUI element factory used in the model *
*/ private IGUIElementFactory guiElementFactory = GUIElementFactory.getInstance(); /** ** Map of all GUI elements that are part of the tree for efficient searching. The keys of the * map are the hwnd's of the GUI elements. *
*/ private Map* Creates a new WindowTree. *
** Private, as the class is a singleton. *
*/ public WindowTree() { guiElementSpecs = new HashMap* Adds a new window to the tree. *
* * @param parentHwnd * hwnd of the parent window * @param childHwnd * hwnd of the window to be created * @param childWindowName * resource id of the window to be created * @param resourceId * resource id of the window to be created * @param className * class name of the window to be created */ public void add(long parentHwnd, long childHwnd, String childWindowName, int resourceId, String className, boolean isModal) { MFCGUIElementSpec parent = guiElementSpecs.get(parentHwnd); MFCGUIElementSpec child = guiElementSpecs.get(childHwnd); if (child == null) { child = new MFCGUIElementSpec(childHwnd, childWindowName, resourceId, className, isModal); if (parent != null) { List* Searches the tree for a window with the specified hwnd and returns its * {@link MFCGUIElementSpec} . *
* * @param hwnd * hwnd that is looked for * @return {@link MFCGUIElementSpec} of the window with the given hwnd if found, null otherwise */ public MFCGUIElement find(long hwnd) { MFCGUIElement guiElement = guiElements.get(hwnd); if (guiElement == null) { List* Sets the name of a GUI element given its HWND. *
* * @param hwnd * HWND of the GUI element * @param windowName * new name of the GUI element */ public void setName(long hwnd, String windowName) { MFCGUIElementSpec child = guiElementSpecs.get(hwnd); if (child != null) { child.setName(windowName); MFCGUIElement guiElement = guiElements.remove(hwnd); if (guiElement == null) { // we need to update the GUI model as well find(hwnd); } } } /** ** Removes a window (defined by its hwnd) from the tree. All children of the window will be * removed recursively. *
* * @param hwnd * hwnd of the window to be removed * @return number of windows that were removed */ public int remove(long hwnd) { MFCGUIElementSpec node = guiElementSpecs.remove(hwnd); int removedCounter = 1; if (node != null) { List* Returns the number of nodes contained in the WindowTree. *
* * @return number of nodes */ public int size() { return guiElementSpecs.size(); } /** ** Returns a sorted set of all targets that existed any time in the window tree. *
* * @return set of targets */ public Set