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 | |
---|
15 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
16 | |
---|
17 | import java.util.Collections; |
---|
18 | import java.util.LinkedList; |
---|
19 | import 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 | */ |
---|
31 | public 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 | */ |
---|
53 | public GUIElementGroup(String groupName, IGUIElement parent) { |
---|
54 | super(new GroupSpecification(groupName), parent); |
---|
55 | } |
---|
56 | |
---|
57 | /* (non-Javadoc) |
---|
58 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(IGUIElementSpec) |
---|
59 | */ |
---|
60 | @Override |
---|
61 | public final void updateSpecification(IGUIElementSpec furtherSpec) { |
---|
62 | // do nothing |
---|
63 | } |
---|
64 | |
---|
65 | /* (non-Javadoc) |
---|
66 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() |
---|
67 | */ |
---|
68 | @Override |
---|
69 | public String getPlatform() { |
---|
70 | return "none"; |
---|
71 | } |
---|
72 | |
---|
73 | /* (non-Javadoc) |
---|
74 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier() |
---|
75 | */ |
---|
76 | @Override |
---|
77 | public String getStringIdentifier() { |
---|
78 | return ((GroupSpecification) super.getSpecification()).name; |
---|
79 | } |
---|
80 | |
---|
81 | /* (non-Javadoc) |
---|
82 | * @see java.lang.Object#toString() |
---|
83 | */ |
---|
84 | @Override |
---|
85 | public String toString() { |
---|
86 | return getStringIdentifier(); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * <p> |
---|
91 | * returns the list of GUI elements belonging to this group. |
---|
92 | * </p> |
---|
93 | * |
---|
94 | * @return the GUI elements belonging to this group |
---|
95 | * |
---|
96 | */ |
---|
97 | public List<IGUIElement> getGroupedElements() { |
---|
98 | return Collections.unmodifiableList(groupedGUIElements); |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * <p> |
---|
103 | * allows adding a new GUI element to the group |
---|
104 | * </p> |
---|
105 | * |
---|
106 | * @param guiElement the new member of the group |
---|
107 | */ |
---|
108 | void addToGroup(IGUIElement guiElement) { |
---|
109 | this.groupedGUIElements.add(guiElement); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * <p> |
---|
114 | * internally required GUI element specification for a GUI element group. This is just a wrapper |
---|
115 | * for a name of a GUI element group |
---|
116 | * </p> |
---|
117 | * |
---|
118 | * @author Patrick Harms |
---|
119 | */ |
---|
120 | private static class GroupSpecification implements IGUIElementSpec { |
---|
121 | |
---|
122 | /** |
---|
123 | * <p> |
---|
124 | * default serial version UID |
---|
125 | * </p> |
---|
126 | */ |
---|
127 | private static final long serialVersionUID = 1L; |
---|
128 | |
---|
129 | /** |
---|
130 | * <p> |
---|
131 | * the name of the GUI element group represented by this specification |
---|
132 | * </p> |
---|
133 | */ |
---|
134 | private String name; |
---|
135 | |
---|
136 | /** |
---|
137 | * <p> |
---|
138 | * instantiates the group specification with the given name. Two group specifications |
---|
139 | * are only similar, if their names match. |
---|
140 | * </p> |
---|
141 | * |
---|
142 | * @param name the name of the group |
---|
143 | */ |
---|
144 | private GroupSpecification(String name) { |
---|
145 | super(); |
---|
146 | this.name = name; |
---|
147 | } |
---|
148 | |
---|
149 | /* (non-Javadoc) |
---|
150 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType() |
---|
151 | */ |
---|
152 | @Override |
---|
153 | public String getType() { |
---|
154 | return "GUI element group"; |
---|
155 | } |
---|
156 | |
---|
157 | /* (non-Javadoc) |
---|
158 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy() |
---|
159 | */ |
---|
160 | @Override |
---|
161 | public String[] getTypeHierarchy() { |
---|
162 | return new String[] { getType() }; |
---|
163 | } |
---|
164 | |
---|
165 | /* (non-Javadoc) |
---|
166 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
167 | */ |
---|
168 | @Override |
---|
169 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
170 | return |
---|
171 | (other instanceof GroupSpecification) && |
---|
172 | name.equals(((GroupSpecification) other).name); |
---|
173 | } |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | } |
---|