source: trunk/autoquest-plugin-mfc/src/main/java/de/ugoe/cs/autoquest/plugin/mfc/guimodel/MFCGUIElement.java @ 1876

Last change on this file since 1876 was 1876, checked in by pharms, 9 years ago
  • added support for views in GUIs
  • Property svn:executable set to *
File size: 5.2 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.
[837]14
[922]15package de.ugoe.cs.autoquest.plugin.mfc.guimodel;
[619]16
[922]17import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
[1490]18import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
[922]19import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
[1876]20import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView;
[619]21
22/**
[837]23 * <p>
24 * Base class that represents GUI element in MFC GUIs.
25 * </p>
[619]26 *
[837]27 * @version 1.0
28 * @author Patrick Harms
[619]29 */
30public abstract class MFCGUIElement extends AbstractDefaultGUIElement {
[837]31
32    /**
33     * <p>
34     * Id for object serialization.
35     * </p>
36     */
[619]37    private static final long serialVersionUID = 1L;
38
39    /**
[837]40     * <p>
41     * Constructor. Creates a new MFCGUIElement.
42     * </p>
43     *
44     * @param specification
45     *            specification of created GUI element
46     * @param parent
47     *            parent of the created GUI element; null means that the element is a top-level
48     *            window
[619]49     */
50    public MFCGUIElement(MFCGUIElementSpec specification, MFCGUIElement parent) {
51        super(specification, parent);
52    }
53
[837]54    /*
55     * (non-Javadoc)
56     *
[922]57     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
[619]58     */
59    @Override
60    public String getPlatform() {
61        return "MFC";
62    }
63
64    /**
[837]65     * <p>
66     * Returns the HWND (Id) of the GUI element.
67     * </p>
68     *
69     * @return the HWND (Id)
[619]70     */
71    public String getId() {
72        return Long.toString(((MFCGUIElementSpec) super.getSpecification()).getHwnd());
73    }
74
75    /**
[837]76     * <p>
77     * Returns the type of the GUI element.
78     * </p>
79     *
80     * @return the type
[619]81     */
82    public String getType() {
83        return ((MFCGUIElementSpec) super.getSpecification()).getType();
84    }
85
86    /**
[837]87     * <p>
88     * Returns the name of the GUI element.
89     * </p>
90     *
91     * @return the name
[619]92     */
93    public String getName() {
94        return ((MFCGUIElementSpec) super.getSpecification()).getName();
95    }
96
97    /**
[837]98     * <p>
99     * Returns the modality of the GUI element.
100     * </p>
101     *
102     * @return the modality
[619]103     */
104    public boolean isModal() {
105        return ((MFCGUIElementSpec) super.getSpecification()).isModal();
106    }
107
108    /**
109     * <p>
[837]110     * Returns the resource Id of the GUI element.
[619]111     * </p>
[837]112     *
113     * @return the resource Id
[619]114     */
115    public int getResourceId() {
116        return ((MFCGUIElementSpec) super.getSpecification()).getResourceId();
117    }
118
[837]119    /*
120     * (non-Javadoc)
121     *
122     * @see
[922]123     * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore
[837]124     * .guimodel.IGUIElementSpec)
[619]125     */
126    @Override
127    public void updateSpecification(IGUIElementSpec furtherSpec) {
128        ((MFCGUIElementSpec) super.getSpecification()).update(furtherSpec);
129    }
[837]130
131    /*
132     * (non-Javadoc)
133     *
[922]134     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
[837]135     */
[681]136    @Override
137    public String getStringIdentifier() {
138        String str = this.toString();
[837]139        if (getParent() != null) {
[994]140            return str + "<-" + getParent().getStringIdentifier();
[681]141        }
142        return str;
143    }
[619]144
[837]145    /*
146     * (non-Javadoc)
147     *
[619]148     * @see java.lang.Object#toString()
149     */
150    @Override
151    public String toString() {
152        return super.getSpecification().toString();
153    }
154
[1490]155    /* (non-Javadoc)
[1876]156     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getView()
157     */
158    @Override
159    public IGUIView getView() {
160        IGUIElement element = this;
161       
162        while ((element != null) && (!(element instanceof IGUIView))) {
163            element = element.getParent();
164        }
165       
166        return (IGUIView) element;
167    }
168
169    /* (non-Javadoc)
[1490]170     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
171     */
172    @Override
173    public double getDistanceTo(IGUIElement otherElement) {
174        throw new UnsupportedOperationException("not implemented yet");
175    }
176
[619]177    /**
178     * <p>
[837]179     * Returns the XML representation of the GUI element.
[619]180     * </p>
[837]181     *
182     * @return the XML representation
[619]183     */
184    public String toXML() {
185        if (getParent() != null) {
[837]186            return ((MFCGUIElement) getParent()).toXML() +
[619]187                ((MFCGUIElementSpec) super.getSpecification()).toXML();
188        }
189        else {
190            return ((MFCGUIElementSpec) super.getSpecification()).toXML();
191        }
192    }
193}
Note: See TracBrowser for help on using the repository browser.