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

Last change on this file since 751 was 751, checked in by sherbold, 12 years ago
  • TextInput? events can now be configured to support a specific type of equality: Lexical, Syntactical, and Semantical
  • the command detextTestInputEvents now allows the definition of the equality of the generated TextInput? events (see above)
File size: 3.8 KB
Line 
1package de.ugoe.cs.quest.eventcore.gui;
2
3import java.util.List;
4
5import de.ugoe.cs.quest.eventcore.Event;
6
7/**
8 * <p>
9 * A text input represents a list of key events that together represent entering text into a
10 * text field or text area.
11 * </p>
12 *
13 * @version $Revision: $ $Date: $
14 * @author 2011, last modified by $Author: $
15 */
16public class TextInput implements IInteraction {
17   
18    public enum TextEquality {LEXICAL, SYNTACTICAL, SEMANTICAL};
19
20    /**  */
21    private static final long serialVersionUID = 1L;
22   
23    /** the text resulting from the text input events */
24    private String enteredText;
25
26    /** the text input events that caused the entering of the text */
27    private List<Event> textInputEvents;
28   
29    private final TextEquality equalityType;
30
31    /**
32     * <p>
33     * TODO: comment
34     * </p>
35     *
36     * @param enteredText
37     * @param textInputEvents
38     */
39    public TextInput(String enteredText, List<Event> textInputEvents) {
40        this(enteredText, textInputEvents, TextEquality.LEXICAL);
41    }
42   
43    /**
44     * <p>
45     * TODO: comment
46     * </p>
47     *
48     * @param enteredText
49     * @param textInputEvents
50     * @param equalityType
51     */
52    public TextInput(String enteredText, List<Event> textInputEvents, TextEquality equalityType) {
53        this.enteredText = enteredText;
54        this.textInputEvents = textInputEvents;
55        this.equalityType = equalityType;
56    }
57
58    /*
59     * (non-Javadoc)
60     *
61     * @see de.harms.attef.userinteraction.Interaction#getName()
62     */
63    public String getName() {
64        return "TextInput(\"" + enteredText + "\")";
65    }
66
67    /*
68     * (non-Javadoc)
69     *
70     * @see java.lang.Object#toString()
71     */
72    @Override
73    public String toString() {
74        return "text input \"" + enteredText + "\"";
75    }
76
77    /**
78     * @return the enteredText
79     */
80    public String getEnteredText() {
81        return enteredText;
82    }
83
84    /**
85     * @return the textInputEvents
86     */
87    public List<Event> getTextInputEvents() {
88        return textInputEvents;
89    }
90
91    /*
92     * (non-Javadoc)
93     *
94     * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()
95     */
96    public boolean startsLogicalSequence() {
97        return false;
98    }
99
100    /*
101     * (non-Javadoc)
102     *
103     * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence()
104     */
105    public boolean finishesLogicalSequence() {
106        return false;
107    }
108   
109    /*
110     * (non-Javadoc)
111     *
112     * @see java.lang.Object#equals(java.lang.Object)
113     */
114    @Override
115    public boolean equals(Object obj) {
116        if (this == obj) {
117            return true;
118        }
119        else if (obj instanceof TextInput) {
120            switch (equalityType)
121            {
122                case LEXICAL:
123                    return textInputEvents.equals(((TextInput) obj).textInputEvents);
124                case SYNTACTICAL:
125                    return enteredText.equals(((TextInput) obj).enteredText);
126                case SEMANTICAL:
127                    return true;
128                default:
129                    throw new AssertionError("reached source code that should be unreachable");
130            }
131        }
132        return false;
133    }
134
135    /*
136     * (non-Javadoc)
137     *
138     * @see java.lang.Object#hashCode()
139     */
140    @Override
141    public int hashCode() {
142        int hashCode = getClass().hashCode();
143        if( equalityType==TextEquality.LEXICAL) {
144            hashCode += enteredText.hashCode() + textInputEvents.size();
145        }
146        else if( equalityType==TextEquality.SYNTACTICAL) {
147            hashCode += enteredText.hashCode();
148        }
149        return hashCode;
150    }
151
152}
Note: See TracBrowser for help on using the repository browser.