/** * 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; }
/** 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); } } } }