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

Last change on this file since 1876 was 1876, checked in by pharms, 9 years ago
  • added support for views in GUIs
File size: 5.7 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#getView()
93     */
94    @Override
95    public IGUIView getView() {
96        return null;
97    }
98
99    /* (non-Javadoc)
100     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
101     */
102    @Override
103    public double getDistanceTo(IGUIElement otherElement) {
104        if (equals(otherElement)) {
105            return 0.0;
106        }
107        else if (super.getParent() != null) {
108            return super.getParent().getDistanceTo(otherElement);
109        }
110        else {
111            return 1.0;
112        }
113    }
114
115    /**
116     * <p>
117     * returns the list of GUI elements belonging to this group.
118     * </p>
119     *
120     * @return the GUI elements belonging to this group
121     *
122     */
123    public List<IGUIElement> getGroupedElements() {
124        return Collections.unmodifiableList(groupedGUIElements);
125    }
126   
127    /**
128     * <p>
129     * allows adding a new GUI element to the group
130     * </p>
131     *
132     * @param guiElement the new member of the group
133     */
134    void addToGroup(IGUIElement guiElement) {
135        this.groupedGUIElements.add(guiElement);
136    }
137   
138    /**
139     * <p>
140     * internally required GUI element specification for a GUI element group. This is just a wrapper
141     * for a name of a GUI element group
142     * </p>
143     *
144     * @author Patrick Harms
145     */
146    private static class GroupSpecification implements IGUIElementSpec {
147       
148        /**
149         * <p>
150         * default serial version UID
151         * </p>
152         */
153        private static final long serialVersionUID = 1L;
154       
155        /**
156         * <p>
157         * the name of the GUI element group represented by this specification
158         * </p>
159         */
160        private String name;
161
162        /**
163         * <p>
164         * instantiates the group specification with the given name. Two group specifications
165         * are only similar, if their names match.
166         * </p>
167         *
168         * @param name the name of the group
169         */
170        private GroupSpecification(String name) {
171            super();
172            this.name = name;
173        }
174
175        /* (non-Javadoc)
176         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
177         */
178        @Override
179        public String getType() {
180            return "GUI element group";
181        }
182
183        /* (non-Javadoc)
184         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy()
185         */
186        @Override
187        public String[] getTypeHierarchy() {
188            return new String[] { getType() };
189        }
190
191        /* (non-Javadoc)
192         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
193         */
194        @Override
195        public boolean getSimilarity(IGUIElementSpec other) {
196            return
197                (other instanceof GroupSpecification) &&
198                name.equals(((GroupSpecification) other).name);
199        }
200
201    }
202
203}
Note: See TracBrowser for help on using the repository browser.