예제 #1
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 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);
    }
  }
예제 #3
0
  private void search(int direction) {
    String searchText = searchField.getText();
    if (searchText == null || searchText.length() == 0 || rTextArea.getText() == null) {
      return;
    }

    boolean forward = direction >= 0;
    boolean matchCase = matchCaseCB.isSelected();
    boolean regex = regexCB.isSelected();
    boolean wholeWord = wholeWordCB.isSelected();

    if (markAllCB.isSelected()) {
      rTextArea.markAll(searchText, matchCase, wholeWord, regex);
    } else {
      rTextArea.clearMarkAllHighlights();
    }

    SearchContext context = new SearchContext();
    context.setSearchFor(searchText);
    context.setMatchCase(matchCase);
    context.setRegularExpression(regex);
    context.setSearchForward(forward);
    context.setWholeWord(wholeWord);

    // TODO hack: move cursor before previous search for not jump to next occurrence
    if (direction == 0 && !COLOR_BG_ERROR.equals(searchField.getBackground())) {
      try {
        int caretPos = rTextArea.getCaretPosition();
        int lineNum = rTextArea.getLineOfOffset(caretPos) - 1;
        if (lineNum > 1) {
          rTextArea.setCaretPosition(rTextArea.getLineStartOffset(lineNum));
        }
      } catch (BadLocationException e) {
        LOG.error("Caret move error", e);
      }
    }

    boolean found = SearchEngine.find(rTextArea, context);
    if (!found) {
      int pos =
          SearchEngine.getNextMatchPos(
              searchText, rTextArea.getText(), forward, matchCase, wholeWord);
      if (pos != -1) {
        rTextArea.setCaretPosition(forward ? 0 : rTextArea.getDocument().getLength() - 1);
        search(direction);
        searchField.setBackground(COLOR_BG_WARN);
        return;
      }
      searchField.setBackground(COLOR_BG_ERROR);
    } else {
      searchField.setBackground(COLOR_BG_NORMAL);
    }
  }
  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);
    }
  }
  public void actionPerformed(ActionEvent e) {

    // "FindNext" => search forward, "FindPrev" => search backward
    String command = e.getActionCommand();
    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);

    boolean found = SearchEngine.find(textArea, context);
    if (!found) {
      JOptionPane.showMessageDialog(this, "Text not found");
    }
  }
예제 #6
0
  @Override
  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if ("FindNext".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      boolean markAll = markAllCB.isSelected();
      boolean forward = downCB.isSelected();
      boolean matchCase = matchCaseCB.isSelected();
      boolean wholeWord = wholeWrdsCB.isSelected();
      boolean regex = regexCB.isSelected();
      if (markAll) {
        rSyntaxTextArea.clearMarkAllHighlights();
        rSyntaxTextArea.markAll(text, matchCase, wholeWord, regex);
      }

      SearchContext c = new SearchContext();
      c.setMatchCase(matchCase);
      c.setSearchFor(text);
      c.setWholeWord(wholeWord);
      c.setRegularExpression(regex);
      c.setSearchForward(forward);
      boolean found = SearchEngine.find(rSyntaxTextArea, c);
      if (!found) {
        JOptionPane.showMessageDialog(
            this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound"));
      }
    } else if ("Close".equals(command)) {
      setVisible(false);
    } else if ("Replace".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      String textReplace = replaceTF.getText();
      if (textReplace.equals(text)) {
        return;
      } else {
        boolean forward = downCB.isSelected();
        boolean matchCase = matchCaseCB.isSelected();
        boolean wholeWord = wholeWrdsCB.isSelected();
        boolean regex = regexCB.isSelected();
        SearchContext c = new SearchContext();
        c.setMatchCase(matchCase);
        c.setSearchFor(text);
        c.setReplaceWith(textReplace);
        c.setWholeWord(wholeWord);
        c.setRegularExpression(regex);
        c.setSearchForward(forward);
        boolean found = SearchEngine.find(rSyntaxTextArea, c);
        if (!found) {
          JOptionPane.showMessageDialog(
              this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound"));
        }
      }

    } else if ("ReplaceAll".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      String textReplace = replaceTF.getText();
      if (textReplace.equals(text)) {
        return;
      } else {
        boolean matchCase = matchCaseCB.isSelected();
        boolean wholeWord = wholeWrdsCB.isSelected();
        boolean regex = regexCB.isSelected();
        SearchContext c = new SearchContext();
        c.setMatchCase(matchCase);
        c.setSearchFor(text);
        c.setWholeWord(wholeWord);
        c.setRegularExpression(regex);
        c.setReplaceWith(textReplace);
        SearchEngine.find(rSyntaxTextArea, c);
      }
    }
  }