Ignore:
Timestamp:
09/19/12 16:25:42 (12 years ago)
Author:
sherbold
Message:
  • TextInput? now returns an unmodifiable view of the internal event list
  • code documentation and formating
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  
    22package de.ugoe.cs.quest.eventcore.gui; 
    33 
     4import java.util.Collections; 
    45import java.util.List; 
    56 
     
    138139    /** 
    139140     * <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. 
    141142     * </p> 
    142143     *  
     
    144145     */ 
    145146    public List<Event> getTextInputEvents() { 
    146         // TODO should return an immutable view on the list 
    147         return textInputEvents; 
     147        return Collections.unmodifiableList(textInputEvents); 
    148148    } 
    149149 
  • trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/TextInputDetector.java

    r786 r830  
     1 
    12package de.ugoe.cs.quest.eventcore.gui; 
    23 
     
    2021/** 
    2122 * <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 key 
    24  * events. The replacement is only done, if the key events have a text field or text area as target 
     23 * 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 
    2526 * </p> 
    2627 *  
     
    2930 */ 
    3031public class TextInputDetector { 
    31      
    32     /** the keyboard map to use for character recognition*/ 
     32 
     33    /** the keyboard map to use for character recognition */ 
    3334    private KeyboardMap keyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
    34      
     35 
    3536    /** the keys pressed in parallel */ 
    3637    List<VirtualKey> pressedKeys = new ArrayList<VirtualKey>(); 
    37      
     38 
    3839    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     *  
    4547     */ 
    4648    public TextInputDetector() { 
    4749        this(TextEquality.LEXICAL); 
    4850    } 
    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     */ 
    5061    public TextInputDetector(TextEquality textEqualityType) { 
    5162        this.textEqualityType = textEqualityType; 
     
    5465    /** 
    5566     * <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 
    6274     *  
    6375     * @return the resulting sequence, in which key interactions on text fields and areas are 
     
    6678    public List<Event> detectTextInputs(List<Event> sequence) { 
    6779        List<Event> resultingSequence = new LinkedList<Event>(); 
    68          
     80 
    6981        int textEntryStartIndex = -1; 
    7082        IEventTarget lastEventTarget = null; 
     
    7688            currentEvent = sequence.get(index); 
    7789            textInputEvent = null; 
    78              
     90 
    7991            if (isKeyInteraction(currentEvent) && isDataInputEventTarget(currentEvent.getTarget())) 
    8092            { 
     
    8496                } 
    8597                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 
    89102                    textEntryStartIndex = index; 
    90103                    lastEventTarget = currentEvent.getTarget(); 
     
    94107            else { 
    95108                if (textEntryStartIndex >= 0) { 
    96                     textInputEvent = handleTextEntrySequence 
    97                         (sequence, textEntryStartIndex, index - 1, lastEventTarget); 
    98                      
     109                    textInputEvent = 
     110                        handleTextEntrySequence(sequence, textEntryStartIndex, index - 1, 
     111                                                lastEventTarget); 
     112 
    99113                    textEntryStartIndex = -1; 
    100114                    lastEventTarget = null; 
    101115                } 
    102                  
     116 
    103117            } 
    104118 
     
    106120                resultingSequence.add(textInputEvent); 
    107121            } 
    108              
     122 
    109123            if (currentEvent != null) { 
    110124                resultingSequence.add(currentEvent); 
    111125            } 
    112              
     126 
    113127            index++; 
    114128        } 
    115129 
    116130        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 
    120135            if (textInputEvent != null) { 
    121136                resultingSequence.add(textInputEvent); 
     
    131146     * </p> 
    132147     *  
    133      * @param event the even to check 
     148     * @param event 
     149     *            the even to check 
    134150     *  
    135151     * @return as described 
     
    142158     * <p> 
    143159     * 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 no 
    146      * text input 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). 
    147163     * </p> 
    148164     *  
     
    157173     *            the event target to be used for the new event 
    158174     *  
    159      * @return a text input event representing the text input resulting from the events of 
    160      *         the provided subsequence 
     175     * @return a text input event representing the text input resulting from the events of the 
     176     *         provided subsequence 
    161177     *  
    162178     * @throws IllegalArgumentException 
    163179     *             if the denoted subsequence contains other events than key interactions 
    164180     */ 
    165     private Event handleTextEntrySequence(List<Event>  sequence, 
    166                                           int          startIndex, 
    167                                           int          endIndex, 
     181    private Event handleTextEntrySequence(List<Event> sequence, 
     182                                          int startIndex, 
     183                                          int endIndex, 
    168184                                          IEventTarget eventTarget) 
    169185    { 
     
    171187 
    172188        String enteredText = determineEnteredText(sequence, startIndex, endIndex, textInputEvents); 
    173          
     189 
    174190        if ((enteredText != null) && (!"".equals(enteredText))) { 
    175191            TextInput textInput = new TextInput(enteredText, textInputEvents, textEqualityType); 
     
    186202     * </p> 
    187203     *  
    188      * @param eventTarget the event target to check 
     204     * @param eventTarget 
     205     *            the event target to check 
    189206     *  
    190207     * @return true, if it is a text field or a text area ; false else 
     
    223240     */ 
    224241    private String determineEnteredText(List<Event> sequence, 
    225                                         int         startIndex, 
    226                                         int         endIndex, 
     242                                        int startIndex, 
     243                                        int endIndex, 
    227244                                        List<Event> textInputEvents) 
    228245        throws IllegalArgumentException 
     
    230247        Event event; 
    231248        StringBuffer enteredText = new StringBuffer(); 
    232          
     249 
    233250        for (int i = startIndex; i <= endIndex; i++) { 
    234251            event = sequence.get(i); 
    235              
     252 
    236253            if (event.getType() instanceof KeyPressed || event.getType() instanceof KeyTyped) { 
    237254                VirtualKey key = ((KeyInteraction) event.getType()).getKey(); 
     
    257274                } 
    258275            } 
    259             else if (event.getType() instanceof KeyReleased || event.getType() instanceof KeyTyped) { 
     276            else if (event.getType() instanceof KeyReleased || event.getType() instanceof KeyTyped) 
     277            { 
    260278                pressedKeys.remove(((KeyInteraction) event.getType()).getKey()); 
    261279            } 
    262280            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 
    268286            textInputEvents.add(event); 
    269287        } 
    270          
     288 
    271289        if (enteredText.length() > 0) { 
    272290            return enteredText.toString(); 
     
    283301     * </p> 
    284302     *  
    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 
    287307     *  
    288308     * @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 
    12package de.ugoe.cs.quest.eventcore.gui; 
    23 
    34/** 
    4  * TODO comment 
     5 * <p> 
     6 * Event type for selecting text. 
     7 * </p> 
    58 *  
    6  * @version $Revision: $ $Date: $ 
    7  * @author 2011, last modified by $Author: $ 
     9 * @version 1.0 
     10 * @author Patrick Harms 
    811 */ 
    912public class TextSelection implements IInteraction { 
    1013 
    11     /**  */ 
     14    /** 
     15     * <p> 
     16     * Id for object serialization. 
     17     * </p> 
     18     */ 
    1219    private static final long serialVersionUID = 1L; 
    1320 
     
    4855        return false; 
    4956    } 
    50      
     57 
    5158    /* 
    5259     * (non-Javadoc) 
  • trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/gui/ValueSelection.java

    r655 r830  
     1 
    12package de.ugoe.cs.quest.eventcore.gui; 
    23 
    34/** 
    4  * TODO comment 
     5 * <p> 
     6 * Event type for selecting a value. 
     7 * </p> 
    58 *  
    6  * @version $Revision: $ $Date: $ 
    7  * @author 2011, last modified by $Author: $ 
     9 * @version 1.0 
     10 * @author Patrick Harms 
    811 */ 
    912public class ValueSelection<T> implements IInteraction { 
    10      
    11     /**  */ 
     13 
     14    /** 
     15     * <p> 
     16     * Id for object serialization. 
     17     * </p> 
     18     */ 
    1219    private static final long serialVersionUID = 1L; 
    1320 
    14     /** */ 
     21    /** 
     22     * <p> 
     23     * The selected value. 
     24     * </p> 
     25     */ 
    1526    private T selectedValue; 
    1627 
    1728    /** 
    18      * TODO: comment 
     29     * <p> 
     30     * Constructor. Creates a new ValueSelection. 
     31     * </p> 
    1932     *  
    2033     * @param selectedValue 
     34     *            the selected value 
    2135     */ 
    2236    public ValueSelection(T selectedValue) { 
     
    6276 
    6377    /** 
     78     * <p> 
     79     * Returns the selected value associated with this event. 
     80     * </p> 
     81     *  
    6482     * @return the selectedValue 
    6583     */ 
     
    8199        ValueSelection<?> otherValueSelection = (ValueSelection<?>) obj; 
    82100 
    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))))); 
    88103    } 
    89104 
    90     /* (non-Javadoc) 
     105    /* 
     106     * (non-Javadoc) 
     107     *  
    91108     * @see java.lang.Object#hashCode() 
    92109     */ 
Note: See TracChangeset for help on using the changeset viewer.