List of usage examples for javax.swing.text Element getElement
public Element getElement(int index);
From source file:org.domainmath.gui.MainFrame.java
private void gotoItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gotoItemActionPerformed if (fileTab.getSelectedIndex() >= 0) { String s = JOptionPane.showInputDialog("Line Number:"); RTextScrollPane t = (RTextScrollPane) fileTab.getComponentAt(fileTab.getSelectedIndex()); RSyntaxTextArea selectedArea = (RSyntaxTextArea) t.getTextArea(); try {/*from w w w . j av a 2s. c o m*/ Element element = selectedArea.getDocument().getDefaultRootElement(); int lineRequested = Integer.parseInt(s); int rowCount = element.getElementCount(); if (lineRequested > rowCount || lineRequested < 0) { setVisible(false); return; } Element row = null; int firstCharacter = 0; int rowNumber = 0; for (int i = 0; i < lineRequested; ++i) { firstCharacter = getFirstCharacter(row); rowNumber = element.getElementIndex(firstCharacter); row = element.getElement(rowNumber); } int lastColumnInRow = row.getEndOffset(); selectedArea.select(firstCharacter, lastColumnInRow - 1); } catch (Exception e) { } } }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
/** * Called when the caret position is updated. * * @param e the caret event/*from w w w. j a va 2 s. co m*/ */ public void caretUpdate(CaretEvent ce) { super.caretUpdate(ce); currentPosition = getCaretPosition(); Element map = getElementMap(); int row = map.getElementIndex(currentPosition); if (currentRow != row) { currentRow = row; //lineBorder.setRowCount(map.getElementCount()); } Element lineElem = map.getElement(row); int col = currentPosition - lineElem.getStartOffset(); editorPanel.getStatusBar().setCaretPosition(row + 1, col + 1); repaint(); }
From source file:org.fife.rsta.ac.js.JavaScriptParser.java
/** * {@inheritDoc}// ww w. j a v a2s .c o m */ public ParseResult parse(RSyntaxDocument doc, String style) { astRoot = null; result.clearNotices(); // Always spell check all lines, for now. Element root = doc.getDefaultRootElement(); int lineCount = root.getElementCount(); result.setParsedLines(0, lineCount - 1); DocumentReader r = new DocumentReader(doc); ErrorCollector errorHandler = new ErrorCollector(); long start = System.currentTimeMillis(); try { String script = IOUtils.toString(r); CompilerEnvirons env = createCompilerEnvironment(errorHandler, langSupport); Parser parser = new Parser(env); astRoot = parser.parse(new StringReader(MIRTH_SCRIPT_PREFIX + script + MIRTH_SCRIPT_SUFFIX), null, 0); env = createCompilerEnvironment(new ErrorCollector(), langSupport); astRoot = new Parser(env).parse(script, null, 0); long time = System.currentTimeMillis() - start; result.setParseTime(time); } catch (IOException ioe) { // Never happens result.setError(ioe); ioe.printStackTrace(); } catch (RhinoException re) { // Shouldn't happen since we're passing an ErrorCollector in int line = re.lineNumber(); // if (line>0) { Element elem = root.getElement(line); int offs = elem.getStartOffset(); int len = elem.getEndOffset() - offs - 1; String msg = re.details(); result.addNotice(new DefaultParserNotice(this, msg, line, offs, len)); // } } catch (Exception e) { result.setError(e); // catch all } r.close(); // Get any parser errors. switch (langSupport.getErrorParser()) { default: case RHINO: gatherParserErrorsRhino(errorHandler, root); break; case JSHINT: gatherParserErrorsJsHint(doc); break; } // addNotices(doc); support.firePropertyChange(PROPERTY_AST, null, astRoot); return result; }
From source file:ru.gelin.fictionbook.reader.models.FBSimpleElementTest.java
@Test public void testGetElement() { Node node = fb.getDocument().selectSingleNode("//fb:section[@id='section1']/fb:title"); Element parent = document.getElement(node); assertSame(element, parent.getElement(0)); }
From source file:tk.tomby.tedit.core.Buffer.java
/** * DOCUMENT ME!//from www . j a v a 2s .com * * @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()); } }