Changeset 1688
- Timestamp:
- 08/21/14 16:01:12 (10 years ago)
- 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 36 36 import de.ugoe.cs.util.console.GlobalDataContainer; 37 37 38 39 // helper class for the tree like structure part within a Jacareto file 40 class 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 38 72 /** 39 73 * <p> … … 48 82 private int nextRef; 49 83 private JFCGUIElement currentFocus; 84 85 private StructureNode structure; 86 private StructureNode lastMouseClickEvent; 87 private StructureNode lastFocusChangeEvent; 88 private StructureNode lastItemActionEvent; 50 89 51 90 /* … … 118 157 } 119 158 120 private ArrayList<String> writeJacaretoEvents(BufferedWriter writer, 121 Collection<List<Event>> sequences) 159 private void writeJacaretoEvents(BufferedWriter writer, Collection<List<Event>> sequences) 122 160 throws IOException 123 161 { 124 ArrayList<String> structure = new ArrayList<String>(); 125 structure.add("<StructureElement class=\"jacareto.struct.RootElement\">"); 162 structure = new StructureNode("<StructureElement class=\"jacareto.struct.RootElement\">"); 126 163 // reference the elements that we included in the header 127 164 structure.add("<Recordable ref=\"0\" />"); // Calendar … … 137 174 138 175 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); 141 179 } 142 180 else if (event.getType() instanceof MouseButtonUp) { 143 writeMouseClickEvent(writer, structure,event, 502);181 writeMouseClickEvent(writer, event, 502); 144 182 } 145 183 else if (event.getType() instanceof MouseClick) { 146 writeMouseClickEvent(writer, structure, event, 500); 147 structure.add("</StructureElement>"); 184 writeMouseClickEvent(writer, event, 500); 148 185 // 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 } 150 202 } 151 /*152 203 else if (event.getType() instanceof KeyboardFocusChange) { 153 writeFocusChangeEvent(writer, structure,event);204 writeFocusChangeEvent(writer, event); 154 205 } 155 */156 206 } 157 207 } 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 { 165 211 writeLine(writer, "</Record>"); 166 212 167 213 // write the recording's structure 168 214 writeLine(writer, "<Structure>"); 169 for (String element : structure) { 170 writeLine(writer, element); 171 } 215 writer.write(structure.toString()); 172 216 // close root element 173 writeLine(writer, "</StructureElement>");174 217 writeLine(writer, "</Structure>"); 175 218 } … … 180 223 try { 181 224 writeJacaretoHead(writer); 182 ArrayList<String> structure =writeJacaretoEvents(writer, sequences);183 writeJacaretoTail(writer , structure);225 writeJacaretoEvents(writer, sequences); 226 writeJacaretoTail(writer); 184 227 writeLine(writer, "</JacaretoStructure>"); 185 228 … … 230 273 } 231 274 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 { 236 276 JFCGUIElement target = (JFCGUIElement) event.getTarget(); 237 277 MouseButtonInteraction info = (MouseButtonInteraction) event.getType(); … … 261 301 ); 262 302 //@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 { 273 310 KeyboardFocusChange info = (KeyboardFocusChange) event.getType(); 274 311 JFCGUIElement target = (JFCGUIElement) event.getTarget(); 275 312 276 313 if (currentFocus != null) { 314 lastFocusChangeEvent = 315 new StructureNode("<StructureElement class=\"jacareto.struct.FocusChange\">"); 316 277 317 // focus lost on old target 278 writeFocusEvent(writer, structure,info, currentFocus, 1005);318 writeFocusEvent(writer, info, currentFocus, 1005); 279 319 // focus gained on new target 280 writeFocusEvent(writer, structure,info, target, 1004);320 writeFocusEvent(writer, info, target, 1004); 281 321 } 282 322 else { … … 290 330 291 331 private void writeFocusEvent(BufferedWriter writer, 292 ArrayList<String> structure,293 332 KeyboardFocusChange info, 294 333 JFCGUIElement target, … … 313 352 ); 314 353 //@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 321 359 { 322 360 MouseButtonInteraction info = (MouseButtonInteraction) event.getType(); … … 356 394 //@formatter:on 357 395 358 structure.add("<Recordable ref=\"" + (nextRef++) + "\" />");396 lastMouseClickEvent.add("<Recordable ref=\"" + (nextRef++) + "\" />"); 359 397 } 360 398
Note: See TracChangeset
for help on using the changeset viewer.