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