[927] | 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.
|
---|
[786] | 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.eventcore.gui;
|
---|
[544] | 16 |
|
---|
[830] | 17 | import java.util.Collections;
|
---|
[687] | 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
[687] | 21 |
|
---|
[544] | 22 | /**
|
---|
[687] | 23 | * <p>
|
---|
[786] | 24 | * A text input represents a list of key events that together represent entering text into a text
|
---|
| 25 | * field or text area.
|
---|
[687] | 26 | * </p>
|
---|
[544] | 27 | *
|
---|
[786] | 28 | * @version 1.0
|
---|
| 29 | * @author Patrick Harms, Steffen Herbold
|
---|
[544] | 30 | */
|
---|
| 31 | public class TextInput implements IInteraction {
|
---|
| 32 |
|
---|
[786] | 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 | */
|
---|
[544] | 67 | private static final long serialVersionUID = 1L;
|
---|
[786] | 68 |
|
---|
| 69 | /**
|
---|
| 70 | * <p>
|
---|
| 71 | * The text resulting from the text input events.
|
---|
| 72 | * </p>
|
---|
| 73 | */
|
---|
[687] | 74 | private String enteredText;
|
---|
[544] | 75 |
|
---|
[786] | 76 | /**
|
---|
| 77 | * <p>
|
---|
| 78 | * The text input events that caused the entering of the text.
|
---|
| 79 | * </p>
|
---|
| 80 | */
|
---|
[687] | 81 | private List<Event> textInputEvents;
|
---|
[786] | 82 |
|
---|
| 83 | /**
|
---|
| 84 | * <p>
|
---|
| 85 | * Defines how this TextInput event evaluates the equality.
|
---|
| 86 | * </p>
|
---|
| 87 | */
|
---|
[751] | 88 | private final TextEquality equalityType;
|
---|
[687] | 89 |
|
---|
| 90 | /**
|
---|
| 91 | * <p>
|
---|
[786] | 92 | * Constructor. Creates a new {@link TextInput} with {@link TextEquality#LEXICAL} equality.
|
---|
[687] | 93 | * </p>
|
---|
[786] | 94 | *
|
---|
[687] | 95 | * @param enteredText
|
---|
[786] | 96 | * text resulting from the inputs
|
---|
[687] | 97 | * @param textInputEvents
|
---|
[786] | 98 | * text input events of which this input consists
|
---|
[687] | 99 | */
|
---|
| 100 | public TextInput(String enteredText, List<Event> textInputEvents) {
|
---|
[751] | 101 | this(enteredText, textInputEvents, TextEquality.LEXICAL);
|
---|
| 102 | }
|
---|
[786] | 103 |
|
---|
[751] | 104 | /**
|
---|
| 105 | * <p>
|
---|
[786] | 106 | * Constructor. Creates a new {@link TextInput}..
|
---|
[751] | 107 | * </p>
|
---|
[786] | 108 | *
|
---|
[751] | 109 | * @param enteredText
|
---|
[786] | 110 | * text resulting from the inputs
|
---|
[751] | 111 | * @param textInputEvents
|
---|
[786] | 112 | * text input events of which this input consists
|
---|
[751] | 113 | * @param equalityType
|
---|
[786] | 114 | * defines how this event evaluates the equality (@see {@link TextEquality})
|
---|
[751] | 115 | */
|
---|
| 116 | public TextInput(String enteredText, List<Event> textInputEvents, TextEquality equalityType) {
|
---|
[687] | 117 | this.enteredText = enteredText;
|
---|
| 118 | this.textInputEvents = textInputEvents;
|
---|
[751] | 119 | this.equalityType = equalityType;
|
---|
[687] | 120 | }
|
---|
| 121 |
|
---|
[544] | 122 | /*
|
---|
| 123 | * (non-Javadoc)
|
---|
| 124 | *
|
---|
| 125 | * @see de.harms.attef.userinteraction.Interaction#getName()
|
---|
| 126 | */
|
---|
| 127 | public String getName() {
|
---|
[687] | 128 | return "TextInput(\"" + enteredText + "\")";
|
---|
[544] | 129 | }
|
---|
| 130 |
|
---|
| 131 | /*
|
---|
| 132 | * (non-Javadoc)
|
---|
| 133 | *
|
---|
| 134 | * @see java.lang.Object#toString()
|
---|
| 135 | */
|
---|
| 136 | @Override
|
---|
| 137 | public String toString() {
|
---|
[687] | 138 | return "text input \"" + enteredText + "\"";
|
---|
[544] | 139 | }
|
---|
| 140 |
|
---|
[687] | 141 | /**
|
---|
[786] | 142 | * <p>
|
---|
| 143 | * Returns the entered text.
|
---|
| 144 | * </p>
|
---|
| 145 | *
|
---|
| 146 | * @return the entered text
|
---|
[687] | 147 | */
|
---|
| 148 | public String getEnteredText() {
|
---|
| 149 | return enteredText;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /**
|
---|
[786] | 153 | * <p>
|
---|
[830] | 154 | * Returns the events of which this {@link TextInput} consists. The returned list is immutable.
|
---|
[786] | 155 | * </p>
|
---|
| 156 | *
|
---|
[687] | 157 | * @return the textInputEvents
|
---|
| 158 | */
|
---|
| 159 | public List<Event> getTextInputEvents() {
|
---|
[830] | 160 | return Collections.unmodifiableList(textInputEvents);
|
---|
[687] | 161 | }
|
---|
| 162 |
|
---|
[544] | 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 | }
|
---|
[786] | 180 |
|
---|
[681] | 181 | /*
|
---|
| 182 | * (non-Javadoc)
|
---|
| 183 | *
|
---|
| 184 | * @see java.lang.Object#equals(java.lang.Object)
|
---|
| 185 | */
|
---|
| 186 | @Override
|
---|
| 187 | public boolean equals(Object obj) {
|
---|
[687] | 188 | if (this == obj) {
|
---|
[681] | 189 | return true;
|
---|
| 190 | }
|
---|
[687] | 191 | else if (obj instanceof TextInput) {
|
---|
[751] | 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 | }
|
---|
[687] | 203 | }
|
---|
[681] | 204 | return false;
|
---|
| 205 | }
|
---|
[544] | 206 |
|
---|
[681] | 207 | /*
|
---|
| 208 | * (non-Javadoc)
|
---|
| 209 | *
|
---|
| 210 | * @see java.lang.Object#hashCode()
|
---|
| 211 | */
|
---|
| 212 | @Override
|
---|
| 213 | public int hashCode() {
|
---|
[751] | 214 | int hashCode = getClass().hashCode();
|
---|
[786] | 215 | if (equalityType == TextEquality.LEXICAL) {
|
---|
[751] | 216 | hashCode += enteredText.hashCode() + textInputEvents.size();
|
---|
| 217 | }
|
---|
[786] | 218 | else if (equalityType == TextEquality.SYNTACTICAL) {
|
---|
[751] | 219 | hashCode += enteredText.hashCode();
|
---|
| 220 | }
|
---|
| 221 | return hashCode;
|
---|
[681] | 222 | }
|
---|
| 223 |
|
---|
[544] | 224 | }
|
---|