source: trunk/autoquest-plugin-mfc/src/main/java/de/ugoe/cs/autoquest/plugin/mfc/HandlerCreate.java

Last change on this file was 2146, checked in by pharms, 7 years ago
  • refactored GUI model so that hierarchical event target structures can also be used and created by plugins not being strictly for GUIs
File size: 4.3 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.mfc;
16
17import org.xml.sax.SAXException;
18
19import de.ugoe.cs.autoquest.eventcore.EventTargetModelException;
20import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree;
21import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
22import de.ugoe.cs.autoquest.plugin.mfc.guimodel.MFCGUIElementSpec;
23
24/**
25 * <p>
26 * Message handler for {@code WM_CREATE} messages. The handler maintains the {@link GUIElementTree}.
27 * </p>
28 *
29 * @author Steffen Herbold
30 * @version 1.0
31 */
32public class HandlerCreate extends MessageHandler {
33
34    /**
35     * <p>
36     * Constructor. Creates a new HandlerCreate.
37     * </p>
38     *
39     * @param guiElementTree the tree of GUI element specifications to be created and adapted during
40     *                   parsing
41     */
42    public HandlerCreate(GUIElementTree<Long> guiElementTree) {
43        super(guiElementTree);
44    }
45
46    /**
47     * <p>
48     * Name of the created GUI element.
49     * </p>
50     */
51    private String guiElementName;
52
53    /**
54     * <p>
55     * HWND of the created GUI element.
56     * </p>
57     */
58    private long hwnd;
59
60    /**
61     * <p>
62     * HWND of the created GUI elements's parent.
63     * </p>
64     */
65    private long parentHwnd;
66
67    /**
68     * <p>
69     * Resource Id of the created element.
70     * </p>
71     */
72    private int resourceId;
73
74    /**
75     * <p>
76     * GUI element class of the created element.
77     * </p>
78     */
79    private String className;
80
81    /**
82     * <p>
83     * Modality of the created GUI element.
84     * </p>
85     */
86    private boolean isModal;
87
88    /*
89     * (non-Javadoc)
90     *
91     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onEndElement()
92     */
93    @Override
94    public void onEndElement() throws SAXException {
95        if (hwnd != 0) {
96                IGUIElementSpec spec = new MFCGUIElementSpec(hwnd, guiElementName, resourceId, className, isModal);
97            try {
98                super.getGUIElementTree().add(hwnd, parentHwnd, spec);
99            }
100            catch (EventTargetModelException e) {
101                throw new SAXException("could not handle GUI element with handle " +
102                                       hwnd + ": " + e.getMessage(), e);
103            }
104        }
105    }
106
107    /*
108     * (non-Javadoc)
109     *
110     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onParameter(java.lang.String ,
111     * java.lang.String)
112     */
113    @Override
114    public void onParameter(String name, String value) {
115        if (name.equals("window.hwnd")) {
116            hwnd = Long.parseLong(value);
117        }
118        else if (name.equals("window.name")) {
119            guiElementName = value;
120        }
121        else if (name.equals("window.parent.hwnd")) {
122            parentHwnd = Long.parseLong(value);
123        }
124        else if (name.equals("window.resourceId")) {
125            resourceId = Integer.parseInt(value);
126        }
127        else if (name.equals("window.class")) {
128            if (value.startsWith("Afx:")) {
129                className = "Afx:";
130            }
131            else {
132                className = value;
133            }
134        }
135        else if (name.equals("window.ismodal")) {
136            if (value.equals("true") || value.equals("1")) {
137                isModal = true;
138            }
139        }
140    }
141
142    /*
143     * (non-Javadoc)
144     *
145     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onStartElement()
146     */
147    @Override
148    public void onStartElement() {
149        guiElementName = "";
150        hwnd = 0;
151        parentHwnd = 0;
152        resourceId = 0;
153        className = "";
154        isModal = false;
155    }
156
157}
Note: See TracBrowser for help on using the repository browser.