Example #1
0
  private boolean apply(String actionCommand) {

    CASTable table = casView.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 (!fromExpr.equals("") && !toExpr.equals("")) {
        if (substList.length() > 1) {
          substList.append(',');
          substComment.append(',');
        }
        fromExpr = casView.resolveCASrowReferences(fromExpr, editRow);
        toExpr = casView.resolveCASrowReferences(toExpr, editRow);
        substList.append(fromExpr);
        substList.append('=');
        substList.append(toExpr);
        substComment.append(fromExpr);
        substComment.append('=');
        substComment.append(toExpr);
      }
    }
    substList.append('}');

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

    // substitute command
    String subCmd = "Substitute[" + evalText + "," + substList + "]";
    if (actionCommand.equals("Substitute")) {
      subCmd = "Substitute[" + evalText + "," + substList + "]";
      keepInput = false;
    } else if (actionCommand.equals("Numeric")) {
      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);

      casView.processRowThenEdit(editRow, true);
      // table.startEditingRow(editRow + 1);
      return true;
    } catch (Throwable e) {
      e.printStackTrace();
      return false;
    }
  }
Example #2
0
  protected void createGUI() {
    setTitle(app.getPlain("Substitute") + " - " + app.getCommand("Row") + " " + (editRow + 1));
    setResizable(true);

    GeoCasCell cell = casView.getConsoleTable().getGeoCasCell(editRow);

    HashSet<GeoElement> vars = cell.getInputVE().getVariables();
    Vector<String> row;
    if (vars != null) {
      data = new Vector<Vector<String>>(vars.size() + 1);
      Iterator<GeoElement> iter = vars.iterator();
      while (iter.hasNext()) {
        row = new Vector<String>(2);
        GeoElement var = iter.next();
        String nextVar = var.getLabel();
        int i = 0;
        for (i = 0; i < data.size(); i++) {
          if (data.get(i).firstElement().compareTo(nextVar) >= 0) {
            break;
          }
        }
        if (i == data.size() || !data.get(i).firstElement().equals(nextVar)) {
          row.add(nextVar);
          row.add("");
          data.insertElementAt(row, i);
        }
      }
    } else {
      data = new Vector<Vector<String>>(1);
    }
    row = new Vector<String>(2);
    row.add("");
    row.add("");
    data.add(row);

    Vector<String> header = new Vector<String>();
    header.add(app.getPlain("OldExpression"));
    header.add(app.getPlain("NewExpression"));
    replaceTable = new JTable(data, header);
    replaceTable.setDefaultEditor(Object.class, new MathTextCellEditor());
    replaceTable.getTableHeader().setReorderingAllowed(false);
    double fontFactor = Math.max(1, app.getGUIFontSize() / DEFAULT_FONT_SIZE);
    replaceTable.setRowHeight((int) (DEFAULT_TABLE_CELL_HEIGHT * fontFactor));

    replaceTable.setPreferredScrollableViewportSize(
        new Dimension(
            (int) (DEFAULT_TABLE_WIDTH * fontFactor), (int) (DEFAULT_TABLE_HEIGHT * fontFactor)));
    scrollPane = new JScrollPane(replaceTable);

    captionPanel = new JPanel(new BorderLayout(5, 0));

    captionPanel.add(scrollPane, BorderLayout.CENTER);

    replaceTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    replaceTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent e) {
                addRow(false);
              }
            });

    replaceTable.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != '\t') addRow(true);
          }
        });

    // buttons
    btEval = new JButton("=");
    btEval.setToolTipText(app.getCommandTooltip("Evaluate"));
    btEval.setActionCommand("Evaluate");
    btEval.addActionListener(this);

    btNumeric = new JButton("\u2248");
    btNumeric.setToolTipText(app.getCommandTooltip("Numeric"));
    btNumeric.setActionCommand("Numeric");
    btNumeric.addActionListener(this);

    btSub = new JButton(app.getPlain("\u2713"));
    btSub.setToolTipText(app.getCommandTooltip("Substitute"));
    btSub.setActionCommand("Substitute");
    btSub.addActionListener(this);

    btPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    btPanel.add(btEval);
    btPanel.add(btNumeric);
    btPanel.add(btSub);

    // Create the JOptionPane.
    optionPane = new JPanel(new BorderLayout(5, 5));

    // create object list
    optionPane.add(captionPanel, BorderLayout.CENTER);

    optionPane.add(btPanel, BorderLayout.SOUTH);
    optionPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make this dialog display it.
    setContentPane(optionPane);
  }