source: trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/GUIElementGroup.java @ 1490

Last change on this file since 1490 was 1490, checked in by pharms, 10 years ago
  • added support and initial implementation of a platform specific distance measure between GUI elements
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.eventcore.guimodel;
16
17import java.util.Collections;
18import java.util.LinkedList;
19import java.util.List;
20
21/**
22 * <p>
23 * This class is a dummy GUI element to represent groups of GUI elements. A group of GUI elements
24 * can be integrated in any GUI model using the method
25 * {@link GUIModel#groupGUIElements(java.util.List, String)}. A group has the same behavior as
26 * any other parent GUI element.
27 * </p>
28 *
29 * @author Patrick Harms
30 */
31public class GUIElementGroup extends AbstractDefaultGUIElement {
32
33    /**
34     * <p>
35     * default serial version UID
36     * </p>
37     */
38    private static final long serialVersionUID = 1L;
39   
40    /**
41     * the list of grouped GUIElements
42     */
43    private List<IGUIElement> groupedGUIElements = new LinkedList<IGUIElement>();
44
45    /**
46     * <p>
47     * instantiates a GUI element group with a name and its optional parent GUI element
48     * </p>
49     *
50     * @param groupName the name of the GUI element group
51     * @param parent    the optional parent GUI element of the group
52     * @param guiModel  the GUI model to which the group will belong
53     */
54    public GUIElementGroup(String groupName, IGUIElement parent, GUIModel guiModel) {
55        super(new GroupSpecification(groupName), parent);
56        super.setGUIModel(guiModel);
57    }
58
59    /* (non-Javadoc)
60     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(IGUIElementSpec)
61     */
62    @Override
63    public final void updateSpecification(IGUIElementSpec furtherSpec) {
64        // do nothing
65    }
66
67    /* (non-Javadoc)
68     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
69     */
70    @Override
71    public String getPlatform() {
72        return "none";
73    }
74
75    /* (non-Javadoc)
76     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
77     */
78    @Override
79    public String getStringIdentifier() {
80        return ((GroupSpecification) super.getSpecification()).name;
81    }
82
83    /* (non-Javadoc)
84     * @see java.lang.Object#toString()
85     */
86    @Override
87    public String toString() {
88        return getStringIdentifier();
89    }
90
91    /* (non-Javadoc)
92     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
93     */
94    @Override
95    public double getDistanceTo(IGUIElement otherElement) {
96        if (equals(otherElement)) {
97            return 0.0;
98        }
99        else if (super.getParent() != null) {
100            return super.getParent().getDistanceTo(otherElement);
101        }
102        else {
103            return 1.0;
104        }
105    }
106
107    /**
108     * <p>
109     * returns the list of GUI elements belonging to this group.
110     * </p>
111     *
112     * @return the GUI elements belonging to this group
113     *
114     */
115    public List<IGUIElement> getGroupedElements() {
116        return Collections.unmodifiableList(groupedGUIElements);
117    }
118   
119    /**
120     * <p>
121     * allows adding a new GUI element to the group
122     * </p>
123     *
124     * @param guiElement the new member of the group
125     */
126    void addToGroup(IGUIElement guiElement) {
127        this.groupedGUIElements.add(guiElement);
128    }
129   
130    /**
131     * <p>
132     * internally required GUI element specification for a GUI element group. This is just a wrapper
133     * for a name of a GUI element group
134     * </p>
135     *
136     * @author Patrick Harms
137     */
138    private static class GroupSpecification implements IGUIElementSpec {
139       
140        /**
141         * <p>
142         * default serial version UID
143         * </p>
144         */
145        private static final long serialVersionUID = 1L;
146       
147        /**
148         * <p>
149         * the name of the GUI element group represented by this specification
150         * </p>
151         */
152        private String name;
153
154        /**
155         * <p>
156         * instantiates the group specification with the given name. Two group specifications
157         * are only similar, if their names match.
158         * </p>
159         *
160         * @param name the name of the group
161         */
162        private GroupSpecification(String name) {
163            super();
164            this.name = name;
165        }
166
167        /* (non-Javadoc)
168         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
169         */
170        @Override
171        public String getType() {
172            return "GUI element group";
173        }
174
175        /* (non-Javadoc)
176         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy()
177         */
178        @Override
179        public String[] getTypeHierarchy() {
180            return new String[] { getType() };
181        }
182
183        /* (non-Javadoc)
184         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
185         */
186        @Override
187        public boolean getSimilarity(IGUIElementSpec other) {
188            return
189                (other instanceof GroupSpecification) &&
190                name.equals(((GroupSpecification) other).name);
191        }
192
193    }
194
195}
Note: See TracBrowser for help on using the repository browser.