Changeset 830 for trunk/quest-core-events/src
- Timestamp:
- 09/19/12 16:25:42 (12 years ago)
- Location:
- trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/TextInput.java
r786 r830 2 2 package de.ugoe.cs.quest.eventcore.gui; 3 3 4 import java.util.Collections; 4 5 import java.util.List; 5 6 … … 138 139 /** 139 140 * <p> 140 * Returns the events of which this {@link TextInput} consists. 141 * Returns the events of which this {@link TextInput} consists. The returned list is immutable. 141 142 * </p> 142 143 * … … 144 145 */ 145 146 public List<Event> getTextInputEvents() { 146 // TODO should return an immutable view on the list 147 return textInputEvents; 147 return Collections.unmodifiableList(textInputEvents); 148 148 } 149 149 -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/TextInputDetector.java
r786 r830 1 1 2 package de.ugoe.cs.quest.eventcore.gui; 2 3 … … 20 21 /** 21 22 * <p> 22 * The text input detector iterates a list of events and searches for subsequent key events. 23 * Those are replaced by a single text input event representing the text entered through the key24 * events.The replacement is only done, if the key events have a text field or text area as target23 * The text input detector iterates a list of events and searches for subsequent key events. Those 24 * are replaced by a single text input event representing the text entered through the key events. 25 * The replacement is only done, if the key events have a text field or text area as target 25 26 * </p> 26 27 * … … 29 30 */ 30 31 public class TextInputDetector { 31 32 /** the keyboard map to use for character recognition */32 33 /** the keyboard map to use for character recognition */ 33 34 private KeyboardMap keyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 34 35 35 36 /** the keys pressed in parallel */ 36 37 List<VirtualKey> pressedKeys = new ArrayList<VirtualKey>(); 37 38 38 39 private final TextEquality textEqualityType; 39 40 /** 41 * <p> 42 * TODO: comment 43 * </p> 44 * 40 41 /** 42 * <p> 43 * Constructor. Creates a new TextInputDectector that generates {@link TextInput} with 44 * {@link TextEquality#LEXICAL} equality. 45 * </p> 46 * 45 47 */ 46 48 public TextInputDetector() { 47 49 this(TextEquality.LEXICAL); 48 50 } 49 51 52 /** 53 * <p> 54 * Constructor. Creates a new TextInputDectector that generates {@link TextInput} with a given 55 * {@link TextEquality} type. 56 * </p> 57 * 58 * @param textEqualityType 59 * equality type of the generated events 60 */ 50 61 public TextInputDetector(TextEquality textEqualityType) { 51 62 this.textEqualityType = textEqualityType; … … 54 65 /** 55 66 * <p> 56 * in the provided list of events, this method detects any event sequences that consists of 57 * key interactions and replaces them with a single text input interaction. This contains 58 * the entered text as well as the replaced key interaction events 59 * </p> 60 * 61 * @param sequence the event sequence to search for text input events 67 * in the provided list of events, this method detects any event sequences that consists of key 68 * interactions and replaces them with a single text input interaction. This contains the 69 * entered text as well as the replaced key interaction events 70 * </p> 71 * 72 * @param sequence 73 * the event sequence to search for text input events 62 74 * 63 75 * @return the resulting sequence, in which key interactions on text fields and areas are … … 66 78 public List<Event> detectTextInputs(List<Event> sequence) { 67 79 List<Event> resultingSequence = new LinkedList<Event>(); 68 80 69 81 int textEntryStartIndex = -1; 70 82 IEventTarget lastEventTarget = null; … … 76 88 currentEvent = sequence.get(index); 77 89 textInputEvent = null; 78 90 79 91 if (isKeyInteraction(currentEvent) && isDataInputEventTarget(currentEvent.getTarget())) 80 92 { … … 84 96 } 85 97 else if (!lastEventTarget.equals(currentEvent.getTarget())) { 86 textInputEvent = handleTextEntrySequence 87 (sequence, textEntryStartIndex, index - 1, lastEventTarget); 88 98 textInputEvent = 99 handleTextEntrySequence(sequence, textEntryStartIndex, index - 1, 100 lastEventTarget); 101 89 102 textEntryStartIndex = index; 90 103 lastEventTarget = currentEvent.getTarget(); … … 94 107 else { 95 108 if (textEntryStartIndex >= 0) { 96 textInputEvent = handleTextEntrySequence 97 (sequence, textEntryStartIndex, index - 1, lastEventTarget); 98 109 textInputEvent = 110 handleTextEntrySequence(sequence, textEntryStartIndex, index - 1, 111 lastEventTarget); 112 99 113 textEntryStartIndex = -1; 100 114 lastEventTarget = null; 101 115 } 102 116 103 117 } 104 118 … … 106 120 resultingSequence.add(textInputEvent); 107 121 } 108 122 109 123 if (currentEvent != null) { 110 124 resultingSequence.add(currentEvent); 111 125 } 112 126 113 127 index++; 114 128 } 115 129 116 130 if (textEntryStartIndex >= 0) { 117 textInputEvent = handleTextEntrySequence 118 (sequence, textEntryStartIndex, sequence.size() - 1, lastEventTarget); 119 131 textInputEvent = 132 handleTextEntrySequence(sequence, textEntryStartIndex, sequence.size() - 1, 133 lastEventTarget); 134 120 135 if (textInputEvent != null) { 121 136 resultingSequence.add(textInputEvent); … … 131 146 * </p> 132 147 * 133 * @param event the even to check 148 * @param event 149 * the even to check 134 150 * 135 151 * @return as described … … 142 158 * <p> 143 159 * creates a single text input event as replacement for key interactions being part of the 144 * subsequence of events denoted by the start and end index in the provide event sequence. If 145 * no text was entered, because the subsequence only contained key released events, then no146 * textinput event is generated (the method returns null).160 * subsequence of events denoted by the start and end index in the provide event sequence. If no 161 * text was entered, because the subsequence only contained key released events, then no text 162 * input event is generated (the method returns null). 147 163 * </p> 148 164 * … … 157 173 * the event target to be used for the new event 158 174 * 159 * @return a text input event representing the text input resulting from the events of 160 * theprovided subsequence175 * @return a text input event representing the text input resulting from the events of the 176 * provided subsequence 161 177 * 162 178 * @throws IllegalArgumentException 163 179 * if the denoted subsequence contains other events than key interactions 164 180 */ 165 private Event handleTextEntrySequence(List<Event> 166 int 167 int 181 private Event handleTextEntrySequence(List<Event> sequence, 182 int startIndex, 183 int endIndex, 168 184 IEventTarget eventTarget) 169 185 { … … 171 187 172 188 String enteredText = determineEnteredText(sequence, startIndex, endIndex, textInputEvents); 173 189 174 190 if ((enteredText != null) && (!"".equals(enteredText))) { 175 191 TextInput textInput = new TextInput(enteredText, textInputEvents, textEqualityType); … … 186 202 * </p> 187 203 * 188 * @param eventTarget the event target to check 204 * @param eventTarget 205 * the event target to check 189 206 * 190 207 * @return true, if it is a text field or a text area ; false else … … 223 240 */ 224 241 private String determineEnteredText(List<Event> sequence, 225 int 226 int 242 int startIndex, 243 int endIndex, 227 244 List<Event> textInputEvents) 228 245 throws IllegalArgumentException … … 230 247 Event event; 231 248 StringBuffer enteredText = new StringBuffer(); 232 249 233 250 for (int i = startIndex; i <= endIndex; i++) { 234 251 event = sequence.get(i); 235 252 236 253 if (event.getType() instanceof KeyPressed || event.getType() instanceof KeyTyped) { 237 254 VirtualKey key = ((KeyInteraction) event.getType()).getKey(); … … 257 274 } 258 275 } 259 else if (event.getType() instanceof KeyReleased || event.getType() instanceof KeyTyped) { 276 else if (event.getType() instanceof KeyReleased || event.getType() instanceof KeyTyped) 277 { 260 278 pressedKeys.remove(((KeyInteraction) event.getType()).getKey()); 261 279 } 262 280 else { 263 throw new IllegalArgumentException 264 ("the subsequence denoted by the indexes contains other interactions than " +265 "just key strokes");266 } 267 281 throw new IllegalArgumentException( 282 "the subsequence denoted by the indexes contains other interactions than " 283 + "just key strokes"); 284 } 285 268 286 textInputEvents.add(event); 269 287 } 270 288 271 289 if (enteredText.length() > 0) { 272 290 return enteredText.toString(); … … 283 301 * </p> 284 302 * 285 * @param key the key for which the character shall be determined 286 * @param pressedKeys the list of other keys pressed in parallel 303 * @param key 304 * the key for which the character shall be determined 305 * @param pressedKeys 306 * the list of other keys pressed in parallel 287 307 * 288 308 * @return the character resulting from the combination of pressed keys -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/TextSelection.java
r681 r830 1 1 2 package de.ugoe.cs.quest.eventcore.gui; 2 3 3 4 /** 4 * TODO comment 5 * <p> 6 * Event type for selecting text. 7 * </p> 5 8 * 6 * @version $Revision: $ $Date: $7 * @author 2011, last modified by $Author: $9 * @version 1.0 10 * @author Patrick Harms 8 11 */ 9 12 public class TextSelection implements IInteraction { 10 13 11 /** */ 14 /** 15 * <p> 16 * Id for object serialization. 17 * </p> 18 */ 12 19 private static final long serialVersionUID = 1L; 13 20 … … 48 55 return false; 49 56 } 50 57 51 58 /* 52 59 * (non-Javadoc) -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/ValueSelection.java
r655 r830 1 1 2 package de.ugoe.cs.quest.eventcore.gui; 2 3 3 4 /** 4 * TODO comment 5 * <p> 6 * Event type for selecting a value. 7 * </p> 5 8 * 6 * @version $Revision: $ $Date: $7 * @author 2011, last modified by $Author: $9 * @version 1.0 10 * @author Patrick Harms 8 11 */ 9 12 public class ValueSelection<T> implements IInteraction { 10 11 /** */ 13 14 /** 15 * <p> 16 * Id for object serialization. 17 * </p> 18 */ 12 19 private static final long serialVersionUID = 1L; 13 20 14 /** */ 21 /** 22 * <p> 23 * The selected value. 24 * </p> 25 */ 15 26 private T selectedValue; 16 27 17 28 /** 18 * TODO: comment 29 * <p> 30 * Constructor. Creates a new ValueSelection. 31 * </p> 19 32 * 20 33 * @param selectedValue 34 * the selected value 21 35 */ 22 36 public ValueSelection(T selectedValue) { … … 62 76 63 77 /** 78 * <p> 79 * Returns the selected value associated with this event. 80 * </p> 81 * 64 82 * @return the selectedValue 65 83 */ … … 81 99 ValueSelection<?> otherValueSelection = (ValueSelection<?>) obj; 82 100 83 return 84 ((otherValueSelection != null) && 85 ((selectedValue == otherValueSelection.selectedValue) || 86 ((selectedValue != null) && 87 (selectedValue.equals(otherValueSelection.selectedValue))))); 101 return ((otherValueSelection != null) && ((selectedValue == otherValueSelection.selectedValue) || ((selectedValue != null) && (selectedValue 102 .equals(otherValueSelection.selectedValue))))); 88 103 } 89 104 90 /* (non-Javadoc) 105 /* 106 * (non-Javadoc) 107 * 91 108 * @see java.lang.Object#hashCode() 92 109 */
Note: See TracChangeset
for help on using the changeset viewer.