Index: /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java
===================================================================
--- /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java	(revision 1833)
+++ /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java	(revision 1834)
@@ -302,4 +302,6 @@
                     // if a menu file was provided, use the improved event
                     // generation
+                    // TODO: check how much of this is still necessary with
+                    // the new menu index system
                     if (menuList != null) {
                         if (event.getTarget() instanceof JFCMenuButton) {
@@ -423,5 +425,5 @@
             if (indent < oldIndent) {
                 // this is a parent submenu
-                elements.add(menuElements.get(stripped));
+                elements.push(menuElements.get(stripped));
                 oldIndent = indent;
             }
Index: /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDparseJFCwithJacaretoIndices.java
===================================================================
--- /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDparseJFCwithJacaretoIndices.java	(revision 1833)
+++ /trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDparseJFCwithJacaretoIndices.java	(revision 1834)
@@ -15,4 +15,7 @@
 package de.ugoe.cs.autoquest.plugin.jfc.commands;
 
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.HashMap;
@@ -24,5 +27,8 @@
 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
 import de.ugoe.cs.autoquest.plugin.jfc.JFCSimplifiedLogParser;
+import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElement;
 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElementSpec;
+import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenu;
+import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenuButton;
 import de.ugoe.cs.util.console.Command;
 import de.ugoe.cs.util.console.Console;
@@ -40,4 +46,6 @@
 public class CMDparseJFCwithJacaretoIndices implements Command {
 
+    private List<String> menuList;
+
     @Override
     public void run(List<Object> parameters) {
@@ -47,5 +55,7 @@
             filename = (String) parameters.get(0);
             if (parameters.size() >= 2) {
-                sequencesName = (String) parameters.get(1);
+                menuList =
+                    Files.readAllLines(Paths.get((String) parameters.get(1)),
+                                       Charset.defaultCharset());
             }
         }
@@ -80,5 +90,88 @@
     @Override
     public String help() {
-        return "parseJFCwithJacaretoIndices <filename> {<sequences>}";
+        return "parseJFCwithJacaretoIndices <filename> {<menufile>}";
+    }
+
+    private int findPopupMenuIndex(IGUIElement item, GUIModel model) {
+        // TODO: refactor
+        int index = -1;
+        List<IGUIElement> children = model.getChildren(item);
+        IGUIElement menuChild = null;
+
+        // try to identify this popup menu by looking at its children
+        // find the first menu item child of this item
+        for (IGUIElement child : children) {
+            if (child instanceof JFCMenuButton || child instanceof JFCMenu) {
+                menuChild = child;
+                break;
+            }
+        }
+
+        if (menuChild == null) {
+            // this popup menu cannot be identified
+            // TODO: exception, logging etc
+            return -1;
+        }
+
+        // find line that contains this menu item name
+        String itemName = ((JFCGUIElement) menuChild).getName().trim().toLowerCase();
+        int lineOfItem = -1;
+
+        for (int i = 0; i < menuList.size(); i++) {
+            String name = "\"" + menuList.get(i).trim().toLowerCase() + "\"";
+            if (name.equals(itemName)) {
+                lineOfItem = i;
+                break;
+            }
+        }
+
+        if (lineOfItem == -1) {
+            // failed to find this item in the menu file
+            // TODO: exception, logging etc
+            return -1;
+        }
+
+        // find menu item's parent line
+        String stripped = menuList.get(lineOfItem).replaceFirst("^ *", "");
+        int indent = menuList.get(lineOfItem).length() - stripped.length();
+
+        if (indent != 0) {
+            for (int i = lineOfItem; i >= 0; i--) {
+                stripped = menuList.get(i).replaceFirst("^ *", "");
+                int oldIndent = menuList.get(i).length() - stripped.length();
+
+                if (oldIndent < indent) {
+                    lineOfItem = i;
+                    break;
+                }
+            }
+        }
+
+        // get the item's indentation
+        stripped = menuList.get(lineOfItem).replaceFirst("^ *", "");
+        indent = menuList.get(lineOfItem).length() - stripped.length();
+
+        if (indent == 0) {
+            // top level menu item, just count in which position it is
+            for (int i = 0; i <= lineOfItem; i++) {
+                if (!menuList.get(i).startsWith(" ")) {
+                    index++;
+                }
+            }
+        }
+        else {
+            // find the topmenu index in the menu file by going backwards
+            for (int i = lineOfItem; i >= 0; i--) {
+                stripped = menuList.get(i).replaceFirst("^ *", "");
+                int oldIndent = menuList.get(i).length() - stripped.length();
+
+                if (oldIndent < indent) {
+                    index = lineOfItem - i;
+                    break;
+                }
+            }
+        }
+
+        return index;
     }
 
@@ -98,5 +191,18 @@
             }
 
-            ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count);
+            if (menuList != null && type.equals("javax.swing.JPopupMenu")) {
+                // try to use a workaround for popup menu index problems
+                int index = findPopupMenuIndex((IGUIElement) child, targets);
+                if (index != -1) {
+                    ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(index);
+                }
+                else {
+                    // workaround failed, use normal method as fallback
+                    ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count);
+                }
+            }
+            else {
+                ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count);
+            }
 
             generateJacaretoIndices(targets.getChildren(child), targets);
