source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/data/WindowTreeNode.java @ 171

Last change on this file since 171 was 171, checked in by sherbold, 13 years ago
  • code documentation and formatting
File size: 6.2 KB
Line 
1package de.ugoe.cs.eventbench.windows.data;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import de.ugoe.cs.util.StringTools;
7
8/**
9 * <p>
10 * This class implements a node in the {@link WindowTree} that is maintained
11 * during parsing a session.
12 * </p>
13 * <p>
14 * The window tree is structure that contains the hierarchy of the windows of a
15 * application as well as basic information about each window: the hwnd; its
16 * name; its resource id; its class name.
17 * </p>
18 *
19 * @author Steffen Herbold
20 * @version 1.0
21 */
22public class WindowTreeNode {
23
24        /**
25         * <p>
26         * Name of the window. May change over time.
27         * </p>
28         */
29        private String windowName;
30
31        /**
32         * <p>
33         * Handle of the window. Used as unique identifier during its existence.
34         * </p>
35         */
36        private final int hwnd;
37
38        /**
39         * <p>
40         * Resource id of the window.
41         * </p>
42         */
43        private final int resourceId;
44
45        /**
46         * <p>
47         * Class name of the window.
48         * </p>
49         */
50        private final String className;
51
52        /**
53         * <p>
54         * True, if the window is modal.
55         * </p>
56         */
57        private final boolean isModal;
58
59        /**
60         * <p>
61         * Parent of the window. <code>null</code> if the window has no parent.
62         * </p>
63         */
64        private WindowTreeNode parent;
65
66        /**
67         * <p>
68         * List of the windows children. May be empty.
69         * </p>
70         */
71        private List<WindowTreeNode> children;
72
73        /**
74         * <p>
75         * Creates a new WindowTreeNode.
76         * </p>
77         * <p>
78         * The constructor is protected WindowTreeNode may only be created from the
79         * WindowTree.
80         * </p>
81         *
82         * @param hwnd
83         *            hwnd of the window
84         * @param parent
85         *            reference to the parent's WindowTreeNode
86         * @param windowName
87         *            name of the window
88         * @param resourceId
89         *            resource id of the window
90         * @param className
91         *            class name of the window
92         * @param isModal
93         *            modality of the window
94         */
95        protected WindowTreeNode(int hwnd, WindowTreeNode parent,
96                        String windowName, int resourceId, String className, boolean isModal) {
97                this.hwnd = hwnd;
98                this.parent = parent;
99                this.windowName = windowName;
100                this.resourceId = resourceId;
101                this.className = className;
102                this.isModal = isModal;
103                children = new ArrayList<WindowTreeNode>();
104        }
105
106        /**
107         * <p>
108         * Returns a reference to the WindowTreeNode of the parent.
109         * </p>
110         *
111         * @return WindowTreeNode of the parent
112         */
113        public WindowTreeNode getParent() {
114                return parent;
115        }
116
117        /**
118         * <p>
119         * Returns the list of the windows children.
120         * </p>
121         *
122         * @return list of the windows children
123         */
124        public List<WindowTreeNode> getChildren() {
125                return children;
126        }
127
128        /**
129         * <p>
130         * Returns the name of the window.
131         * </p>
132         *
133         * @return name of the window
134         */
135        public String getName() {
136                return windowName;
137        }
138
139        /**
140         * <p>
141         * Returns the hwnd of the window.
142         * </p>
143         *
144         * @return hwnd of the window
145         */
146        public int getHwnd() {
147                return hwnd;
148        }
149
150        /**
151         * <p>
152         * Returns the resource id of the window.
153         * </p>
154         *
155         * @return resource id of the window
156         */
157        public int getResourceId() {
158                return resourceId;
159        }
160
161        /**
162         * <p>
163         * Returns the class name of the window.
164         * </p>
165         *
166         * @return
167         */
168        public String getClassName() {
169                return className;
170        }
171
172        /**
173         * <p>
174         * Sets the name of the window.
175         * </p>
176         *
177         * @param text
178         *            new name of the window
179         */
180        public void setName(String text) {
181                windowName = text;
182        }
183
184        /**
185         * <p>
186         * Removes a the window and all its children from the {@link WindowTree}.
187         * </p>
188         *
189         * @return list of the children of the window for further clean up.
190         */
191        public List<WindowTreeNode> remove() {
192                if (parent != null) {
193                        parent.removeChild(this);
194                }
195                return children;
196        }
197
198        /**
199         * <p>
200         * Removes a child window.
201         * </p>
202         *
203         * @param child
204         *            reference to the child window to be removed
205         */
206        public void removeChild(WindowTreeNode child) {
207                children.remove(child);
208        }
209
210        /**
211         * <p>
212         * Adds a new child window and creates WindowTreeNode for it.
213         * </p>
214         *
215         * @param childHwnd
216         *            hwnd of the child window
217         * @param childWindowName
218         *            name of the child window
219         * @param resourceId
220         *            resource id of the child window
221         * @param className
222         *            class name of the child window
223         * @param isModal
224         *            modality of the child window
225         * @return reference to the WindowTreeNode created for the child window
226         */
227        public WindowTreeNode addChild(int childHwnd, String childWindowName,
228                        int resourceId, String className, boolean isModal) {
229                WindowTreeNode child = new WindowTreeNode(childHwnd, this,
230                                childWindowName, resourceId, className, isModal);
231                children.add(child);
232                return child;
233        }
234
235        /**
236         * <p>
237         * Returns a string identfier of the window:<br>
238         * {@code [resourceId;"windowName";"className";modality]}
239         * </p>
240         *
241         * @return identifier string of the window
242         */
243        @Override
244        public String toString() {
245                return "[" + resourceId + ";\"" + windowName + "\";\"" + className
246                                + "\";" + isModal + "]";
247        }
248
249        /**
250         * <p>
251         * Returns an XML representation of the window, including its parents. It is
252         * defined as follows:<br>
253         * <code>
254         * parent#xmlRepresentation()<br>
255         * &lt;window name="this.windowname" class="this.className" resourceId="this.resourceId" isModal="this.isModel"/&gt;
256         * </code>
257         * </p>
258         *
259         * @return xml representation of the window
260         */
261        public String xmlRepresentation() {
262                String xmlString = "";
263                if (parent != null) {
264                        xmlString = parent.xmlRepresentation();
265                }
266                xmlString += "<window name=\""
267                                + StringTools.xmlEntityReplacement(windowName) + "\" class=\""
268                                + StringTools.xmlEntityReplacement(className)
269                                + "\" resourceId=\"" + resourceId + "\" isModal=\"" + isModal
270                                + "\"/>";
271                return xmlString;
272        }
273
274        /**
275         * <p>
276         * Returns the names of the parents and itself separated by dots, e.g.,
277         * "GrandParent.Parent.windowName"
278         * </p>
279         *
280         * @return names of the parents separated by dots
281         */
282        public String getParentNames() {
283                String parentNames = "";
284                if (parent != null) {
285                        parentNames = parent.getParentNames() + ".";
286                }
287                parentNames += windowName;
288                return parentNames;
289        }
290
291}
Note: See TracBrowser for help on using the repository browser.