コード例 #1
0
 /**
  * Builds the set of FocusKey objects for all focusable components on the form. A FocusKey allows
  * us to store a reference to a focusable component and later find that component when a form has
  * been de-serialized. We don't use the component name to reference the component because we don't
  * want to keep track of when the user changes the name.
  */
 public void buildFocusKeys(
     HashSet currentFocusSet,
     HashMap focus_key_map,
     FormComponent form,
     CompositeFocusKey compositeKey) {
   for (int row = 1; row <= form.getRowCount(); row++) {
     for (int col = 1; col <= form.getColumnCount(); col++) {
       GridComponent gc = form.getGridComponent(col, row);
       if (gc instanceof StandardComponent) {
         Component comp = gc.getBeanDelegate();
         if (comp != null) {
           if (currentFocusSet.contains(comp)) {
             CompositeFocusKey ckey = (CompositeFocusKey) compositeKey.clone();
             ckey.add(new FormCellFocusKey(row, col, comp));
             focus_key_map.put(comp, ckey);
           } else {
             /**
              * This comp must be a container that contains components that are in the focus policy
              * This can happen for Java Beans that are also panels which contain other components.
              */
             if (comp instanceof Container) {
               CompositeFocusKey ckey = (CompositeFocusKey) compositeKey.clone();
               ckey.add(new FormCellFocusKey(row, col, comp));
               buildContainerFocusKeys(currentFocusSet, focus_key_map, (Container) comp, ckey);
             } else {
               // ignore because this could be a component like
               // a JLabel which does not need focus
             }
           }
         }
       } else if (gc instanceof FormComponent) {
         FormComponent childform = (FormComponent) gc;
         CompositeFocusKey ckey = (CompositeFocusKey) compositeKey.clone();
         ckey.add(new FormCellFocusKey(row, col, gc));
         buildFocusKeys(currentFocusSet, focus_key_map, childform, ckey);
       } else {
         if (gc != null) {
           System.out.println(
               "FormFocusManager.buildDefaultPolicyFailed  found unknown comp: " + gc.getClass());
         }
       }
     }
   }
 }