Ejemplo n.º 1
0
  /**
   * @param actionCommand Evaluate || Numeric || Substitute
   * @return true iff any substitution applied
   */
  protected boolean apply(String actionCommand) {

    CASTable table = getCASView().getConsoleTable();

    // create substitution list
    StringBuilder substList = new StringBuilder("{");
    StringBuilder substComment = new StringBuilder();

    for (int i = 0; i < data.size(); i++) {
      String fromExpr = data.get(i).get(0).trim();
      String toExpr = data.get(i).get(1).trim();
      if (!"".equals(fromExpr) && !"".equals(toExpr)) {
        if (substList.length() > 1) {
          substList.append(',');
          substComment.append(',');
        }
        fromExpr = getCASView().resolveCASrowReferences(fromExpr, editRow);
        toExpr = getCASView().resolveCASrowReferences(toExpr, editRow);
        substList.append(fromExpr);
        substList.append('=');
        substList.append(toExpr);
        substComment.append(fromExpr);
        substComment.append('=');
        substComment.append(toExpr);
      }
    }
    substList.append('}');

    if ("{}".equals(substList.toString())) return false;

    // make sure pure substitute is not evaluated
    boolean keepInput = false;

    // substitute command
    String subCmd = "Substitute[" + evalText + "," + substList + "]";
    if ("Substitute".equals(actionCommand)) {
      subCmd = "Substitute[" + evalText + "," + substList + "]";
      keepInput = true;
    } else if ("Numeric".equals(actionCommand)) {
      subCmd = "Numeric[" + subCmd + "]";
      keepInput = false;
    }

    try {
      GeoCasCell currCell = table.getGeoCasCell(editRow);
      currCell.setProcessingInformation(prefix, subCmd, postfix);
      currCell.setEvalCommand("Substitute");
      currCell.setEvalComment(substComment.toString());

      // make sure pure substitute is not evaluated
      currCell.setKeepInputUsed(keepInput);

      getCASView().processRowThenEdit(editRow, true);
      // table.startEditingRow(editRow + 1);
      return true;
    } catch (Throwable e) {
      e.printStackTrace();
      return false;
    }
  }
Ejemplo n.º 2
0
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    setText((value == null) ? "" : value.toString());
    setFont(casTable.getFont());

    if (isSelected) {
      setBackground(GeoGebraColorConstants.TABLE_SELECTED_BACKGROUND_COLOR_HEADER);
    } else {
      setBackground(GeoGebraColorConstants.TABLE_BACKGROUND_COLOR_HEADER);
    }

    // update height
    Dimension prefSize = getPreferredSize();
    // go through all columns of this row to get the max height
    int height = casTable.getPreferredRowHeight(index);
    if (height != prefSize.height) {
      prefSize.height = height;
      setSize(prefSize);
      setPreferredSize(prefSize);
    }

    return this;
  }