/*................................................................................................*/
  public boolean startJob(String arguments, Object condition, boolean hiredByName) {
    addMenuItem("Directory for Sample Trees From Directory...", makeCommand("setDirPath", this));
    fillerTasks = new Vector();
    if (!MesquiteThread
        .isScripting()) { // enclosed in conditional to avoid hiring query when opening file; should
      // be handled by snapshot/doCommand when file is opened.
      String directoryPath =
          MesquiteFile.chooseDirectory(
              "Choose directory containing tree files:",
              previousDirectory); // MesquiteFile.saveFileAsDialog("Base name for files (files will
      // be named <name>1.nex, <name>2.nex, etc.)", baseName);

      if (StringUtil.blank(directoryPath)) { // TODO: clean this up?
        return false;
      } else {
        directory = new File(directoryPath);
        previousDirectory = directory.getParent();
        if (directory.exists() && directory.isDirectory()) {
          return hireFillers(directoryPath);
        }
      }
    }
    return true; // Add something to make sure directory paths are set up correctly, when not
    // scripting...
  }
 /** condition passed to this module must be subclass of CharacterState */
 public boolean startJob(String arguments, Object condition, boolean hiredByName) {
   hiringCondition = condition;
   String exp, mexp;
   if (getExplanationByWhichHired() != null) {
     exp = getExplanationByWhichHired();
     mexp = exp;
   } else {
     exp = "Source of Characters  (for " + getEmployer().getName() + ")";
     mexp = exp;
   }
   MesquiteModuleInfo mmi =
       MesquiteTrunk.mesquiteModulesInfoVector.findModule(
           mesquite.charMatrices.StoredCharacters.StoredCharacters.class);
   if (mmi != null && !mmi.isCompatible(condition, getProject(), this)) {
     if (!MesquiteDialog.useWizards) {
       exp +=
           "\n\nNOTE: The choice Stored Characters does not appear because there are no appropriate matrices currently defined and stored in the data file or project.  ";
     }
   } else if (CharacterSource.useStoredAsDefault()) {
     characterSourceTask =
         (CharacterObedSource)
             hireNamedEmployee(
                 CharacterObedSource.class,
                 "#mesquite.charMatrices.StoredCharacters.StoredCharacters",
                 condition);
   }
   if (characterSourceTask == null) {
     if (arguments == null) arguments = MesquiteThread.retrieveAndDeleteHint(this);
     if (arguments != null)
       characterSourceTask =
           (CharacterObedSource)
               hireNamedEmployee(CharacterObedSource.class, arguments, condition);
     if (characterSourceTask == null) {
       if (condition != null)
         characterSourceTask =
             (CharacterObedSource)
                 hireCompatibleEmployee(CharacterObedSource.class, condition, exp);
       else
         characterSourceTask = (CharacterObedSource) hireEmployee(CharacterObedSource.class, exp);
     }
   }
   if (characterSourceTask == null)
     return sorry(getName() + " couldn't start because no source of characters was obtained.");
   charSourceName = new MesquiteString(characterSourceTask.getName());
   cstC = makeCommand("setCharacterSource", this);
   characterSourceTask.setHiringCommand(cstC);
   if (numModulesAvailable(CharacterObedSource.class) > 1) {
     mss = addSubmenu(null, mexp, cstC, CharacterObedSource.class);
     mss.setNameHolder(this);
     if (condition != null) mss.setCompatibilityCheck(hiringCondition);
     mss.setSelected(charSourceName);
   }
   return true;
 }
  /*.................................................................................................................*/
  public boolean queryOptions() {
    if (!MesquiteThread.isScripting()) {

      duplicateExcludedCharacters =
          !AlertDialog.query(
              containerOfModule(),
              "Remove excluded characters?",
              "Remove excluded characters?",
              "Yes",
              "No");
    }
    return true;
  }
 /*.................................................................................................................*/
 public boolean startJob(String arguments, Object condition, boolean hiredByName) {
   if (!MesquiteThread.isScripting()) {
     int s =
         MesquiteInteger.queryInteger(
             containerOfModule(),
             "Number of taxa to exclude",
             "Enter the number of randomly chosen taxa to exclude",
             numExcluded);
     if (MesquiteInteger.isCombinable(s)) numExcluded = s;
     else return false;
   }
   addMenuItem("Number of Taxa Excluded...", makeCommand("setNumberExcluded", this));
   return true;
 }
 /**
  * Called to provoke any necessary initialization. This helps prevent the module's intialization
  * queries to the user from happening at inopportune times (e.g., while a long chart calculation
  * is in mid-progress)
  */
 public void initialize(Taxa taxa) {
   setPreferredTaxa(taxa);
   fillerTask.initialize(taxa);
   if (!fillerTask.hasLimitedTrees(taxa)) {
     if (!MesquiteThread.isScripting() && !nTreesSet) {
       int n =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Trees per block?",
               "How many trees to include per tree block?",
               numTrees);
       if (MesquiteInteger.isCombinable(n) && n > 0) numTrees = n;
       nTreesSet = true;
     }
   }
   ntreesItem.setEnabled(!fillerTask.hasLimitedTrees(taxa));
   MesquiteTrunk.resetMenuItemEnabling();
 }
 /**
  * Called to provoke any necessary initialization. This helps prevent the module's intialization
  * queries to the user from happening at inopportune times (e.g., while a long chart calculation
  * is in mid-progress)
  */
 public void initialize(Taxa taxa) {
   setPreferredTaxa(taxa);
   fillerTask.initialize(taxa);
   if (!fillerTask.hasLimitedTrees(taxa)) {
     if (!MesquiteThread.isScripting() && !nTreesSet) {
       int n =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Trees per block?",
               "How many trees to include per tree block?",
               numTrees);
       if (MesquiteInteger.isCombinable(n) && n > 0) numTrees = n;
       nTreesSet = true;
     }
   }
   if (enableNumTreesChoice() && ntreesItem == null)
     ntreesItem = addMenuItem("Number of Trees...", makeCommand("setNumberTrees", this));
   if (ntreesItem != null && fillerTask != null)
     ntreesItem.setEnabled(!fillerTask.hasLimitedTrees(taxa));
   MesquiteTrunk.resetMenuItemEnabling();
 }
  /*.................................................................................................................*/
  public boolean startJob(String arguments, Object condition, boolean hiredByName) {
    if (arguments == null) {
      if (MesquiteThread.isScripting())
        fillerTask = (TreeBlockFiller) hireNamedEmployee(TreeBlockFiller.class, "#StoredTrees");
      if (fillerTask == null)
        fillerTask =
            (TreeBlockFiller)
                hireEmployee(TreeBlockFiller.class, "Source of trees for tree blocks");
    } else {
      fillerTask = (TreeBlockFiller) hireNamedEmployee(TreeBlockFiller.class, arguments);
      if (fillerTask == null)
        fillerTask =
            (TreeBlockFiller)
                hireEmployee(TreeBlockFiller.class, "Source of trees for tree blocks");
    }

    if (fillerTask == null)
      return sorry(getName() + " couldn't start because no source of trees obtained.");
    ntreesItem = addMenuItem("Number of Trees...", makeCommand("setNumberTrees", this));
    return true;
  }
  /*.................................................................................................................*/
  public Tree retrieveTreeBlock(TreeVector treeList, MesquiteDouble finalScore) {
    logln("Preparing to receive TNT trees.");
    boolean success = false;
    taxa = treeList.getTaxa();
    // TODO		finalScore.setValue(finalValue);

    suppressProjectPanelReset();
    CommandRecord oldCR = MesquiteThread.getCurrentCommandRecord();
    CommandRecord scr = new CommandRecord(true);
    MesquiteThread.setCurrentCommandRecord(scr);

    // define file paths and set tree files as needed.
    setFileNames();
    String[] outputFilePaths = externalProcRunner.getOutputFilePaths();

    String treeFilePath = outputFilePaths[OUT_TREEFILE];
    taxonNumberTranslation = getTaxonNumberTranslation(taxa);
    namer.setNumberTranslationTable(taxonNumberTranslation);

    runFilesAvailable();

    // read in the tree files
    success = false;
    Tree t = null;

    MesquiteBoolean readSuccess = new MesquiteBoolean(false);
    // TreeVector tv = new TreeVector(taxa);
    if (bootstrapOrJackknife()) {
      if (resamplingAllConsensusTrees)
        t =
            ZephyrUtil.readTNTTreeFile(
                this,
                treeList,
                taxa,
                treeFilePath,
                "TNT " + getResamplingKindName() + " Rep",
                0,
                readSuccess,
                false,
                false,
                null,
                namer); // set first tree number as 0 as will remove the first one later.
      else
        t =
            ZephyrUtil.readTNTTreeFile(
                this,
                treeList,
                taxa,
                treeFilePath,
                "TNT " + getResamplingKindName() + " Majority Rule Tree",
                1,
                readSuccess,
                false,
                false,
                freqRef,
                namer);
    } else
      t =
          ZephyrUtil.readTNTTreeFile(
              this,
              treeList,
              taxa,
              treeFilePath,
              "TNTTree",
              1,
              readSuccess,
              false,
              harvestOnlyStrictConsensus,
              null,
              namer);
    success = t != null;
    if (success && bootstrapOrJackknife() && resamplingAllConsensusTrees) {
      t = t.cloneTree();
      treeList.removeElementAt(0, false); // get rid of first one as this is the bootstrap tree
    }

    MesquiteThread.setCurrentCommandRecord(oldCR);
    success = readSuccess.getValue();
    if (!success) {
      logln("Execution of TNT unsuccessful [2]");
      if (!beanWritten) postBean("unsuccessful [2]", false);
      beanWritten = true;
    } else {
      if (!beanWritten) postBean("successful", false);
      beanWritten = true;
    }

    desuppressProjectPanelReset();
    if (data != null) data.decrementEditInhibition();
    //	manager.deleteElement(tv);  // get rid of temporary tree block
    externalProcRunner.finalCleanup();
    if (success) return t;
    return null;
  }
  public boolean queryOptions() {
    if (!okToInteractWithUser(
        CAN_PROCEED_ANYWAY,
        "Querying Options")) // Debugg.println needs to check that options set well enough to
                             // proceed anyway
    return true;
    boolean closeWizard = false;

    if ((MesquiteTrunk.isMacOSXBeforeSnowLeopard()) && MesquiteDialog.currentWizard == null) {
      CommandRecord cRec = null;
      cRec = MesquiteThread.getCurrentCommandRecordDefIfNull(null);
      if (cRec != null) {
        cRec.requestEstablishWizard(true);
        closeWizard = true;
      }
    }

    MesquiteInteger buttonPressed = new MesquiteInteger(1);

    queryOptionsDialog =
        new ExtensibleDialog(
            containerOfModule(),
            "TNT Options & Locations",
            buttonPressed); // MesquiteTrunk.mesquiteTrunk.containerOfModule()
    //		queryOptionsDialog.addLabel("TNT - Options and Locations");
    String helpString =
        "This module will prepare a matrix for TNT, and ask TNT do to an analysis.  A command-line version of TNT must be installed. "
            + "You can ask it to do a bootstrap analysis or not. "
            + "Mesquite will read in the trees found by TNT. ";

    queryOptionsDialog.appendToHelpString(helpString);
    queryOptionsDialog.setHelpURL(zephyrRunnerEmployer.getProgramURL());

    MesquiteTabbedPanel tabbedPanel = queryOptionsDialog.addMesquiteTabbedPanel();

    tabbedPanel.addPanel("TNT Program Details", true);
    externalProcRunner.addItemsToDialogPanel(queryOptionsDialog);
    Checkbox parallelCheckBox =
        queryOptionsDialog.addCheckBox("use PVM for parallel processing", parallel);
    parallelCheckBox.addItemListener(this);
    IntegerField slavesField =
        queryOptionsDialog.addIntegerField(
            "Number of Slaves", numSlaves, 4, 0, MesquiteInteger.infinite);
    IntegerField maxRamField =
        queryOptionsDialog.addIntegerField("mxram value", mxram, 4, 0, MesquiteInteger.infinite);

    tabbedPanel.addPanel("Search Options", true);
    Choice searchStyleChoice = null;
    if (bootstrapAllowed)
      searchStyleChoice =
          queryOptionsDialog.addPopUpMenu(
              "Type of search/resampling:",
              new String[] {
                "Regular Search",
                "Bootstrap",
                "Jackknife",
                "Symmetric Resampled",
                "Poisson Bootstrap"
              },
              searchStyle);
    queryOptionsDialog.addLabel("Regular Search Commands");
    searchField = queryOptionsDialog.addTextAreaSmallFont(searchArguments, 7, 80);
    searchScriptPathField =
        queryOptionsDialog.addTextField(
            "Path to TNT run file containing search commands", searchScriptPath, 40);
    Button browseSearchScriptPathButton =
        queryOptionsDialog.addAListenedButton("Browse...", null, this);
    browseSearchScriptPathButton.setActionCommand("browseSearchScript");
    harvestOnlyStrictConsensusBox =
        queryOptionsDialog.addCheckBox("only acquire strict consensus", harvestOnlyStrictConsensus);
    queryOptionsDialog.addHorizontalLine(1);
    //		Checkbox doBootstrapBox = queryOptionsDialog.addCheckBox("do bootstrapping", doBootstrap);
    if (bootstrapAllowed) {
      bootStrapRepsField =
          queryOptionsDialog.addIntegerField(
              "Resampling Replicates", bootstrapreps, 8, 0, MesquiteInteger.infinite);
      queryOptionsDialog.addLabel("Resampling Search Commands");
      bootstrapSearchField =
          queryOptionsDialog.addTextAreaSmallFont(bootstrapSearchArguments, 7, 80);
      bootSearchScriptPathField =
          queryOptionsDialog.addTextField(
              "Path to TNT run file containing search commands for resampled",
              bootSearchScriptPath,
              30);
      Button browseBootSearchScriptPathButton =
          queryOptionsDialog.addAListenedButton("Browse...", null, this);
      browseSearchScriptPathButton.setActionCommand("browseBootSearchScript");
      resamplingAllConsensusTreesBox =
          queryOptionsDialog.addCheckBox(
              "allow TNT to calculate consensus tree", !resamplingAllConsensusTrees);
    }

    adjustDialogText();
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addNewDialogPanel();
    useDefaultsButton = queryOptionsDialog.addAListenedButton("Set to Defaults", null, this);
    useDefaultsButton.setActionCommand("setToDefaults");

    tabbedPanel.addPanel("Other Options", true);
    convertGapsBox =
        queryOptionsDialog.addCheckBox(
            "convert gaps to missing (to avoid gap=extra state)", convertGapsToMissing);
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addLabel("Post-Search TNT Commands");
    otherOptionsField = queryOptionsDialog.addTextAreaSmallFont(otherOptions, 7, 80);
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addNewDialogPanel();
    useDefaultsOtherOptionsButton =
        queryOptionsDialog.addAListenedButton("Set to Defaults", null, this);
    useDefaultsOtherOptionsButton.setActionCommand("setToDefaultsOtherOptions");

    tabbedPanel.cleanup();
    queryOptionsDialog.nullifyAddPanel();

    queryOptionsDialog.completeAndShowDialog("Search", "Cancel", null, null);

    if (buttonPressed.getValue() == 0) {
      boolean infererOK = (treeInferer == null || treeInferer.optionsChosen());
      if (externalProcRunner.optionsChosen() && infererOK) {
        if (bootstrapAllowed) {
          bootstrapreps = bootStrapRepsField.getValue();
          bootstrapSearchArguments = bootstrapSearchField.getText();
          bootSearchScriptPath = bootSearchScriptPathField.getText();
          harvestOnlyStrictConsensus = harvestOnlyStrictConsensusBox.getState();
          resamplingAllConsensusTrees = !resamplingAllConsensusTreesBox.getState();
          searchStyle = searchStyleChoice.getSelectedIndex();
        }
        numSlaves = slavesField.getValue();
        otherOptions = otherOptionsField.getText();
        convertGapsToMissing = convertGapsBox.getState();
        parallel = parallelCheckBox.getState();
        //				doBootstrap = doBootstrapBox.getState();
        searchArguments = searchField.getText();
        searchScriptPath = searchScriptPathField.getText();
        mxram = maxRamField.getValue();

        storeRunnerPreferences();
      }
    }
    queryOptionsDialog.dispose();
    if (closeWizard) MesquiteDialog.closeWizard();

    return (buttonPressed.getValue() == 0);
  }