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