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

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