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

Last change on this file since 1260 was 1260, checked in by pharms, 11 years ago
  • added support for grouping GUI elements
  • performance improvements
  • extended merge support for including non-recursive merges
  • added switch for validation
File size: 4.6 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    private static final long serialVersionUID = 1L;
35   
36    /**
37     * the list of grouped GUIElements
38     */
39    private List<IGUIElement> groupedGUIElements = new LinkedList<IGUIElement>();
40
41    /**
42     * <p>
43     * instantiates a GUI element group with a name and its optional parent GUI element
44     * </p>
45     *
46     * @param groupName the name of the GUI element group
47     * @param parent    the optional parent GUI element of the group
48     */
49    public GUIElementGroup(String groupName, IGUIElement parent) {
50        super(new GroupSpecification(groupName), parent);
51    }
52
53    /* (non-Javadoc)
54     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(IGUIElementSpec)
55     */
56    @Override
57    public final void updateSpecification(IGUIElementSpec furtherSpec) {
58        // do nothing
59    }
60
61    /* (non-Javadoc)
62     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
63     */
64    @Override
65    public String getPlatform() {
66        return "none";
67    }
68
69    /* (non-Javadoc)
70     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
71     */
72    @Override
73    public String getStringIdentifier() {
74        return ((GroupSpecification) super.getSpecification()).name;
75    }
76
77    /* (non-Javadoc)
78     * @see java.lang.Object#toString()
79     */
80    @Override
81    public String toString() {
82        return getStringIdentifier();
83    }
84
85    /**
86     * <p>
87     * TODO: comment
88     * </p>
89     *
90     * @param guiElement
91     */
92    public void addToGroup(IGUIElement guiElement) {
93        this.groupedGUIElements.add(guiElement);
94    }
95   
96    /**
97     *
98     */
99    public List<IGUIElement> getGroupedElements() {
100        return Collections.unmodifiableList(groupedGUIElements);
101    }
102   
103    /**
104     * <p>
105     * internally required GUI element specification for a GUI element group. This is just a wrapper
106     * for a name of a GUI element group
107     * </p>
108     *
109     * @author Patrick Harms
110     */
111    private static class GroupSpecification implements IGUIElementSpec {
112       
113        /**  */
114        private static final long serialVersionUID = 1L;
115        /**
116         * the name of the GUI element group represented by this specification
117         */
118        private String name;
119
120        /**
121         * <p>
122         * instantiates the group specification with the given name. Two group specifications
123         * are only similar, if their names match.
124         * </p>
125         *
126         * @param name the name of the group
127         */
128        private GroupSpecification(String name) {
129            super();
130            this.name = name;
131        }
132
133        /* (non-Javadoc)
134         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
135         */
136        @Override
137        public String getType() {
138            return "GUI element group";
139        }
140
141        /* (non-Javadoc)
142         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy()
143         */
144        @Override
145        public String[] getTypeHierarchy() {
146            return new String[] { getType() };
147        }
148
149        /* (non-Javadoc)
150         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
151         */
152        @Override
153        public boolean getSimilarity(IGUIElementSpec other) {
154            return
155                (other instanceof GroupSpecification) &&
156                name.equals(((GroupSpecification) other).name);
157        }
158
159    }
160
161}
Note: See TracBrowser for help on using the repository browser.