Ejemplo n.º 1
0
  /**
   * 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;
  }
Ejemplo n.º 2
0
 /** Override the default window parsing to consume everything between dialog open and close. */
 protected boolean parseWindowEvent(AWTEvent event) {
   boolean consumed = true;
   if (event.getSource() instanceof FileDialog) {
     if (isOpen(event)) {
       dialog = (FileDialog) event.getSource();
       originalFile = dialog.getFile();
       originalDir = dialog.getDirectory();
     }
     // The FileDialog robot uses some event listener hacks to set the
     // correct state on dialog close; make sure we record after that
     // listener is finished.
     if (event instanceof FileDialogTerminator) setFinished(true);
     else if (event.getSource() == dialog && isClose(event)) {
       AWTEvent terminator = new FileDialogTerminator(dialog, event.getID());
       dialog.getToolkit().getSystemEventQueue().postEvent(terminator);
     }
   }
   return consumed;
 }