public void find(boolean forward) {
    SearchContext context = new SearchContext();
    String text = findTextField.getText();
    if (text.length() == 0) {
      return;
    }
    context.setSearchFor(text);

    context.setMatchCase(this.matchCaseCheckBox.isSelected());
    context.setRegularExpression(this.regExCheckBox.isSelected());
    context.setSearchForward(forward);

    context.setWholeWord(this.wholeWordsOnlyCheckBox.isSelected());

    SearchResult found = SearchEngine.find(selectedArea, context);
    if (this.markAllComboBox.isSelected()) {
      selectedArea.setMarkOccurrences(true);
    } else {
      selectedArea.setMarkOccurrences(false);
    }
    if (!found.wasFound()) {
      JOptionPane.showMessageDialog(
          this, "Text not found", "DomainMath IDE", JOptionPane.INFORMATION_MESSAGE);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void actionPerformed(ActionEvent e) {
    // "FindNext" => search forward, "FindPrev" => search backward
    String command = e.getActionCommand();
    if (command != null && command.toLowerCase().equals("tab closing")) {
      closeTextPanel();
    } else {
      boolean forward = "FindNext".equals(command);

      // Create an object defining our search parameters.
      SearchContext context = new SearchContext();
      String text = searchField.getText();
      if (text.length() == 0) {
        return;
      }
      context.setSearchFor(text);
      context.setMatchCase(matchCaseCB.isSelected());
      context.setRegularExpression(regexCB.isSelected());
      context.setSearchForward(forward);
      context.setWholeWord(false);

      SearchResult found = SearchEngine.find(rsTextArea, context);
      if (!found.wasFound()) {
        rsTextArea.setCaretPosition(forward ? 0 : rsTextArea.getDocument().getLength() - 1);
        found = SearchEngine.find(rsTextArea, context);
        if (!found.wasFound()) {
          JOptionPane.showMessageDialog(this, "Text not found");
        }
      }
    }
  }
  public void replaceAll(boolean back) {
    SearchContext context = new SearchContext();
    String findText = this.findTextField.getText();
    String text = this.replaceTextField.getText();
    if (text.length() == 0) {
      return;
    }
    context.setSearchFor(findText);
    context.setReplaceWith(text);
    context.setMatchCase(this.matchCaseCheckBox.isSelected());
    context.setRegularExpression(this.regExCheckBox.isSelected());
    context.setSearchForward(back);
    context.setWholeWord(this.wholeWordsOnlyCheckBox.isSelected());

    SearchResult found = SearchEngine.replaceAll(selectedArea, context);

    if (found.wasFound()) {
      JOptionPane.showMessageDialog(
          this, "Unable to replace the text", "DomainMath IDE", JOptionPane.INFORMATION_MESSAGE);
    }
  }