List of usage examples for javax.swing.text Element getStartOffset
public int getStartOffset();
From source file:ru.gelin.fictionbook.reader.models.FBSimpleElementTest.java
@Test public void testGetElementIndex() { Node node = fb.getDocument().selectSingleNode("//fb:section[@id='section1']"); Element section = document.getElement(node); node = node.selectSingleNode("fb:p"); Element p = document.getElement(node); //index of <p> after <title> in <section> assertEquals(1, section.getElementIndex(p.getStartOffset() + 1)); }
From source file:tk.tomby.tedit.core.Buffer.java
/** * DOCUMENT ME!//w ww . j a v a 2s .c om * * @return DOCUMENT ME! */ public int getCurrentColumn() { int position = getCaretPosition(); int line = getCurrentLine(); Element element = getDocument().getDefaultRootElement().getElement(line); return (element != null) ? position - element.getStartOffset() : position; }
From source file:tk.tomby.tedit.core.Buffer.java
/** * DOCUMENT ME!/*from ww w . j ava 2 s .c om*/ * * @param line DOCUMENT ME! */ public void gotoLine(int line) { Element root = editor.getDocument().getDefaultRootElement(); if ((line < root.getElementCount()) && (line > 0)) { Element element = root.getElement(line - 1); editor.setCaretPosition(element.getStartOffset()); } }
From source file:tk.tomby.tedit.core.snr.FindReplaceWorker.java
/** * DOCUMENT ME!//from www.jav a 2 s. c o m */ 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++; } } }
From source file:tk.tomby.tedit.core.snr.FindReplaceWorker.java
/** * DOCUMENT ME!/*ww w .j av a 2 s . c om*/ */ 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--; } } }
From source file:tk.tomby.tedit.core.snr.FindReplaceWorker.java
/** * DOCUMENT ME!/* ww w. j a v a2 s. c o m*/ * * @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; }