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

Last change on this file since 2146 was 2146, checked in by pharms, 7 years ago
  • refactored GUI model so that hierarchical event target structures can also be used and created by plugins not being strictly for GUIs
  • Property svn:mime-type set to text/plain
File size: 5.5 KB
Line 
1//   Copyright 2015 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 de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetGroup;
18import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec;
19
20/**
21 * <p>
22 * implementation of event target groups for GUI elements
23 * </p>
24 *
25 * @author Patrick Harms
26 */
27public class GUIElementGroup extends HierarchicalEventTargetGroup implements IGUIElement {
28
29    /**  */
30    private static final long serialVersionUID = 1L;
31   
32    /** the internal fake event target specification */
33    private GroupSpecification groupSpecification;
34   
35    /** stores if the usage of the group was observed (just to match the implemented interface */
36    private boolean usageObserved = false;
37
38    /**
39     * <p>
40     * instantiates a GUI element group with a name and its optional parent GUI element
41     * </p>
42     *
43     * @param groupName        the name of the GUI element group
44     * @param parent           the optional parent GUI element of the group
45     * @param eventTargetModel the GUI model to which the group will belong
46     */
47    public GUIElementGroup(String      groupName,
48                           IGUIElement parent,
49                           GUIModel    guiModel)
50    {
51        super(groupName, parent, guiModel);
52        groupSpecification = new GroupSpecification(groupName);
53    }
54
55    /* (non-Javadoc)
56     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getSpecification()
57     */
58    @Override
59    public IGUIElementSpec getSpecification() {
60        return groupSpecification;
61    }
62
63    /* (non-Javadoc)
64     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
65     */
66    @Override
67    public String getStringIdentifier() {
68        return groupSpecification.name;
69    }
70
71    /* (non-Javadoc)
72     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getParent()
73     */
74    @Override
75    public IGUIElement getParent() {
76        return (IGUIElement) super.getParent();
77    }
78
79    /* (non-Javadoc)
80     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getView()
81     */
82    @Override
83    public IGUIView getView() {
84        return null;
85    }
86
87    /* (non-Javadoc)
88     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getGUIModel()
89     */
90    @Override
91    public GUIModel getGUIModel() {
92        return (GUIModel) super.getEventTargetModel();
93    }
94
95    /* (non-Javadoc)
96     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#isUsed()
97     */
98    @Override
99    public boolean isUsed() {
100        return usageObserved;
101    }
102
103    /* (non-Javadoc)
104     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#markUsed()
105     */
106    @Override
107    public void markUsed() {
108        usageObserved = true;
109    }
110
111    /* (non-Javadoc)
112     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
113     */
114    @Override
115    public double getDistanceTo(IGUIElement otherElement) {
116        if (equals(otherElement)) {
117            return 0.0;
118        }
119        else if (getParent() != null) {
120            return getParent().getDistanceTo(otherElement);
121        }
122        else {
123            return 1.0;
124        }
125    }
126   
127    /**
128     * <p>
129     * internally required GUI element specification for a GUI element group. This is just a wrapper
130     * for a name of a GUI element group
131     * </p>
132     *
133     * @author Patrick Harms
134     */
135    private static class GroupSpecification implements IGUIElementSpec {
136       
137        /**
138         * <p>
139         * default serial version UID
140         * </p>
141         */
142        private static final long serialVersionUID = 1L;
143       
144        /**
145         * <p>
146         * the name of the GUI element group represented by this specification
147         * </p>
148         */
149        private String name;
150
151        /**
152         * <p>
153         * instantiates the group specification with the given name. Two group specifications
154         * are only similar, if their names match.
155         * </p>
156         *
157         * @param name the name of the group
158         */
159        private GroupSpecification(String name) {
160            super();
161            this.name = name;
162        }
163
164        /* (non-Javadoc)
165         * @see de.ugoe.cs.autoquest.eventcore.IEventTargetSpec#getSimilarity(IEventTargetSpec)
166         */
167        @Override
168        public boolean getSimilarity(IEventTargetSpec other) {
169            return
170                (other instanceof GroupSpecification) &&
171                name.equals(((GroupSpecification) other).name);
172        }
173
174        /* (non-Javadoc)
175         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
176         */
177        @Override
178        public String getType() {
179            return "GUI element group";
180        }
181
182        /* (non-Javadoc)
183         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy()
184         */
185        @Override
186        public String[] getTypeHierarchy() {
187            return new String[] { getType() };
188        }
189
190    }
191}
Note: See TracBrowser for help on using the repository browser.