/**
  * Builds an list of components that are ordered in the focus order previously set by a user for a
  * given form. The form may have changed (components might have been deleted or moved), so we need
  * to delete those components from the focus order that don't match the current state of the form.
  */
 ArrayList buildStoredFocusList(FormComponent form) {
   ArrayList focus_list = new ArrayList();
   FocusPolicyMemento memento = form.getFocusPolicy();
   if (memento != null) {
     Collection fkeys = memento.getFocusPolicyKeys();
     Iterator iter = fkeys.iterator();
     while (iter.hasNext()) {
       FocusKey fkey = (FocusKey) iter.next();
       Component comp = fkey.getComponent(form);
       if (comp != null) {
         focus_list.add(comp);
       }
     }
   }
   return focus_list;
 }
 /** Checks that all focuskeys reference the correct components */
 public void validateFocusKeys(FormComponent root, FocusPolicyMemento memento) {
   Iterator iter = memento.getFocusPolicyKeys().iterator();
   while (iter.hasNext()) {
     FocusKey fkey = (FocusKey) iter.next();
     Component comp = fkey.getComponent(root);
     assert (comp != null);
     System.out.print("Focuskey validated: ");
     fkey.print();
     System.out.println("   comp: " + comp.getClass());
   }
 }
  /**
   * @return the focus policy memento that represents the current focus ordering for this manager
   */
  public FocusPolicyMemento getFocusPolicyMemento() {
    HashSet current_focus_set = new HashSet();
    current_focus_set.addAll(m_focus_list);

    HashMap focus_key_map = new HashMap();
    CompositeFocusKey cfk = new CompositeFocusKey();
    /** first build location keys for all components in the the form */
    buildFocusKeys(current_focus_set, focus_key_map, m_form, cfk);

    FocusPolicyMemento memento = new FocusPolicyMemento();

    /** now iterate over the focus list and get the corresponding focus key */
    Iterator iter = m_focus_list.iterator();
    while (iter.hasNext()) {
      Component comp = (Component) iter.next();
      FocusKey fkey = (FocusKey) focus_key_map.get(comp);
      if (fkey != null) memento.addFocusKey(fkey);
    }

    return memento;
  }