Changeset 1688


Ignore:
Timestamp:
08/21/14 16:01:12 (10 years ago)
Author:
dmay
Message:

Finally implement focus events; this was a lot more work than expected. The <structure> part of a Jacareto xml file is now represented by a tree because it seems really hard to write this directly as a sequence.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java

    r1686 r1688  
    3636import de.ugoe.cs.util.console.GlobalDataContainer; 
    3737 
     38 
     39// helper class for the tree like structure part within a Jacareto file 
     40class StructureNode { 
     41    public String content; 
     42    public ArrayList<StructureNode> children; 
     43 
     44    public StructureNode(String content) { 
     45        this.content = content; 
     46        this.children = new ArrayList<StructureNode>(); 
     47    } 
     48 
     49    public StructureNode add(String content) { 
     50        StructureNode node = new StructureNode(content); 
     51        children.add(node); 
     52        return node; 
     53    } 
     54 
     55    @Override 
     56    public String toString() { 
     57        String separator = System.getProperty("line.separator"); 
     58        String result = content + separator; 
     59 
     60        for (StructureNode child : children) { 
     61            result += child.toString(); 
     62        } 
     63 
     64        if (content.startsWith("<Recordable")) { 
     65            return result; 
     66        } 
     67 
     68        return result + "</StructureElement>" + separator; 
     69    } 
     70} 
     71 
    3872/** 
    3973 * <p> 
     
    4882    private int nextRef; 
    4983    private JFCGUIElement currentFocus; 
     84 
     85    private StructureNode structure; 
     86    private StructureNode lastMouseClickEvent; 
     87    private StructureNode lastFocusChangeEvent; 
     88    private StructureNode lastItemActionEvent; 
    5089 
    5190    /* 
     
    118157    } 
    119158 
    120     private ArrayList<String> writeJacaretoEvents(BufferedWriter writer, 
    121                                                   Collection<List<Event>> sequences) 
     159    private void writeJacaretoEvents(BufferedWriter writer, Collection<List<Event>> sequences) 
    122160        throws IOException 
    123161    { 
    124         ArrayList<String> structure = new ArrayList<String>(); 
    125         structure.add("<StructureElement class=\"jacareto.struct.RootElement\">"); 
     162        structure = new StructureNode("<StructureElement class=\"jacareto.struct.RootElement\">"); 
    126163        // reference the elements that we included in the header 
    127164        structure.add("<Recordable ref=\"0\" />"); // Calendar 
     
    137174 
    138175                if (event.getType() instanceof MouseButtonDown) { 
    139                     structure.add("<StructureElement class=\"jacareto.struct.MouseClick\">"); 
    140                     writeMouseClickEvent(writer, structure, event, 501); 
     176                    lastMouseClickEvent = 
     177                        new StructureNode("<StructureElement class=\"jacareto.struct.MouseClick\">"); 
     178                    writeMouseClickEvent(writer, event, 501); 
    141179                } 
    142180                else if (event.getType() instanceof MouseButtonUp) { 
    143                     writeMouseClickEvent(writer, structure, event, 502); 
     181                    writeMouseClickEvent(writer, event, 502); 
    144182                } 
    145183                else if (event.getType() instanceof MouseClick) { 
    146                     writeMouseClickEvent(writer, structure, event, 500); 
    147                     structure.add("</StructureElement>"); 
     184                    writeMouseClickEvent(writer, event, 500); 
    148185                    // FIXME: don't always write an item action 
    149                     writeItemActionEvent(writer, structure, event); 
     186                    writeItemActionEvent(writer, event); 
     187                    // FIXME: don't write it all here because there 
     188                    // might be no item action at all 
     189                    if (lastFocusChangeEvent == null) { 
     190                        // write structure sequentially 
     191                        structure.children.add(lastMouseClickEvent); 
     192                        structure.children.add(lastItemActionEvent); 
     193                    } 
     194                    else { 
     195                        // with nested structure 
     196                        structure.children.add(lastItemActionEvent); 
     197                        lastItemActionEvent.children.add(0, lastFocusChangeEvent); 
     198                        lastFocusChangeEvent.children.add(0, lastMouseClickEvent); 
     199 
     200                        lastFocusChangeEvent = null; 
     201                    } 
    150202                } 
    151                 /* 
    152203                else if (event.getType() instanceof KeyboardFocusChange) { 
    153                     writeFocusChangeEvent(writer, structure, event); 
     204                    writeFocusChangeEvent(writer, event); 
    154205                } 
    155                 */ 
    156206            } 
    157207        } 
    158  
    159         return structure; 
    160     } 
    161  
    162     private void writeJacaretoTail(BufferedWriter writer, ArrayList<String> structure) 
    163         throws IOException 
    164     { 
     208    } 
     209 
     210    private void writeJacaretoTail(BufferedWriter writer) throws IOException { 
    165211        writeLine(writer, "</Record>"); 
    166212 
    167213        // write the recording's structure 
    168214        writeLine(writer, "<Structure>"); 
    169         for (String element : structure) { 
    170             writeLine(writer, element); 
    171         } 
     215        writer.write(structure.toString()); 
    172216        // close root element 
    173         writeLine(writer, "</StructureElement>"); 
    174217        writeLine(writer, "</Structure>"); 
    175218    } 
     
    180223        try { 
    181224            writeJacaretoHead(writer); 
    182             ArrayList<String> structure = writeJacaretoEvents(writer, sequences); 
    183             writeJacaretoTail(writer, structure); 
     225            writeJacaretoEvents(writer, sequences); 
     226            writeJacaretoTail(writer); 
    184227            writeLine(writer, "</JacaretoStructure>"); 
    185228 
     
    230273    } 
    231274 
    232     private void writeItemActionEvent(BufferedWriter writer, 
    233                                       ArrayList<String> structure, 
    234                                       Event event) throws IOException 
    235     { 
     275    private void writeItemActionEvent(BufferedWriter writer, Event event) throws IOException { 
    236276        JFCGUIElement target = (JFCGUIElement) event.getTarget(); 
    237277        MouseButtonInteraction info = (MouseButtonInteraction) event.getType(); 
     
    261301        ); 
    262302        //@formatter:on 
    263         structure.add("<StructureElement class=\"jacareto.struct.ItemStateChange\">"); 
    264         structure.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
    265         structure.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
    266         structure.add("</StructureElement>"); 
    267     } 
    268  
    269     private void writeFocusChangeEvent(BufferedWriter writer, 
    270                                        ArrayList<String> structure, 
    271                                        Event event) throws IOException 
    272     { 
     303        lastItemActionEvent = 
     304            new StructureNode("<StructureElement class=\"jacareto.struct.ItemStateChange\">"); 
     305        lastItemActionEvent.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
     306        lastItemActionEvent.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
     307    } 
     308 
     309    private void writeFocusChangeEvent(BufferedWriter writer, Event event) throws IOException { 
    273310        KeyboardFocusChange info = (KeyboardFocusChange) event.getType(); 
    274311        JFCGUIElement target = (JFCGUIElement) event.getTarget(); 
    275312 
    276313        if (currentFocus != null) { 
     314            lastFocusChangeEvent = 
     315                new StructureNode("<StructureElement class=\"jacareto.struct.FocusChange\">"); 
     316 
    277317            // focus lost on old target 
    278             writeFocusEvent(writer, structure, info, currentFocus, 1005); 
     318            writeFocusEvent(writer, info, currentFocus, 1005); 
    279319            // focus gained on new target 
    280             writeFocusEvent(writer, structure, info, target, 1004); 
     320            writeFocusEvent(writer, info, target, 1004); 
    281321        } 
    282322        else { 
     
    290330 
    291331    private void writeFocusEvent(BufferedWriter writer, 
    292                                  ArrayList<String> structure, 
    293332                                 KeyboardFocusChange info, 
    294333                                 JFCGUIElement target, 
     
    313352        ); 
    314353        //@formatter:on 
    315     } 
    316  
    317     private void writeMouseClickEvent(BufferedWriter writer, 
    318                                       ArrayList<String> structure, 
    319                                       Event event, 
    320                                       int jacId) throws IOException 
     354        lastFocusChangeEvent.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
     355    } 
     356 
     357    private void writeMouseClickEvent(BufferedWriter writer, Event event, int jacId) 
     358        throws IOException 
    321359    { 
    322360        MouseButtonInteraction info = (MouseButtonInteraction) event.getType(); 
     
    356394        //@formatter:on 
    357395 
    358         structure.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
     396        lastMouseClickEvent.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 
    359397    } 
    360398 
Note: See TracChangeset for help on using the changeset viewer.