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
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
[2146]17import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec;
[922]18import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
[1490]19import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
[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
[2146]127    public void updateSpecification(IEventTargetSpec furtherSpec) {
128        if (furtherSpec instanceof MFCGUIElementSpec) {
129            ((MFCGUIElementSpec) super.getSpecification()).update((MFCGUIElementSpec) furtherSpec);
130        }
[619]131    }
[837]132
133    /*
134     * (non-Javadoc)
135     *
[922]136     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
[837]137     */
[681]138    @Override
139    public String getStringIdentifier() {
140        String str = this.toString();
[837]141        if (getParent() != null) {
[994]142            return str + "<-" + getParent().getStringIdentifier();
[681]143        }
144        return str;
145    }
[619]146
[837]147    /*
148     * (non-Javadoc)
149     *
[619]150     * @see java.lang.Object#toString()
151     */
152    @Override
153    public String toString() {
154        return super.getSpecification().toString();
155    }
156
[1490]157    /* (non-Javadoc)
[1876]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)
[1490]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
[619]179    /**
180     * <p>
[837]181     * Returns the XML representation of the GUI element.
[619]182     * </p>
[837]183     *
184     * @return the XML representation
[619]185     */
186    public String toXML() {
187        if (getParent() != null) {
[837]188            return ((MFCGUIElement) getParent()).toXML() +
[619]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.