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