source: trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/TextInput.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
File size: 5.9 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.gui;
16
17import java.util.Collections;
18import java.util.List;
19
20import de.ugoe.cs.autoquest.eventcore.Event;
21
22/**
23 * <p>
24 * A text input represents a list of key events that together represent entering text into a text
25 * field or text area.
26 * </p>
27 *
28 * @version 1.0
29 * @author Patrick Harms, Steffen Herbold
30 */
31public class TextInput implements IInteraction {
32
33    /**
34     * <p>
35     * Defines how the {@link TextInput}s are evaluated as equal.
36     * </p>
37     *
38     * @version 1.0
39     * @author Steffen Herbold
40     */
41    public enum TextEquality {
42        /**
43         * <p>
44         * Two text inputs are equal if their {@link TextInput#textInputEvents} are equal.
45         * </p>
46         */
47        LEXICAL,
48        /**
49         * <p>
50         * Two text inputs are equal if their {@link TextInput#enteredText}s are equal.
51         * </p>
52         */
53        SYNTACTICAL,
54        /**
55         * <p>
56         * All text inputs are equal.
57         * </p>
58         */
59        SEMANTICAL
60    };
61
62    /**
63     * <p>
64     * Id for object serialization.
65     * </p>
66     */
67    private static final long serialVersionUID = 1L;
68
69    /**
70     * <p>
71     * The text resulting from the text input events.
72     * </p>
73     */
74    private String enteredText;
75
76    /**
77     * <p>
78     * The text input events that caused the entering of the text.
79     * </p>
80     */
81    private List<Event> textInputEvents;
82
83    /**
84     * <p>
85     * Defines how this TextInput event evaluates the equality.
86     * </p>
87     */
88    private final TextEquality equalityType;
89
90    /**
91     * <p>
92     * Constructor. Creates a new {@link TextInput} with {@link TextEquality#LEXICAL} equality.
93     * </p>
94     *
95     * @param enteredText
96     *            text resulting from the inputs
97     * @param textInputEvents
98     *            text input events of which this input consists
99     */
100    public TextInput(String enteredText, List<Event> textInputEvents) {
101        this(enteredText, textInputEvents, TextEquality.LEXICAL);
102    }
103
104    /**
105     * <p>
106     * Constructor. Creates a new {@link TextInput}..
107     * </p>
108     *
109     * @param enteredText
110     *            text resulting from the inputs
111     * @param textInputEvents
112     *            text input events of which this input consists
113     * @param equalityType
114     *            defines how this event evaluates the equality (@see {@link TextEquality})
115     */
116    public TextInput(String enteredText, List<Event> textInputEvents, TextEquality equalityType) {
117        this.enteredText = enteredText;
118        this.textInputEvents = textInputEvents;
119        this.equalityType = equalityType;
120    }
121
122    /*
123     * (non-Javadoc)
124     *
125     * @see de.harms.attef.userinteraction.Interaction#getName()
126     */
127    public String getName() {
128        return "TextInput(\"" + enteredText + "\")";
129    }
130
131    /*
132     * (non-Javadoc)
133     *
134     * @see java.lang.Object#toString()
135     */
136    @Override
137    public String toString() {
138        return "text input \"" + enteredText + "\"";
139    }
140
141    /**
142     * <p>
143     * Returns the entered text.
144     * </p>
145     *
146     * @return the entered text
147     */
148    public String getEnteredText() {
149        return enteredText;
150    }
151
152    /**
153     * <p>
154     * Returns the events of which this {@link TextInput} consists. The returned list is immutable.
155     * </p>
156     *
157     * @return the textInputEvents
158     */
159    public List<Event> getTextInputEvents() {
160        return Collections.unmodifiableList(textInputEvents);
161    }
162
163    /*
164     * (non-Javadoc)
165     *
166     * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()
167     */
168    public boolean startsLogicalSequence() {
169        return false;
170    }
171
172    /*
173     * (non-Javadoc)
174     *
175     * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence()
176     */
177    public boolean finishesLogicalSequence() {
178        return false;
179    }
180
181    /*
182     * (non-Javadoc)
183     *
184     * @see java.lang.Object#equals(java.lang.Object)
185     */
186    @Override
187    public boolean equals(Object obj) {
188        if (this == obj) {
189            return true;
190        }
191        else if (obj instanceof TextInput) {
192            switch (equalityType)
193            {
194                case LEXICAL:
195                    return textInputEvents.equals(((TextInput) obj).textInputEvents);
196                case SYNTACTICAL:
197                    return enteredText.equals(((TextInput) obj).enteredText);
198                case SEMANTICAL:
199                    return true;
200                default:
201                    throw new AssertionError("reached source code that should be unreachable");
202            }
203        }
204        return false;
205    }
206
207    /*
208     * (non-Javadoc)
209     *
210     * @see java.lang.Object#hashCode()
211     */
212    @Override
213    public int hashCode() {
214        int hashCode = getClass().hashCode();
215        if (equalityType == TextEquality.LEXICAL) {
216            hashCode += enteredText.hashCode() + textInputEvents.size();
217        }
218        else if (equalityType == TextEquality.SYNTACTICAL) {
219            hashCode += enteredText.hashCode();
220        }
221        return hashCode;
222    }
223
224}
Note: See TracBrowser for help on using the repository browser.