Changeset 780 for trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/KeyInteractionSorter.java
- Timestamp:
- 09/06/12 13:14:24 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/KeyInteractionSorter.java
r765 r780 14 14 15 15 /** 16 *17 16 * <p> 18 * TODO comment 17 * This class provides the functionality to sort and clean up all key interactions in a log. In 18 * particular: 19 * <ol> 20 * <li>In case a combination key (e.g., shift, alt, control) is held down, multiple 21 * {@link KeyPressed} events are logged, even though only the first one is of importance. This class 22 * removes all {@link KeyPressed} events for combination keys except the first.</li> 23 * <li>In case a normal key is held down, multiple {@link KeyPressed} events are logged, but there 24 * is only one {@link KeyReleased} event. This class adds a {@link KeyReleased} event for all such 25 * {@link KeyPressed} events.</li> 26 * <li>Due to message filtering of applications, it is possible that a {@link KeyReleased} event 27 * without a preceding {@link KeyPressed} event is logged. This class either adds the missing 28 * {@link KeyPressed} right in front of the {@link KeyReleased} or removes the {@link KeyReleased} 29 * depending on the {@link #mode}. 30 * <li>As a result of steps 2-3, we have always a matching {@link KeyPressed}/{@link KeyReleased} 31 * pairs for all normal keys. This class replaces these pairs with a {@link KeyTyped} event at the 32 * position of the {@link KeyPressed} event.</li> 33 * <li>Sometimes combination keys are not released in the same order they have been pressed. This 34 * class ensures that the {@link KeyReleased} are in the opposite order of the {@link KeyPressed} 35 * events for all combination keys.</li> 36 * </ol> 19 37 * </p> 20 38 * 21 * @version $Revision: $ $Date: Sep 4, 2012$22 * @author 2012, last modified by $Author: sherbold$39 * @version 1.0 40 * @author Steffen Herbold 23 41 */ 24 42 public class KeyInteractionSorter { … … 29 47 * </p> 30 48 * 31 * @version $Revision: $ $Date: Sep 3, 2012$32 * @author 2012, last modified by $Author: sherbold$49 * @version 1.0 50 * @author Steffen Herbold 33 51 */ 34 52 public static enum CleanupMode { 35 REMOVAL, ADDITION 53 /** 54 * <p> 55 * Single {@link KeyReleased} are removed from the sequence. 56 * </p> 57 */ 58 REMOVAL, 59 60 /** 61 * <p> 62 * {@link KeyPressed} events are added to single {@link KeyReleased} events 63 * </p> 64 */ 65 ADDITION 36 66 }; 37 67 68 /** 69 * <p> 70 * 71 * </p> 72 */ 38 73 private final CleanupMode mode; 39 74 75 /** 76 * <p> 77 * Constructor. Creates a new {@link KeyInteractionSorter} with {@link #mode}= 78 * {@link CleanupMode#ADDITION}. 79 * </p> 80 */ 40 81 public KeyInteractionSorter() { 41 82 this(CleanupMode.ADDITION); 42 83 } 43 84 85 /** 86 * <p> 87 * Constructor. Creates a new {@link KeyInteractionSorter}. 88 * </p> 89 * 90 * @param mode 91 * {@link #mode} of the instance 92 */ 44 93 public KeyInteractionSorter(CleanupMode mode) { 45 94 this.mode = mode; 46 95 } 47 96 97 /** 98 * <p> 99 * Sorts and cleans up key interactions according to the class specification (@see 100 * {@link KeyInteractionSorter} class comment). 101 * </p> 102 * <p> 103 * This method returns a sorted copy of a sequence, the sequence itself is not changed. 104 * </p> 105 * 106 * @param sequence 107 * sequence which is sorted 108 * @return sorted copy of sequence 109 */ 48 110 public List<Event> sortKeyInteractions(final List<Event> sequence) { 49 111 List<Event> sortedSequence = new LinkedList<Event>(sequence); … … 55 117 } 56 118 119 /** 120 * <p> 121 * Performs tasks 1-4 defined in the class description. Operations are performed in-place on the 122 * passed sequence. 123 * </p> 124 * 125 * @param sequence 126 * sequence which is sorted 127 */ 57 128 private void sortCombinationKeyPairs(List<Event> sequence) { 58 129 LinkedList<VirtualKey> pressedCombinationKeys = new LinkedList<VirtualKey>(); … … 99 170 } 100 171 172 /** 173 * <p> 174 * Performs task 5 defined in the class description. Operations are performed in-place on the 175 * passed sequence. 176 * </p> 177 * 178 * @param sequence 179 * sequence which is sorted 180 */ 101 181 private void handleIncompleteKeyPairs(List<Event> sequence) { 102 182 Set<VirtualKey> pressedKeys = new HashSet<VirtualKey>();
Note: See TracChangeset
for help on using the changeset viewer.