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

Last change on this file since 2146 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
RevLine 
[927]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
[922]15package de.ugoe.cs.autoquest.plugin.mfc;
[1]16
[1084]17import org.xml.sax.SAXException;
18
[2146]19import de.ugoe.cs.autoquest.eventcore.EventTargetModelException;
[1006]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;
[1]23
[171]24/**
25 * <p>
[1008]26 * Message handler for {@code WM_CREATE} messages. The handler maintains the {@link GUIElementTree}.
[171]27 * </p>
28 *
29 * @author Steffen Herbold
30 * @version 1.0
31 */
[1]32public class HandlerCreate extends MessageHandler {
33
[619]34    /**
35     * <p>
36     * Constructor. Creates a new HandlerCreate.
37     * </p>
38     *
[1006]39     * @param guiElementTree the tree of GUI element specifications to be created and adapted during
[619]40     *                   parsing
41     */
[1028]42    public HandlerCreate(GUIElementTree<Long> guiElementTree) {
[1006]43        super(guiElementTree);
[619]44    }
[1]45
[619]46    /**
47     * <p>
[1008]48     * Name of the created GUI element.
[619]49     * </p>
50     */
[1008]51    private String guiElementName;
[171]52
[619]53    /**
54     * <p>
[1008]55     * HWND of the created GUI element.
[619]56     * </p>
57     */
58    private long hwnd;
[171]59
[619]60    /**
61     * <p>
[1008]62     * HWND of the created GUI elements's parent.
[619]63     * </p>
64     */
65    private long parentHwnd;
[171]66
[619]67    /**
68     * <p>
[1008]69     * Resource Id of the created element.
[619]70     * </p>
71     */
72    private int resourceId;
[171]73
[619]74    /**
75     * <p>
[1008]76     * GUI element class of the created element.
[619]77     * </p>
78     */
79    private String className;
[171]80
[619]81    /**
82     * <p>
[1008]83     * Modality of the created GUI element.
[619]84     * </p>
85     */
86    private boolean isModal;
[171]87
[619]88    /*
89     * (non-Javadoc)
90     *
[922]91     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onEndElement()
[619]92     */
93    @Override
[1084]94    public void onEndElement() throws SAXException {
[619]95        if (hwnd != 0) {
[1008]96                IGUIElementSpec spec = new MFCGUIElementSpec(hwnd, guiElementName, resourceId, className, isModal);
[1084]97            try {
98                super.getGUIElementTree().add(hwnd, parentHwnd, spec);
99            }
[2146]100            catch (EventTargetModelException e) {
[1084]101                throw new SAXException("could not handle GUI element with handle " +
102                                       hwnd + ": " + e.getMessage(), e);
103            }
[619]104        }
105    }
[1]106
[619]107    /*
108     * (non-Javadoc)
109     *
[922]110     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onParameter(java.lang.String ,
[619]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")) {
[1008]119            guiElementName = value;
[619]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    }
[1]141
[619]142    /*
143     * (non-Javadoc)
144     *
[922]145     * @see de.ugoe.cs.autoquest.plugin.mfc.MessageHandler#onStartElement()
[619]146     */
147    @Override
148    public void onStartElement() {
[1008]149        guiElementName = "";
[619]150        hwnd = 0;
151        parentHwnd = 0;
152        resourceId = 0;
153        className = "";
154        isModal = false;
155    }
[1]156
157}
Note: See TracBrowser for help on using the repository browser.