예제 #1
0
  /** DOCUMENT ME! */
  public void previous() {
    for (int count = 0, i = buffer.getCurrentLine(); i >= 0; ) {
      Element line = init(i);

      int offset = line.getStartOffset();
      int start = 0;
      int end = 0;

      while (matcher.find()) {
        start = offset + matcher.start();
        end = offset + matcher.end();
      }

      if (start != end) {
        buffer.select(start, end);

        break;
      }

      if (PreferenceManager.getBoolean("snr.warp", false) && (i == 0)) {
        if (count > 1) {
          Toolkit.getDefaultToolkit().beep();

          break;
        }

        count++;

        i = buffer.getLineCount() - 1;
      } else {
        i--;
      }
    }
  }
예제 #2
0
  /** DOCUMENT ME! */
  public void replace() {
    String replace = PreferenceManager.getString("snr.replace", "");

    if ((replace != null) && !replace.equals("")) {
      int start = buffer.getSelectionStart();
      int end = buffer.getSelectionEnd();

      if (start != end) {
        Document doc = buffer.getDocument();

        try {
          doc.remove(start, end - start);
          doc.insertString(start, replace, null);
        } catch (BadLocationException e) {
          log.error(e.getMessage(), e);
        }
      }
    }
  }
예제 #3
0
  /**
   * DOCUMENT ME!
   *
   * @param lineNumber DOCUMENT ME!
   * @return DOCUMENT ME!
   */
  private Element init(int lineNumber) {
    Document doc = buffer.getDocument();
    Element line = doc.getDefaultRootElement().getElement(lineNumber);

    try {
      int options = Pattern.DOTALL;

      String find = PreferenceManager.getString("snr.find", "");

      if ((find != null) && !find.equals("")) {
        if (PreferenceManager.getBoolean("snr.case", false)) {
          find = find.toLowerCase();

          options |= Pattern.CASE_INSENSITIVE;
        }

        if (PreferenceManager.getBoolean("snr.whole", false)) {
          find = "\\b" + find + "\\b";
        }

        int offset = line.getStartOffset();
        int length = line.getEndOffset() - offset;

        if (PreferenceManager.getInt("snr.direction", FORWARD) == FORWARD) {
          if ((buffer.getSelectionEnd() > line.getStartOffset())
              && (buffer.getSelectionEnd() <= line.getEndOffset())) {
            offset = buffer.getSelectionEnd();
            length = line.getEndOffset() - offset;
          }
        } else {
          if ((buffer.getSelectionStart() > line.getStartOffset())
              && (buffer.getSelectionStart() <= line.getEndOffset())) {
            length = buffer.getSelectionStart() - offset;
          }
        }

        String text = doc.getText(offset, length);

        Pattern pattern = Pattern.compile(find, options);

        this.matcher = pattern.matcher(text);
      }
    } catch (BadLocationException e) {
      log.error(e.getMessage(), e);
    }

    return line;
  }
예제 #4
0
  /** DOCUMENT ME! */
  public void next() {
    for (int count = 0, i = buffer.getCurrentLine(); i < buffer.getLineCount(); ) {
      Element line = init(i);

      int offset = line.getStartOffset();

      if (PreferenceManager.getInt("snr.direction", FORWARD) == FORWARD) {
        if ((buffer.getSelectionEnd() > line.getStartOffset())
            && (buffer.getSelectionEnd() <= line.getEndOffset())) {
          offset = buffer.getSelectionEnd();
        }
      }

      if (matcher.find()) {
        int start = offset + matcher.start();
        int end = offset + matcher.end();

        buffer.select(start, end);

        break;
      }

      if (PreferenceManager.getBoolean("snr.warp", false) && (i == (buffer.getLineCount() - 1))) {
        if (count > 1) {
          Toolkit.getDefaultToolkit().beep();

          break;
        }

        count++;

        i = 0;
      } else {
        i++;
      }
    }
  }