protected Step createSelection(JComboBox combo, int index) {
   Step step = null;
   if (combo != null && index != -1) {
     ComponentReference cr = getResolver().addComponent(combo);
     String value = tester.getValueAsString(combo, list, combo.getItemAt(index), index);
     if (value == null) {
       step =
           new Action(
               getResolver(),
               null,
               "actionSelectIndex",
               new String[] {cr.getID(), String.valueOf(index)},
               javax.swing.JComboBox.class);
     } else {
       step =
           new Action(
               getResolver(),
               null,
               "actionSelectItem",
               new String[] {cr.getID(), value},
               javax.swing.JComboBox.class);
     }
   }
   return step;
 }
Example #2
0
 /**
  * Set the component reference ID used by method invocation. The class of the component referenced
  * by the component reference will replace the current target class.
  */
 public void setComponentID(String id) {
   if (id == null) {
     componentID = null;
   } else {
     ComponentReference ref = getResolver().getComponentReference(id);
     if (ref != null) {
       componentID = id;
       setTargetClassName(ref.getRefClassName());
     } else throw new NoSuchReferenceException(id);
   }
 }
 protected Step createResize(Window window, Dimension size) {
   Step step = null;
   if (((Dialog) window).isResizable()) {
     ComponentReference ref = getResolver().addComponent(window);
     step =
         new Action(
             getResolver(),
             null,
             "actionResize",
             new String[] {
               ref.getID(), String.valueOf(size.width), String.valueOf(size.height),
             },
             Dialog.class);
   }
   return step;
 }
  /**
   * Create one or more steps corresponding to what was done to the file dialog. If the directory is
   * non-null, the directory was changed. If the file is non-null, the file was accepted.
   */
  protected Step createFileDialogEvents(FileDialog d, String oldDir, String oldFile) {
    ComponentReference ref = getResolver().addComponent(d);
    String file = d.getFile();
    boolean accepted = file != null;
    boolean fileChanged = accepted && !file.equals(oldFile);
    String dir = d.getDirectory();
    boolean dirChanged = dir != oldDir && (dir == null || !dir.equals(oldDir));

    String desc = d.getMode() == FileDialog.SAVE ? "Save File" : "Load File";
    if (accepted) desc += " (" + file + ")";
    else desc += " (canceled)";
    Sequence seq = new Sequence(getResolver(), desc);
    if (dirChanged) {
      seq.addStep(
          new Action(
              getResolver(),
              null,
              "actionSetDirectory",
              new String[] {ref.getID(), dir},
              FileDialog.class));
    }
    if (accepted) {
      Step accept =
          new Action(
              getResolver(), null, "actionAccept", new String[] {ref.getID()}, FileDialog.class);
      if (fileChanged) {
        seq.addStep(
            new Action(
                getResolver(),
                null,
                "actionSetFile",
                new String[] {ref.getID(), file},
                FileDialog.class));
        seq.addStep(accept);
      } else {
        return accept;
      }
    } else {
      Step cancel =
          new Action(
              getResolver(), null, "actionCancel", new String[] {ref.getID()}, FileDialog.class);
      if (dirChanged) seq.addStep(cancel);
      else return cancel;
    }
    return seq;
  }
Example #5
0
 /**
  * Obtain the class of the given reference's component, or return java.awt.Component if not found.
  */
 private static String getRefClass(Resolver r, String id) {
   ComponentReference ref = r.getComponentReference(id);
   return ref == null ? Component.class.getName() : ref.getRefClassName();
 }