source: trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/guimodel/JFCGUIElement.java @ 1678

Last change on this file since 1678 was 1678, checked in by dmay, 10 years ago

current progress: generate valid jacareto xml files and start replaying mouse clicks

  • Property svn:executable set to *
File size: 5.5 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.jfc.guimodel;
16
17import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
18import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
19import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
20
21/**
22 * <p>
23 * Base class for all JFC GUI elements.
24 * </p>
25 *
26 * @version 1.0
27 * @author Patrick Harms
28 */
29public class JFCGUIElement extends AbstractDefaultGUIElement {
30
31    /**
32     * <p>
33     * Id for object serialization.
34     * </p>
35     */
36    private static final long serialVersionUID = 1L;
37
38    /**
39     * <p>
40     * Specification of the GUI Element
41     * </p>
42     */
43    private JFCGUIElementSpec specification;
44
45    /**
46     * <p>
47     * Constructor. Creates a new JFCGUIElement.
48     * </p>
49     *
50     * @param specification
51     *            specification of created GUI element
52     * @param parent
53     *            parent of the created GUI element; null means that the element is a top-level
54     *            window
55     */
56    public JFCGUIElement(JFCGUIElementSpec specification, JFCGUIElement parent) {
57        super(specification, parent);
58        this.specification = specification;
59    }
60
61    /*
62     * (non-Javadoc)
63     *
64     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
65     */
66    @Override
67    public String getPlatform() {
68        return "JFC";
69    }
70
71    /**
72     * <p>
73     * Returns the type of the GUI element, i.e., the name of its Java class.
74     * </p>
75     *
76     * @return the Java class name
77     */
78    public String getJavaType() {
79        return specification.getType();
80    }
81
82    /**
83     * <p>
84     * Returns the name of the GUI element.
85     * </p>
86     *
87     * @return the name
88     */
89    public String getName() {
90        return specification.getName();
91    }
92
93    /**
94     * <p>
95     * Returns the icon of the GUI element.
96     * </p>
97     *
98     * @return the icon
99     */
100    String getIcon() {
101        return specification.getIcon();
102    }
103
104    /**
105     * <p>
106     * Returns the index of the GUI element.
107     * </p>
108     *
109     * @return the index
110     */
111    int getIndex() {
112        return specification.getIndex();
113    }
114
115    /**
116     * <p>
117     * Returns the object hash of the GUI element.
118     * </p>
119     *
120     * @return the object hash
121     */
122    int getElementHash() {
123        return specification.getElementHash();
124    }
125
126    /*
127     * (non-Javadoc)
128     *
129     * @see
130     * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest
131     * .eventcore .guimodel.IGUIElementSpec)
132     */
133    @Override
134    public void updateSpecification(IGUIElementSpec updateSpecification) {
135        if (updateSpecification instanceof JFCGUIElementSpec) {
136            specification.update(((JFCGUIElementSpec) updateSpecification));
137        }
138    }
139
140    /*
141     * (non-Javadoc)
142     *
143     * @see java.lang.Object#toString()
144     */
145    @Override
146    public String getStringIdentifier() {
147        String str = this.toString();
148        if (getParent() != null) {
149            return str + "<-" + getParent().getStringIdentifier();
150        }
151        return str;
152    }
153
154    public String getJacaretoHierarchy() {
155        String str;
156
157        // get the Java classname, ignore the package hierarchy if present
158        String[] parts = getSpecification().getType().split("\\.");
159        String name = parts[parts.length - 1];
160
161        // find the correct Jacareto index
162        // jacareto indices start at 1
163        int jacIndex = getIndex() + 1;
164        // some class specific hacks
165        if (name.equals("JFrame")) {
166            jacIndex++;
167        }
168        else if (name.equals("JLayeredPane")) {
169            jacIndex--;
170        }
171
172        str = parts[parts.length - 1] + "_(" + jacIndex + ")";
173
174        if (getParent() != null) {
175            return ((JFCGUIElement) getParent()).getJacaretoHierarchy() + "." + str;
176        }
177        return str;
178    }
179
180    /*
181     * (non-Javadoc)
182     *
183     * @see java.lang.Object#toString()
184     */
185    @Override
186    public String toString() {
187        String str =
188            getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," + getIcon() +
189                "," + getIndex() + ")";
190        return str;
191    }
192
193    /*
194     * (non-Javadoc)
195     *
196     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
197     */
198    @Override
199    public double getDistanceTo(IGUIElement otherElement) {
200        throw new UnsupportedOperationException("not implemented yet");
201    }
202
203    /**
204     * <p>
205     * A short string describing the GUI element, e.g., Button, Canvas, or ScrollBar.
206     * </p>
207     *
208     * @return short element descriptor
209     */
210    protected String getElementDescriptor() {
211        return "Default";
212    }
213
214}
Note: See TracBrowser for help on using the repository browser.