in src/org/pushingpixels/lightbeam/panels/LightBeamMenuBar.java [80:162]
public PerformanceScenario getMenuSelectionScenario() {
return new PerformanceScenario() {
private List<MenuElement[]> menuPaths;
private int[] perms;
@Override
public String getName() {
return "Menu selection";
}
@Override
public void setup() {
this.menuPaths = new ArrayList<MenuElement[]>();
for (int i = 0; i < getComponentCount(); i++) {
Component comp = getComponent(i);
if (comp instanceof JMenu) {
this.scanMenu(null, (JMenu) comp);
}
}
this.perms = LightBeamUtils.getPermutation(menuPaths.size(),
this.getIterationCount());
}
private void scanMenu(LinkedList<JMenu> currentPath,
JMenuItem menuLeaf) {
int count = 1;
if (currentPath != null)
count += 2 * currentPath.size();
if (menuLeaf != null)
count++;
MenuElement[] path = new MenuElement[count];
count = 0;
// the first element is the menu bar itself
path[count++] = LightBeamMenuBar.this;
if (currentPath != null) {
for (JMenu menu : currentPath) {
// JMenu menu = (JMenu) it.next();
path[count++] = menu;
// important - don't forget the popup menu of the menu
path[count++] = menu.getPopupMenu();
}
}
if (menuLeaf != null)
path[count] = menuLeaf;
menuPaths.add(path);
if (menuLeaf instanceof JMenu) {
JMenu menu = (JMenu) menuLeaf;
if (currentPath == null)
currentPath = new LinkedList<JMenu>();
currentPath.addLast(menu);
for (int i = 0; i < menu.getMenuComponentCount(); i++) {
JMenuItem currItem = menu.getItem(i);
scanMenu(currentPath, currItem);
}
currentPath.removeLast();
}
}
@Override
public int getIterationCount() {
return 15;
}
@Override
public void runSingleIteration(int iterationNumber) {
MenuSelectionManager.defaultManager().setSelectedPath(
this.menuPaths.get(this.perms[iterationNumber]));
JRootPane root = SwingUtilities
.getRootPane(LightBeamMenuBar.this);
root.paintImmediately(new Rectangle(0, 0, root.getWidth(), root
.getHeight()));
}
@Override
public void tearDown() {
MenuSelectionManager.defaultManager().clearSelectedPath();
}
};
}