Index: trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java
===================================================================
--- trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDgenerateJacaretoReplay.java	(revision 1671)
+++ trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java	(revision 1673)
@@ -13,16 +13,22 @@
 //   limitations under the License.
 
-package de.ugoe.cs.autoquest.commands.sequences;
+package de.ugoe.cs.autoquest.plugin.jfc.commands;
 
 import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.logging.Level;
 
 import de.ugoe.cs.autoquest.CommandHelpers;
 import de.ugoe.cs.autoquest.SequenceInstanceOf;
+import de.ugoe.cs.util.console.Command;
 import de.ugoe.cs.autoquest.eventcore.Event;
+import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElement;
 import de.ugoe.cs.util.console.Console;
 import de.ugoe.cs.util.console.GlobalDataContainer;
@@ -36,5 +42,5 @@
  * @version 1.0
  */
-public class CMDgenerateJacaretoReplay extends CMDgenerateReplayfile {
+public class CMDgenerateJacaretoReplay implements Command {
 
     /*
@@ -56,6 +62,4 @@
     @Override
     public void run(List<Object> parameters) {
-        // TODO: except for the last lines, this function is identical to
-        // superclass CMDgenerateReplayfile, extract a function
         String filename;
         String sequencesName;
@@ -125,7 +129,18 @@
                 Event event = eventIter.next();
 
-                // TODO
-                System.out.println(event.getTarget());
-                System.out.println(event.getType());
+                // TODO: do a mapping file or something to map
+                // from autoquest events to jacareto events
+                if (event.getType().getName().equals("KeyboardFocusChange")) {
+                    /*
+                    writeLine(
+                        "<FocusEvent procTime=\"0\" duration=\"0\" source="JFrame_(1).JRootPane_(1).JLayeredPane_(1).JPanel_(1).JPanel_(1).JCheckBox_(1)" +" +
+                        "       class="javax.swing.JCheckBox" uuid="061bee8f-d8a3-477f-ab8d-bab02f614916" ID="1004" component="null" root="JFrame_(1)" xPos="0" yPos="0" width="0" height="0" isTemporary="false" />");
+                    */
+                    System.out.println(((JFCGUIElement)event.getTarget()).getJacaretoHierarchy());
+                }
+                else {
+                    System.out.println(event.getType());
+                    System.out.println(event.getTarget());
+                }
             }
         }
@@ -145,6 +160,4 @@
         }
         writeLine(writer, "</Structure>");
-
-        writeLine(writer, "<JacaretoStructure>");
     }
 
@@ -156,4 +169,5 @@
             ArrayList<String> structure = writeJacaretoEvents(writer, sequences);
             writeJacaretoTail(writer, structure);
+            writeLine(writer, "<JacaretoStructure>");
 
             writer.flush();
@@ -165,3 +179,40 @@
     }
 
+    /**
+     * <p>
+     * Helper function that opens the replay file for writing.
+     * </p>
+     * 
+     * @param filename
+     *            name and path of the replay file
+     * @param encoding
+     *            file encoding, empty string for platform default
+     * @return {@link OutputStreamWriter} that writes to the replay file
+     */
+    private OutputStreamWriter openReplayFile(String filename) {
+        File file = new File(filename);
+        boolean fileCreated;
+        try {
+            fileCreated = file.createNewFile();
+            if (!fileCreated) {
+                Console.traceln(Level.INFO, "Created logfile " + filename);
+            }
+            else {
+                Console.traceln(Level.INFO, "Overwrote existing logfile " + filename);
+            }
+        }
+        catch (IOException e) {
+            Console.printerrln("Unable to create file " + filename);
+            Console.logException(e);
+        }
+        OutputStreamWriter writer = null;
+        try {
+            writer = new OutputStreamWriter(new FileOutputStream(file));
+        }
+        catch (IOException e) {
+            Console.printerrln("Unable to open file for writing (read-only file):" + filename);
+            Console.logException(e);
+        }
+        return writer;
+    }
 }
