예제 #1
0
  public MiniScroll(
      MesquiteCommand command,
      boolean stacked,
      boolean horizontal,
      long currentValue,
      long minValue,
      long maxValue,
      String itemName) {
    this.currentValue = currentValue;
    this.itemName = itemName;
    this.minValue = minValue;
    this.maxValue = maxValue;
    this.stacked = stacked;
    this.horizontal = horizontal;
    this.command = command;
    if (!horizontal && !stacked) {
      totalWidth = textBoxWidth + 10;
      totalHeight = textBoxHeight + 40 + EnterButton.MIN_DIMENSION + 2;
    } else if (stacked) {
      totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2;
      totalHeight = textBoxHeight + 28;
    } else {
      totalWidth = textBoxWidth + 40 + EnterButton.MIN_DIMENSION + 2;
      totalHeight = textBoxHeight + 2;
    }
    setSize(totalWidth, totalHeight);
    setLayout(null);
    if (this.horizontal) {
      add(decrementButton = new MiniScrollButton(this, MiniScrollButton.LEFT, itemName));
      add(incrementButton = new MiniScrollButton(this, MiniScrollButton.RIGHT, itemName));
    } else {
      add(decrementButton = new MiniScrollButton(this, MiniScrollButton.DOWN, itemName));
      add(incrementButton = new MiniScrollButton(this, MiniScrollButton.UP, itemName));
    }
    add(enterButton = new EnterButton(this, horizontal || stacked));
    add(tf = new ScrollTextField(this, Long.toString(currentValue), 2));
    tf.setVisible(false);
    tf.addActionListener(this);
    tf.addTextListener(this);
    tf.setSize(5, 5);
    tf.setLocation(5, 5);

    add(dummy = new TextField(""));
    dummy.setEditable(false);
    dummy.setSize(0, 0);
    dummy.setBackground(bg);
    dummy.setLocation(0, 0);

    decrementButton.setVisible(false);
    incrementButton.setVisible(false);
    enterButton.setVisible(false);
    if (horizontal) {
      if (stacked) {
        tf.setSize(1, 1);
        decrementButton.setLocation(2, arrowHeight);
        incrementButton.setLocation(totalWidth - 20, arrowHeight);
      } else {
        tf.setSize(1, 1);
        decrementButton.setLocation(0, 2);
        tf.setLocation(decrementButton.getBounds().x + decrementButton.getBounds().width, 2);
        incrementButton.setLocation(
            tf.getBounds().x + tf.getBounds().width + EnterButton.MIN_DIMENSION + 1, 2);
      }
    } else {
      if (stacked) {
        tf.setSize(1, 1);
        decrementButton.setLocation(2, arrowHeight);
        incrementButton.setLocation(totalWidth - 26, arrowHeight);
      } else {
        tf.setSize(1, 1);
        incrementButton.setLocation(0, 0);
        tf.setLocation(0, decrementButton.getBounds().height + 6);
        decrementButton.setLocation(
            0, tf.getBounds().y + tf.getBounds().height + EnterButton.MIN_DIMENSION + 1);
      }
    }

    tf.setBackground(bg);
    setBackground(bg);
    enterButton.setEnabled(false);
    decrementButton.setEnabled(currentValue > minValue);
    incrementButton.setEnabled(currentValue < maxValue);
  }
  boolean showOptions() {

    MesquiteInteger buttonPressed = new MesquiteInteger(1);
    ExtensibleDialog queryDialog =
        new ExtensibleDialog(containerOfModule(), "Reinterpret Node Labels", buttonPressed);
    queryDialog.addLargeOrSmallTextLabel(
        "Some programs write information as node labels; e.g. MrBayes writes posterior probabilities as if they were the names of clades (= node labels)."
            + "\nHere you can reintepret such information.");
    // name for information (e.g., "posteriorProbability", "bootstrapFrequency")
    queryDialog.addLabel(
        "Name for information? (e.g., \"posteriorProbability\", \"bootstrapFrequency\")",
        Label.LEFT);
    TextField nameField = queryDialog.addTextField(name, 30);

    queryDialog.addHorizontalLine(2);

    // where to attach
    queryDialog.addLabel("Applies to branch or node?", Label.LEFT);
    String[] where =
        new String[] {
          "Information applies to branch (e.g., posterior probability, bootstrap frequency)",
          "Information applies to node (e.g., clade name)"
        };
    RadioButtons whereButtons = queryDialog.addRadioButtons(where, 0);
    queryDialog.addLabel(
        "(This determines how the information will behave when the tree is rerooted.)", Label.LEFT);
    queryDialog.addHorizontalLine(2);

    // how to treat
    queryDialog.addLabel("Number or text?", Label.LEFT);
    String[] what =
        new String[] {
          "Treat as number (e.g., posterior probability)", "Treat as text (e.g., clade name)"
        };
    RadioButtons whatButtons = queryDialog.addRadioButtons(what, 0);
    queryDialog.addHorizontalLine(2);

    // delete internal node labels after reinterpreting?
    Checkbox delete =
        queryDialog.addCheckBox("Delete internal node labels after reinterpreting?", deleteAfter);
    queryDialog.addHorizontalLine(2);

    queryDialog.completeAndShowDialog(true);

    boolean ok = (queryDialog.query() == 0);

    if (ok) {
      if (StringUtil.blank(nameField.getText())) {
        ok = false;
        alert("A name must be entered for the information");
      } else {
        name = nameField.getText();
        nameRef = NameReference.getNameReference(name);
        appliesToBranch = whereButtons.getValue() == 0;
        isNumber = whatButtons.getValue() == 0;
        deleteAfter = delete.getState();
      }
    }

    queryDialog.dispose();
    return ok;
  }