コード例 #1
0
 /*.................................................................................................................*/
 public String getTitle() {
   if (observedStates == null) doCalcs();
   if (observedStates != null && getProject().getNumberCharMatricesVisible() > 1) {
     CharacterData d = observedStates.getParentData();
     if (d != null && d.getName() != null) {
       String n = d.getName();
       if (n.length() > 12) n = n.substring(0, 12);
       return "Has Data (" + n + ")";
     }
   }
   return "Has Data in Matrix";
 }
コード例 #2
0
 void captureCharacterDataFromObservedStates() {
   if (observedStates == null) {
     if (data != null) data.removeListener(this);
     data = null;
   } else {
     CharacterData temp = observedStates.getParentData();
     if (temp != data) {
       if (data != null) data.removeListener(this);
       if (temp != null) temp.addListenerHighPriority(this);
       data = temp;
     }
   }
 }
コード例 #3
0
  public boolean alterBlockOfCharacters(CharacterData data, int icStart, int icEnd) {
    if (data == null) return false;
    if (data instanceof MolecularData) {
      MolecularData mData = (MolecularData) data;
      mData.reverse(icStart, icEnd, true);
    } else {
      for (int it = 0; it < data.getNumTaxa(); it++)
        for (int i = 0; i <= (icEnd - icStart) / 2 && icStart + i < icEnd - i; i++) {
          data.tradeStatesBetweenCharacters(icStart + i, icEnd - i, it, true);
        }
    }

    return true;
  }
コード例 #4
0
  /**
   * Gets background color for cell for row ic. Override it if you want to change the color from the
   * default.
   */
  public Color getBackgroundColorOfCell(int it, boolean selected) {
    if (observedStates == null) {
      doCalcs();
      if (observedStates == null) return null;
    }
    if (observedStates.getParentData() != null) {
      captureCharacterDataFromObservedStates();

      Associable tInfo = data.getTaxaInfo(false);
      NameReference genBankColor = NameReference.getNameReference("genbankcolor");
      Object obj = tInfo.getAssociatedObject(genBankColor, it); // not saved to file
      if (obj instanceof Color) return (Color) obj;
    }
    if (bits == null || it < 0 || it > bits.getSize()) return null;
    String note = getNote(it);
    if (selected) {
      if (bits.isBitOn(it)) return ColorDistribution.darkGreen;
      else return ColorDistribution.darkRed;
    } else if (bits.isBitOn(it)) {
      if (StringUtil.blank(note)) return ColorDistribution.veryLightGreen;
      if (!(note.equalsIgnoreCase("x"))) return ColorDistribution.lightGreenYellowish;
      return ColorDistribution.lightGreenYellow;
    } else {
      if (StringUtil.blank(note)) return ColorDistribution.brown;
      if (!(note.equalsIgnoreCase("x"))) {
        return Color.red;
      }
      return ColorDistribution.lightRed;
    }
  }
コード例 #5
0
  /*.................................................................................................................*/
  void zapData(CharacterData data, int it) {
    Taxa taxa = data.getTaxa();
    if (it < 0 || it >= taxa.getNumTaxa()) return;
    Associable tInfo = data.getTaxaInfo(false);
    int myColumn = -1;
    if (getEmployer() instanceof ListModule) {

      myColumn = ((ListModule) getEmployer()).getMyColumn(this);
    }
    if (tInfo != null) tInfo.deassignAssociated(it);
    for (int ic = 0; ic < data.getNumChars(); ic++) data.deassign(ic, it);

    data.notifyListeners(this, new Notification(MesquiteListener.DATA_CHANGED));
    outputInvalid();
    parametersChanged();
  }
コード例 #6
0
  /*.................................................................................................................*/
  public boolean arrowTouchInRow(
      Graphics g, int ic, int x, int y, boolean doubleClick, int modifiers) {
    if (MesquiteEvent.rightClick(modifiers)) {
      MesquitePopup popup = new MesquitePopup(table.getMatrixPanel());

      String copyMenuText = "Copy ";
      if (observedStates != null) {
        CharacterData data = observedStates.getParentData();
        if (data != null) {
          copyMenuText += data.getName() + " Data";
          copyMenuText += " [from " + data.getTaxa().getTaxonName(ic) + "]";
        }
      }
      MesquiteCommand mcCopy = makeCommand("copyData", this);
      mcCopy.setDefaultArguments("" + ic);
      MesquiteCheckMenuItem mCopyItem =
          new MesquiteCheckMenuItem(copyMenuText, this, mcCopy, null, null);
      popup.add(mCopyItem);

      String pasteMenuText = "Paste ";
      if (StringUtil.notEmpty(localCopyDataClipboard) && localCopyData != null) {
        pasteMenuText += localCopyData.getName() + " Data";
        if (StringUtil.notEmpty(localCopyDataTaxon)) {
          pasteMenuText += " [from " + localCopyDataTaxon + "] ";
        }
      }
      MesquiteCommand mcPaste = makeCommand("pasteData", this); // only if something in clipboard
      mcPaste.setDefaultArguments("" + ic);
      MesquiteCheckMenuItem mPasteItem =
          new MesquiteCheckMenuItem(pasteMenuText, this, mcPaste, null, null);
      mPasteItem.setEnabled(StringUtil.notEmpty(localCopyDataClipboard));
      popup.add(mPasteItem);

      MesquiteCommand mcDelete = makeCommand("deleteDataTouched", this);
      mcDelete.setDefaultArguments("" + ic);
      MesquiteCheckMenuItem mDeleteItem =
          new MesquiteCheckMenuItem("Delete Data", this, mcDelete, null, null);
      popup.add(mDeleteItem);

      popup.showPopup(x, y + 18);

      return true;
    }
    return false;
  }
コード例 #7
0
  public String getExplanationForRow(int ic) {
    if (observedStates != null && observedStates.getParentData() != null) {
      captureCharacterDataFromObservedStates();

      Associable tInfo = data.getTaxaInfo(false);
      if (tInfo == null) return null;
      return "Notes: " + tInfo.toString(ic);
    }
    return null;
  }
コード例 #8
0
  public boolean alterBlockInTaxon(CharacterData data, int icStart, int icEnd, int it) {
    if (data == null) return false;

    if (data instanceof MolecularData) {
      MolecularData mData = (MolecularData) data;
      mData.reverse(icStart, icEnd, it, false, true);
    } else
      for (int i = 0; i <= (icEnd - icStart) / 2 && icStart + i < icEnd - i; i++) {
        data.tradeStatesBetweenCharacters(icStart + i, icEnd - i, it, true);
      }

    return true;
  }
コード例 #9
0
  public void doCalcs() {
    if (bits != null) bits.clearAllBits();
    if (taxa == null) return;
    if (bits == null) bits = new Bits(taxa.getNumTaxa());
    else bits.resetSize(taxa.getNumTaxa());
    if (observedStates == null) {
      tInfo = null;
      observedStates = matrixSourceTask.getCurrentMatrix(taxa);
      if (observedStates != null) {
        captureCharacterDataFromObservedStates();

        if (data != null) tInfo = data.getTaxaInfo(true);
      }
    }
    if (observedStates == null) return;
    for (int it = 0; it < taxa.getNumTaxa(); it++) {
      if (hasData(it)) bits.setBit(it);
    }
  }
コード例 #10
0
  /*.................................................................................................................*/
  public Object doCommand(String commandName, String arguments, CommandChecker checker) {
    if (checker.compare(
        this.getClass(), "Returns the matrix source", null, commandName, "getMatrixSource")) {
      return matrixSourceTask;
    } else if (checker.compare(
        this.getClass(), "Copies the data for selected taxon", null, commandName, "copyData")) {
      if (observedStates == null) return null;
      CharacterData data = observedStates.getParentData();
      if (data == null) return null;
      int it = MesquiteInteger.fromString(parser.getFirstToken(arguments));
      if (MesquiteInteger.isCombinable(it)) {
        StringBuffer sb = new StringBuffer();
        data.copyDataFromRowIntoBuffer(it, sb);
        if (StringUtil.notEmpty(sb.toString())) {
          localCopyDataClipboard = sb.toString();
          localCopyData = data;
          localCopyDataTaxon = data.getTaxa().getTaxonName(it);
        } else {
          localCopyDataClipboard = null;
          localCopyData = null;
          localCopyDataTaxon = null;
        }
      }
      return null;
    } else if (checker.compare(
        this.getClass(), "Pastes the data for selected taxon", null, commandName, "pasteData")) {
      if (observedStates == null) return null;
      CharacterData data = observedStates.getParentData();
      if (data == null) return null;
      int it = MesquiteInteger.fromString(parser.getFirstToken(arguments));
      if (MesquiteInteger.isCombinable(it) && StringUtil.notEmpty(localCopyDataClipboard)) {
        data.pasteDataFromStringIntoTaxon(it, localCopyDataClipboard);
      }
      return null;
    } else if (checker.compare(
        this.getClass(),
        "Pastes the data for selected taxon",
        null,
        commandName,
        "deleteDataTouched")) {
      if (observedStates == null) return null;
      CharacterData data = observedStates.getParentData();
      if (data == null) return null;
      int it = MesquiteInteger.fromString(parser.getFirstToken(arguments));
      Debugg.println("prepare to delete row: " + it);
      if (MesquiteInteger.isCombinable(it)) {
        if (!AlertDialog.query(
            containerOfModule(),
            "Delete Data?",
            "Are you sure you want to delete the data for taxon "
                + data.getTaxa().getTaxonName(it)
                + " in the matrix \""
                + data.getName()
                + "\"",
            "No",
            "Yes")) {
          zapData(data, it);
        }
      }
      return null;
    } else if (checker.compare(
        this.getClass(), "Deletes the data for selected taxa", null, commandName, "deleteData")) {
      if (observedStates == null) return null;
      captureCharacterDataFromObservedStates();
      if (data == null) return null;
      if (!AlertDialog.query(
          containerOfModule(),
          "Delete Data?",
          "Are you sure you want to delete the data for these taxa in the matrix \""
              + data.getName()
              + "\"",
          "No",
          "Yes")) zapData(data);
      return null;
    } else if (checker.compare(
        this.getClass(),
        "deleteds () and anything between",
        null,
        commandName,
        "deletePrepended")) {
      if (observedStates == null || taxa == null) return null;
      boolean anySelected = taxa.anySelected();
      int myColumn = -1;
      if (getEmployer() instanceof ListModule) {

        myColumn = ((ListModule) getEmployer()).getMyColumn(this);
        if (table != null)
          anySelected = anySelected || table.anyCellSelectedInColumnAnyWay(myColumn);
      }

      for (int it = 0; it < taxa.getNumTaxa(); it++) {
        if ((!anySelected || selected(taxa, it, myColumn))) {
          String note = getNote(it);
          while (!StringUtil.blank(note) && note.indexOf("(") >= 0) {
            int start = note.indexOf("(");
            int end = note.indexOf(")");
            String firstBit = "";
            if (start > 0) firstBit = note.substring(0, start);
            note = firstBit + note.substring(end + 1, note.length());
          }
          setNote(it, note);
        }
      }
      outputInvalid();
      parametersChanged();
      return null;
    } else if (checker.compare(this.getClass(), "deletes *", null, commandName, "deleteStar")) {
      if (observedStates == null || taxa == null) return null;
      boolean anySelected = taxa.anySelected();
      int myColumn = -1;
      if (getEmployer() instanceof ListModule) {

        myColumn = ((ListModule) getEmployer()).getMyColumn(this);
        if (table != null)
          anySelected = anySelected || table.anyCellSelectedInColumnAnyWay(myColumn);
      }
      for (int it = 0; it < taxa.getNumTaxa(); it++) {
        if ((!anySelected || selected(taxa, it, myColumn))) {
          String note = getNote(it);
          while (!StringUtil.blank(note) && note.indexOf("*") >= 0) {
            int start = note.indexOf("*");
            String firstBit = "";
            if (start > 0) firstBit = note.substring(0, start);
            note = firstBit + note.substring(start + 1, note.length());
          }
          setNote(it, note);
        }
      }
      outputInvalid();
      parametersChanged();
      return null;
    } else if (checker.compare(
        this.getClass(),
        "Prepends to the note the sequence length (including N\'s and ?\'s) for the selected taxa",
        null,
        commandName,
        "prependLength")) {
      if (observedStates == null || taxa == null) return null;
      boolean anySelected = taxa.anySelected();
      int myColumn = -1;
      if (getEmployer() instanceof ListModule) {

        myColumn = ((ListModule) getEmployer()).getMyColumn(this);
        if (table != null)
          anySelected = anySelected || table.anyCellSelectedInColumnAnyWay(myColumn);
      }
      for (int it = 0; it < taxa.getNumTaxa(); it++) {
        if (hasData(it) && (!anySelected || selected(taxa, it, myColumn))) {
          String note = getNote(it);
          if (StringUtil.blank(note)) note = "(" + sequenceLength(it) + ")";
          else note = "(" + sequenceLength(it) + ") " + note;
          setNote(it, note);
        }
      }
      outputInvalid();
      parametersChanged();
      return null;
    } else if (checker.compare(
        this.getClass(),
        "Prepends to the note the number of non-missing sites (not including N\'s and ?\'s) for the selected taxa",
        null,
        commandName,
        "prependNumSites")) {
      if (observedStates == null || taxa == null) return null;
      boolean anySelected = taxa.anySelected();
      int myColumn = -1;
      if (getEmployer() instanceof ListModule) {

        myColumn = ((ListModule) getEmployer()).getMyColumn(this);
        if (table != null)
          anySelected = anySelected || table.anyCellSelectedInColumnAnyWay(myColumn);
      }
      for (int it = 0; it < taxa.getNumTaxa(); it++) {
        if (hasData(it) && (!anySelected || selected(taxa, it, myColumn))) {
          String note = getNote(it);
          if (StringUtil.blank(note)) note = "(" + numSites(it) + ")";
          else note = "(" + numSites(it) + ") " + note;
          setNote(it, note);
        }
      }
      outputInvalid();
      parametersChanged();
      return null;
    } else if (checker.compare(
        this.getClass(),
        "Deletes the notes for the selected taxa",
        null,
        commandName,
        "deleteAnnotation")) {
      if (observedStates == null || taxa == null) return null;
      boolean anySelected = taxa.anySelected();
      int myColumn = -1;
      if (getEmployer() instanceof ListModule) {

        myColumn = ((ListModule) getEmployer()).getMyColumn(this);
        if (table != null)
          anySelected = anySelected || table.anyCellSelectedInColumnAnyWay(myColumn);
      }
      for (int it = 0; it < taxa.getNumTaxa(); it++) {
        if (hasData(it) && (!anySelected || selected(taxa, it, myColumn))) {
          setNote(it, null);
        }
      }
      outputInvalid();
      parametersChanged();
      return null;
    } else return super.doCommand(commandName, arguments, checker);
  }
コード例 #11
0
 /** endJob is called as a module is quitting; modules should put their clean up code here. */
 public void endJob() {
   if (data != null) data.removeListener(this);
 }
コード例 #12
0
 public Associable getTaxaInfo(CharacterData data, boolean makeIfNotPresent) {
   if (makeIfNotPresent && taxaInfo == null) {
     taxaInfo = new TaxaInfo(data.getNumTaxa(), data);
   }
   return taxaInfo;
 }
コード例 #13
0
  /** Called to operate on the CharacterData blocks. Returns true if taxa altered */
  public boolean operateOnDatas(ListableVector datas, MesquiteTable table) {
    boolean anyExcluded = false;
    for (int im = 0; im < datas.size(); im++) {
      CharacterData data = (CharacterData) datas.elementAt(im);
      if (data.numCharsCurrentlyIncluded() < data.getNumChars()) anyExcluded = true;
    }
    if (anyExcluded) queryOptions();
    if (getProject() != null) getProject().incrementProjectWindowSuppression();
    for (int im = 0; im < datas.size(); im++) {
      CharacterData data = (CharacterData) datas.elementAt(im);
      CharacterData starter = data.makeCharacterData(data.getMatrixManager(), data.getTaxa());

      starter.addToFile(
          getProject().getHomeFile(), getProject(), findElementManager(CharacterData.class));

      boolean success =
          starter.concatenate(data, false, duplicateExcludedCharacters, false, false, false, false);
      if (success) {
        starter.setName(datas.getUniqueName(data.getName() + " (duplicate)"));
      }
    }
    if (getProject() != null) getProject().decrementProjectWindowSuppression();
    resetAllMenuBars();
    return true;
  }