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 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.mfc.guimodel;
|
---|
16 |
|
---|
17 | import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
|
---|
18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
|
---|
19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
20 | import 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 | */
|
---|
30 | public 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(IGUIElementSpec furtherSpec) {
|
---|
128 | ((MFCGUIElementSpec) super.getSpecification()).update(furtherSpec);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*
|
---|
132 | * (non-Javadoc)
|
---|
133 | *
|
---|
134 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
|
---|
135 | */
|
---|
136 | @Override
|
---|
137 | public String getStringIdentifier() {
|
---|
138 | String str = this.toString();
|
---|
139 | if (getParent() != null) {
|
---|
140 | return str + "<-" + getParent().getStringIdentifier();
|
---|
141 | }
|
---|
142 | return str;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * (non-Javadoc)
|
---|
147 | *
|
---|
148 | * @see java.lang.Object#toString()
|
---|
149 | */
|
---|
150 | @Override
|
---|
151 | public String toString() {
|
---|
152 | return super.getSpecification().toString();
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* (non-Javadoc)
|
---|
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)
|
---|
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 |
|
---|
177 | /**
|
---|
178 | * <p>
|
---|
179 | * Returns the XML representation of the GUI element.
|
---|
180 | * </p>
|
---|
181 | *
|
---|
182 | * @return the XML representation
|
---|
183 | */
|
---|
184 | public String toXML() {
|
---|
185 | if (getParent() != null) {
|
---|
186 | return ((MFCGUIElement) getParent()).toXML() +
|
---|
187 | ((MFCGUIElementSpec) super.getSpecification()).toXML();
|
---|
188 | }
|
---|
189 | else {
|
---|
190 | return ((MFCGUIElementSpec) super.getSpecification()).toXML();
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|