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

Last change on this file was 2218, checked in by pharms, 7 years ago
  • java doc issues removal
  • Property svn:mime-type set to text/plain
File size: 5.5 KB
RevLine 
[2146]1//   Copyright 2015 Georg-August-Universität Göttingen, Germany
[1260]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
[2146]17import de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetGroup;
18import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec;
[1260]19
20/**
21 * <p>
[2146]22 * implementation of event target groups for GUI elements
[1260]23 * </p>
24 *
25 * @author Patrick Harms
26 */
[2146]27public class GUIElementGroup extends HierarchicalEventTargetGroup implements IGUIElement {
[1260]28
[2146]29    /**  */
[1260]30    private static final long serialVersionUID = 1L;
31   
[2146]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;
[1260]37
38    /**
39     * <p>
40     * instantiates a GUI element group with a name and its optional parent GUI element
41     * </p>
42     *
[2218]43     * @param groupName  the name of the GUI element group
44     * @param parent     the optional parent GUI element of the group
45     * @param guiModel   the GUI model to which the group will belong
[1260]46     */
[2146]47    public GUIElementGroup(String      groupName,
48                           IGUIElement parent,
49                           GUIModel    guiModel)
50    {
51        super(groupName, parent, guiModel);
52        groupSpecification = new GroupSpecification(groupName);
[1260]53    }
54
55    /* (non-Javadoc)
[2146]56     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getSpecification()
[1260]57     */
58    @Override
[2146]59    public IGUIElementSpec getSpecification() {
60        return groupSpecification;
[1260]61    }
62
63    /* (non-Javadoc)
64     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier()
65     */
66    @Override
67    public String getStringIdentifier() {
[2146]68        return groupSpecification.name;
[1260]69    }
70
71    /* (non-Javadoc)
[2146]72     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getParent()
[1260]73     */
74    @Override
[2146]75    public IGUIElement getParent() {
76        return (IGUIElement) super.getParent();
[1260]77    }
78
[1490]79    /* (non-Javadoc)
[1876]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)
[2146]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)
[1490]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        }
[2146]119        else if (getParent() != null) {
120            return getParent().getDistanceTo(otherElement);
[1490]121        }
122        else {
123            return 1.0;
124        }
125    }
[1260]126   
127    /**
[1274]128     * <p>
[1260]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       
[1274]137        /**
138         * <p>
139         * default serial version UID
140         * </p>
141         */
[1260]142        private static final long serialVersionUID = 1L;
[1274]143       
[1260]144        /**
[1274]145         * <p>
[1260]146         * the name of the GUI element group represented by this specification
[1274]147         * </p>
[1260]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)
[2146]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)
[1260]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.