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

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

Implement new command, that generates Jacareto indices. Also, get rid of all previous index hacks.

  • Property svn:executable set to *
File size: 5.4 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
160        // find the correct Jacareto index
161        // jacareto indices start at 1
162        int jacIndex = ((JFCGUIElementSpec) getSpecification()).getAltIndex() + 1;
163        str = parts[parts.length - 1] + "_(" + jacIndex + ")";
164
165        if (getParent() != null) {
166            return ((JFCGUIElement) getParent()).getJacaretoHierarchy() + "." + str;
167        }
168        return str;
169    }
170
171    public String getJacaretoRoot() {
172        return getJacaretoHierarchy().split("\\.")[0];
173    }
174
175    /*
176     * (non-Javadoc)
177     *
178     * @see java.lang.Object#toString()
179     */
180    @Override
181    public String toString() {
182        String str =
183            getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," + getIcon() +
184                "," + getIndex() + ")";
185        return str;
186    }
187
188    /*
189     * (non-Javadoc)
190     *
191     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
192     */
193    @Override
194    public double getDistanceTo(IGUIElement otherElement) {
195        throw new UnsupportedOperationException("not implemented yet");
196    }
197
198    /**
199     * <p>
200     * A short string describing the GUI element, e.g., Button, Canvas, or ScrollBar.
201     * </p>
202     *
203     * @return short element descriptor
204     */
205    protected String getElementDescriptor() {
206        return "Default";
207    }
208
209}
Note: See TracBrowser for help on using the repository browser.