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

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