Example #1
0
  /**
   * A request for the MesquiteModule to perform a command. It is passed two strings, the name of
   * the command and the arguments. This should be overridden by any module that wants to respond to
   * a command.
   */
  public Object doCommand(String commandName, String arguments, CommandChecker checker) {
    if (checker.compare(MesquiteModule.class, null, null, commandName, "paint")) {
      MesquiteInteger io = new MesquiteInteger(0);
      int column = MesquiteInteger.fromString(arguments, io);
      int row = MesquiteInteger.fromString(arguments, io);
      if (MesquiteInteger.isCombinable(row)) {
        if (!MesquiteLong.isCombinable(currentColor)) removeColor(row, true);
        else setColor(row, (int) currentColor);
      }
    } else if (checker.compare(
        this.getClass(),
        "Sets the color to be used to paint cells",
        "[name of color]",
        commandName,
        "setColor")) {
      int bc = ColorDistribution.standardColorNames.indexOf(parser.getFirstToken(arguments));
      if (bc >= 0 && MesquiteLong.isCombinable(bc)) {
        removeColor.setValue(false);
        currentColor = bc;
        savedColor = bc;
        colorString = "Color " + ColorDistribution.standardColorNames.getValue(bc);
      }
    } else if (checker.compare(
        this.getClass(),
        "Sets the color of selected taxa",
        "[name of color]",
        commandName,
        "setColorSelected")) {
      int bc = ColorDistribution.standardColorNames.indexOf(parser.getFirstToken(arguments));
      if (bc >= 0 && MesquiteLong.isCombinable(bc)) {
        for (int it = 0; it < taxa.getNumTaxa(); it++) if (taxa.getSelected(it)) setColor(it, bc);
      }
    } else if (checker.compare(
        this.getClass(), "Removes color from all the cells", null, commandName, "removeAllColor")) {
      removeAllColor(true);
    } else if (checker.compare(
        this.getClass(),
        "Sets the paint brush so that it removes colors from any cells touched",
        null,
        commandName,
        "removeColor")) {
      if (StringUtil.blank(arguments)) removeColor.setValue(!removeColor.getValue());
      else removeColor.toggleValue(parser.getFirstToken(arguments));

      if (removeColor.getValue()) {
        colorString = "Remove color";
        currentColor = MesquiteLong.unassigned;
      } else {
        colorString = "Color " + ColorDistribution.standardColorNames.getValue((int) currentColor);
        currentColor = savedColor;
      }
    } else return super.doCommand(commandName, arguments, checker);
    return null;
  }
Example #2
0
 /*.................................................................................................................*/
 public int[] getTaxonNumberTranslation(Taxa taxa) {
   int max = -1;
   for (int it = 0; it < taxa.getNumTaxa(); it++) {
     long translateNumber = getTaxonNumberInTree(taxa, it);
     if (MesquiteLong.isCombinable(translateNumber) && translateNumber > max) {
       max = (int) translateNumber;
     }
   }
   int[] translate = new int[max + 1];
   for (int it = 0; it < data.getNumTaxa(); it++) {
     long translateNumber = getTaxonNumberInTree(taxa, it);
     if (MesquiteLong.isCombinable(translateNumber) && translateNumber >= 0) {
       translate[(int) translateNumber] = it;
     }
   }
   return translate;
 }
 /*.................................................................................................................*/
 public void processOutputFiles(String jobURL) {
   if (rootDir != null) {
     downloadWorkingResults(jobURL, rootDir, true);
     if (outputFileProcessor != null && outputFilePaths != null && lastModified != null) {
       String[] paths = outputFileProcessor.modifyOutputPaths(outputFilePaths);
       for (int i = 0; i < paths.length && i < lastModified.length; i++) {
         File file = new File(paths[i]);
         long lastMod = file.lastModified();
         if (!MesquiteLong.isCombinable(lastModified[i]) || lastMod > lastModified[i]) {
           outputFileProcessor.processOutputFile(paths, i);
           lastModified[i] = lastMod;
         }
       }
     }
   }
 }
  /**
   * This processes information about the files contained in either the results or working directory
   * of a job.
   */
  public CipresJobFile[] processFilesDocument(Document cipresResponseDoc) {
    Element jobfiles = cipresResponseDoc.getRootElement().element("jobfiles");
    if (jobfiles == null) return null;
    List tools = jobfiles.elements("jobfile");
    int count = 0;
    for (Iterator iter = tools.iterator(); iter.hasNext(); ) {
      Element nextTool = (Element) iter.next();
      count++;
    }
    if (count == 0) return null;
    CipresJobFile[] cipresJobFile = new CipresJobFile[count];
    count = 0;
    for (Iterator iter = tools.iterator(); iter.hasNext(); ) {
      Element nextJob = (Element) iter.next();
      if (nextJob != null) {
        if (cipresJobFile[count] == null) cipresJobFile[count] = new CipresJobFile();
        Element jobFileElement = nextJob.element("downloadUri");
        String fileInfo = null;
        if (jobFileElement != null) {
          fileInfo = jobFileElement.elementText("url");
          if (!StringUtil.blank(fileInfo) && count < cipresJobFile.length) {
            cipresJobFile[count].setDownloadURL(fileInfo);
          }
          fileInfo = jobFileElement.elementText("title");
          if (!StringUtil.blank(fileInfo) && count < cipresJobFile.length) {
            cipresJobFile[count].setDownloadTitle(fileInfo);
          }
        }
        fileInfo = nextJob.elementText("dateModified");
        if (!StringUtil.blank(fileInfo) && count < cipresJobFile.length) {
          cipresJobFile[count].setLastModified(fileInfo);
        }
        fileInfo = nextJob.elementText("filename");
        if (!StringUtil.blank(fileInfo) && count < cipresJobFile.length) {
          cipresJobFile[count].setFileName(fileInfo);
        }
        fileInfo = nextJob.elementText("length");
        if (!StringUtil.blank(fileInfo) && count < cipresJobFile.length) {
          cipresJobFile[count].setLength(MesquiteLong.fromString(fileInfo));
        }

        count++;
      }
    }
    return cipresJobFile;
  }