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

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