public void doReplacement() { EditWindow currentWindow = editor.getActiveWindow(); if (currentWindow == null || getFindTextField().getText().length() == 0) { // launch error dialog? return; } JEditorPane editorPane = currentWindow.getEditorPane(); String text = editorPane.getSelectedText(); if (text == null) { // no selection return; } Matcher m = getCurrentPattern().matcher(text); if (m.matches()) { String replacement = getReplaceTextField().getText(); if (getRegexButton().isSelected()) { replacement = m.replaceFirst(replacement); } editorPane.replaceSelection(replacement); } }
public void showResult(JEditorPane txt, String result) { try { if (txt.getText().length() == 0) { appendHTML(txt, result); txt.setSelectionStart(txt.getText().length()); txt.setSelectionEnd(txt.getText().length() - 1); } else { if (txt.getText().length() > MAX_LOG_SIZE) { txt.setSelectionStart(0); txt.setSelectionStart(txt.getText().length() - MAX_LOG_SIZE); txt.replaceSelection(""); } txt.setSelectionStart(txt.getText().length()); appendHTML(txt, result); txt.setSelectionEnd(txt.getText().length()); } } catch (Exception e) { e.printStackTrace(); } }